PageRenderTime 688ms CodeModel.GetById 75ms RepoModel.GetById 1ms app.codeStats 3ms

/tests/CompileTests/RoseExample_tests/trial_Cxx_Grammar.C

https://github.com/GoblinInventor/edg4x-rose
C | 14108 lines | 8485 code | 2536 blank | 3087 comment | 1750 complexity | 8b54bf5d5c2e8df473121fd27356c4cb MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0
  1. // MACHINE GENERATED SOURCE FILE --- DO NOT MODIFY!
  2. #include "sage3basic.h"
  3. #include "sage3.h"
  4. #if 1
  5. #include "AST_FILE_IO.h"
  6. using namespace std;
  7. // Simplify code by using std namespace (never put into header files since it effects users)
  8. using namespace std;
  9. static struct
  10. {
  11. Cxx_GrammarVariants variant;
  12. std::string name;
  13. } Cxx_GrammarTerminalNames[317] = {
  14. {ModifierTag, "SgModifier"},
  15. {BitAttributeTag, "SgBitAttribute"},
  16. {AttributeTag, "SgAttribute"},
  17. {GraphNodeTag, "SgGraphNode"},
  18. {GraphEdgeTag, "SgGraphEdge"},
  19. {GraphTag, "SgGraph"},
  20. {SupportTag, "SgSupport"},
  21. {T_PARTIAL_FUNCTION, "SgPartialFunctionType"},
  22. {T_MEMBERFUNCTION, "SgMemberFunctionType"},
  23. {T_FUNCTION, "SgFunctionType"},
  24. {T_POINTER, "SgPointerType"},
  25. {T_NAME, "SgNamedType"},
  26. {TypeTag, "SgType"},
  27. {EXPR_INIT, "SgInitializer"},
  28. {UNARY_EXPRESSION, "SgUnaryOp"},
  29. {BINARY_EXPRESSION, "SgBinaryOp"},
  30. {ValueExpTag, "SgValueExp"},
  31. {ExpressionTag, "SgExpression"},
  32. {FORTRAN_DO, "SgFortranDo"},
  33. {IO_CONTROL_STATEMENT, "SgIOControlStatement"},
  34. {CLASS_DECL_STMT, "SgClassDeclaration"},
  35. {CLASS_DEFN_STMT, "SgClassDefinition"},
  36. {SCOPE_STMT, "SgScopeStatement"},
  37. {MFUNC_DECL_STMT, "SgMemberFunctionDeclaration"},
  38. {FUNC_DECL_STMT, "SgFunctionDeclaration"},
  39. {CPP_DIRECTIVE_STMT, "SgC_PreprocessorDirectiveStatement"},
  40. {C_LINKAGE_DECLARATION_STMT, "SgClinkageDeclarationStatement"},
  41. {DECL_STMT, "SgDeclarationStatement"},
  42. {StatementTag, "SgStatement"},
  43. {FUNCTION_NAME, "SgFunctionSymbol"},
  44. {SymbolTag, "SgSymbol"},
  45. {LocatedNodeTag, "SgLocatedNode"},
  46. {NodeTag, "SgNode"},
  47. {SymbolTableTag, "SgSymbolTable"},
  48. {InitializedNameTag, "SgInitializedName"},
  49. {NameTag, "SgName"},
  50. {PragmaTag, "SgPragma"},
  51. {ModifierNodesTag, "SgModifierNodes"},
  52. {ConstVolatileModifierTag, "SgConstVolatileModifier"},
  53. {StorageModifierTag, "SgStorageModifier"},
  54. {AccessModifierTag, "SgAccessModifier"},
  55. {FunctionModifierTag, "SgFunctionModifier"},
  56. {UPC_AccessModifierTag, "SgUPC_AccessModifier"},
  57. {LinkageModifierTag, "SgLinkageModifier"},
  58. {SpecialFunctionModifierTag, "SgSpecialFunctionModifier"},
  59. {TypeModifierTag, "SgTypeModifier"},
  60. {ElaboratedTypeModifierTag, "SgElaboratedTypeModifier"},
  61. {BaseClassModifierTag, "SgBaseClassModifier"},
  62. {DeclarationModifierTag, "SgDeclarationModifier"},
  63. {_File_InfoTag, "Sg_File_Info"},
  64. {FileTag, "SgFile"},
  65. {FileListTag, "SgFileList"},
  66. {DirectoryTag, "SgDirectory"},
  67. {DirectoryListTag, "SgDirectoryList"},
  68. {ProjectTag, "SgProject"},
  69. {OptionsTag, "SgOptions"},
  70. {Unparse_InfoTag, "SgUnparse_Info"},
  71. {FuncDecl_attrTag, "SgFuncDecl_attr"},
  72. {ClassDecl_attrTag, "SgClassDecl_attr"},
  73. {T_TYPEDEF_SEQ, "SgTypedefSeq"},
  74. {T_FUNCTION_PARAMETER_TYPE_LIST, "SgFunctionParameterTypeList"},
  75. {TemplateParameterTag, "SgTemplateParameter"},
  76. {TemplateArgumentTag, "SgTemplateArgument"},
  77. {TemplateParameterListTag, "SgTemplateParameterList"},
  78. {TemplateArgumentListTag, "SgTemplateArgumentList"},
  79. {BaseClassTag, "SgBaseClass"},
  80. {DirectedGraphTag, "SgDirectedGraph"},
  81. {DirectedGraphNodeTag, "SgDirectedGraphNode"},
  82. {DirectedGraphEdgeTag, "SgDirectedGraphEdge"},
  83. {QualifiedNameTag, "SgQualifiedName"},
  84. {T_UNKNOWN, "SgTypeUnknown"},
  85. {T_CHAR, "SgTypeChar"},
  86. {T_SIGNED_CHAR, "SgTypeSignedChar"},
  87. {T_UNSIGNED_CHAR, "SgTypeUnsignedChar"},
  88. {T_SHORT, "SgTypeShort"},
  89. {T_SIGNED_SHORT, "SgTypeSignedShort"},
  90. {T_UNSIGNED_SHORT, "SgTypeUnsignedShort"},
  91. {T_INT, "SgTypeInt"},
  92. {T_SIGNED_INT, "SgTypeSignedInt"},
  93. {T_UNSIGNED_INT, "SgTypeUnsignedInt"},
  94. {T_LONG, "SgTypeLong"},
  95. {T_SIGNED_LONG, "SgTypeSignedLong"},
  96. {T_UNSIGNED_LONG, "SgTypeUnsignedLong"},
  97. {T_VOID, "SgTypeVoid"},
  98. {T_GLOBAL_VOID, "SgTypeGlobalVoid"},
  99. {T_WCHAR, "SgTypeWchar"},
  100. {T_FLOAT, "SgTypeFloat"},
  101. {T_DOUBLE, "SgTypeDouble"},
  102. {T_LONG_LONG, "SgTypeLongLong"},
  103. {T_UNSIGNED_LONG_LONG, "SgTypeUnsignedLongLong"},
  104. {T_LONG_DOUBLE, "SgTypeLongDouble"},
  105. {T_STRING, "SgTypeString"},
  106. {T_BOOL, "SgTypeBool"},
  107. {T_COMPLEX, "SgTypeComplex"},
  108. {T_IMAGINARY, "SgTypeImaginary"},
  109. {T_DEFAULT, "SgTypeDefault"},
  110. {T_MEMBER_POINTER, "SgPointerMemberType"},
  111. {T_REFERENCE, "SgReferenceType"},
  112. {T_CLASS, "SgClassType"},
  113. {T_TEMPLATE, "SgTemplateType"},
  114. {T_ENUM, "SgEnumType"},
  115. {T_TYPEDEF, "SgTypedefType"},
  116. {T_MODIFIER, "SgModifierType"},
  117. {T_PARTIAL_FUNCTION_MODIFIER, "SgPartialFunctionModifierType"},
  118. {T_ARRAY, "SgArrayType"},
  119. {T_ELLIPSE, "SgTypeEllipse"},
  120. {UnknownMemberFunctionTag, "SgUnknownMemberFunctionType"},
  121. {T_QUALIFIED_NAME, "SgQualifiedNameType"},
  122. {EXPR_LIST, "SgExprListExp"},
  123. {VAR_REF, "SgVarRefExp"},
  124. {CLASSNAME_REF, "SgClassNameRefExp"},
  125. {FUNCTION_REF, "SgFunctionRefExp"},
  126. {MEMBER_FUNCTION_REF, "SgMemberFunctionRefExp"},
  127. {FUNC_CALL, "SgFunctionCallExp"},
  128. {SIZEOF_OP, "SgSizeOfOp"},
  129. {VA_START_OP, "SgVarArgStartOp"},
  130. {VA_START_ONE_OPERAND_OP, "SgVarArgStartOneOperandOp"},
  131. {VA_OP, "SgVarArgOp"},
  132. {VA_END_OP, "SgVarArgEndOp"},
  133. {VA_COPY_OP, "SgVarArgCopyOp"},
  134. {TYPEID_OP, "SgTypeIdOp"},
  135. {EXPR_CONDITIONAL, "SgConditionalExp"},
  136. {NEW_OP, "SgNewExp"},
  137. {DELETE_OP, "SgDeleteExp"},
  138. {THIS_NODE, "SgThisExp"},
  139. {TYPE_REF, "SgRefExp"},
  140. {AGGREGATE_INIT, "SgAggregateInitializer"},
  141. {CONSTRUCTOR_INIT, "SgConstructorInitializer"},
  142. {ASSIGN_INIT, "SgAssignInitializer"},
  143. {EXPRESSION_ROOT, "SgExpressionRoot"},
  144. {UNARY_MINUS_OP, "SgMinusOp"},
  145. {UNARY_ADD_OP, "SgUnaryAddOp"},
  146. {NOT_OP, "SgNotOp"},
  147. {DEREF_OP, "SgPointerDerefExp"},
  148. {ADDRESS_OP, "SgAddressOfOp"},
  149. {MINUSMINUS_OP, "SgMinusMinusOp"},
  150. {PLUSPLUS_OP, "SgPlusPlusOp"},
  151. {BIT_COMPLEMENT_OP, "SgBitComplementOp"},
  152. {CAST_OP, "SgCastExp"},
  153. {THROW_OP, "SgThrowOp"},
  154. {POINTST_OP, "SgArrowExp"},
  155. {RECORD_REF, "SgDotExp"},
  156. {DOTSTAR_OP, "SgDotStarOp"},
  157. {ARROWSTAR_OP, "SgArrowStarOp"},
  158. {EQ_OP, "SgEqualityOp"},
  159. {LT_OP, "SgLessThanOp"},
  160. {GT_OP, "SgGreaterThanOp"},
  161. {NE_OP, "SgNotEqualOp"},
  162. {LE_OP, "SgLessOrEqualOp"},
  163. {GE_OP, "SgGreaterOrEqualOp"},
  164. {ADD_OP, "SgAddOp"},
  165. {SUBT_OP, "SgSubtractOp"},
  166. {MULT_OP, "SgMultiplyOp"},
  167. {DIV_OP, "SgDivideOp"},
  168. {INTEGER_DIV_OP, "SgIntegerDivideOp"},
  169. {MOD_OP, "SgModOp"},
  170. {AND_OP, "SgAndOp"},
  171. {OR_OP, "SgOrOp"},
  172. {BITXOR_OP, "SgBitXorOp"},
  173. {BITAND_OP, "SgBitAndOp"},
  174. {BITOR_OP, "SgBitOrOp"},
  175. {COMMA_OP, "SgCommaOpExp"},
  176. {LSHIFT_OP, "SgLshiftOp"},
  177. {RSHIFT_OP, "SgRshiftOp"},
  178. {ARRAY_OP, "SgPntrArrRefExp"},
  179. {SCOPE_OP, "SgScopeOp"},
  180. {ASSIGN_OP, "SgAssignOp"},
  181. {PLUS_ASSIGN_OP, "SgPlusAssignOp"},
  182. {MINUS_ASSIGN_OP, "SgMinusAssignOp"},
  183. {AND_ASSIGN_OP, "SgAndAssignOp"},
  184. {IOR_ASSIGN_OP, "SgIorAssignOp"},
  185. {MULT_ASSIGN_OP, "SgMultAssignOp"},
  186. {DIV_ASSIGN_OP, "SgDivAssignOp"},
  187. {MOD_ASSIGN_OP, "SgModAssignOp"},
  188. {XOR_ASSIGN_OP, "SgXorAssignOp"},
  189. {LSHIFT_ASSIGN_OP, "SgLshiftAssignOp"},
  190. {RSHIFT_ASSIGN_OP, "SgRshiftAssignOp"},
  191. {BOOL_VAL, "SgBoolValExp"},
  192. {STRING_VAL, "SgStringVal"},
  193. {SHORT_VAL, "SgShortVal"},
  194. {CHAR_VAL, "SgCharVal"},
  195. {UNSIGNED_CHAR_VAL, "SgUnsignedCharVal"},
  196. {WCHAR_VAL, "SgWcharVal"},
  197. {UNSIGNED_SHORT_VAL, "SgUnsignedShortVal"},
  198. {INT_VAL, "SgIntVal"},
  199. {ENUM_VAL, "SgEnumVal"},
  200. {UNSIGNED_INT_VAL, "SgUnsignedIntVal"},
  201. {LONG_INT_VAL, "SgLongIntVal"},
  202. {LONG_LONG_INT_VAL, "SgLongLongIntVal"},
  203. {UNSIGNED_LONG_LONG_INT_VAL, "SgUnsignedLongLongIntVal"},
  204. {UNSIGNED_LONG_INT_VAL, "SgUnsignedLongVal"},
  205. {FLOAT_VAL, "SgFloatVal"},
  206. {DOUBLE_VAL, "SgDoubleVal"},
  207. {LONG_DOUBLE_VAL, "SgLongDoubleVal"},
  208. {COMPLEX_VAL, "SgComplexVal"},
  209. {NULL_EXPR, "SgNullExpression"},
  210. {VARIANT_EXPR, "SgVariantExpression"},
  211. {STMT_EXPR, "SgStatementExpression"},
  212. {ASM_OP, "SgAsmOp"},
  213. {INTRINSICFN, "SgIntrinsicFn"},
  214. {SUBSCRIPT_EXPR, "SgSubscriptExpression"},
  215. {SUBSCRIPT_COLON, "SgSubscriptColon"},
  216. {COLON, "SgColon"},
  217. {SUBSCRIPT_ASTERISK, "SgSubscriptAsterisk"},
  218. {USE_ONLY_EXPR, "SgUseOnlyExpression"},
  219. {USE_RENAME_EXPR, "SgUseRenameExpression"},
  220. {IO_ITEM_EXPR, "SgIOItemExpression"},
  221. {IO_IMPLIED_DO, "SgIOImpliedDo"},
  222. {EXPONENTIATION_OP, "SgExponentiationOp"},
  223. {FOR_STMT, "SgForStatement"},
  224. {FOR_INIT_STMT, "SgForInitStatement"},
  225. {CATCH_STATEMENT_SEQ, "SgCatchStatementSeq"},
  226. {FUNCTION_PARAMETER_LIST, "SgFunctionParameterList"},
  227. {CTOR_INITIALIZER_LIST, "SgCtorInitializerList"},
  228. {BASIC_BLOCK_STMT, "SgBasicBlock"},
  229. {GLOBAL_STMT, "SgGlobal"},
  230. {IF_STMT, "SgIfStmt"},
  231. {FUNC_DEFN_STMT, "SgFunctionDefinition"},
  232. {WHILE_STMT, "SgWhileStmt"},
  233. {DO_WHILE_STMT, "SgDoWhileStmt"},
  234. {SWITCH_STMT, "SgSwitchStatement"},
  235. {CATCH_STMT, "SgCatchOptionStmt"},
  236. {VAR_DECL_STMT, "SgVariableDeclaration"},
  237. {VAR_DEFN_STMT, "SgVariableDefinition"},
  238. {ENUM_DECL_STMT, "SgEnumDeclaration"},
  239. {ASM_STMT, "SgAsmStmt"},
  240. {TYPEDEF_STMT, "SgTypedefDeclaration"},
  241. {FUNC_TBL_STMT, "SgFunctionTypeTable"},
  242. {EXPR_STMT, "SgExprStatement"},
  243. {LABEL_STMT, "SgLabelStatement"},
  244. {CASE_STMT, "SgCaseOptionStmt"},
  245. {TRY_STMT, "SgTryStmt"},
  246. {DEFAULT_STMT, "SgDefaultOptionStmt"},
  247. {BREAK_STMT, "SgBreakStmt"},
  248. {CONTINUE_STMT, "SgContinueStmt"},
  249. {RETURN_STMT, "SgReturnStmt"},
  250. {GOTO_STMT, "SgGotoStatement"},
  251. {SPAWN_STMT, "SgSpawnStmt"},
  252. {NULL_STMT, "SgNullStatement"},
  253. {VARIANT_STMT, "SgVariantStatement"},
  254. {PRAGMA_DECL, "SgPragmaDeclaration"},
  255. {TEMPLATE_DECL_STMT, "SgTemplateDeclaration"},
  256. {TEMPLATE_INST_DECL_STMT, "SgTemplateInstantiationDecl"},
  257. {TEMPLATE_INST_DEFN_STMT, "SgTemplateInstantiationDefn"},
  258. {TEMPLATE_INST_FUNCTION_DECL_STMT, "SgTemplateInstantiationFunctionDecl"},
  259. {TEMPLATE_INST_MEMBER_FUNCTION_DECL_STMT, "SgTemplateInstantiationMemberFunctionDecl"},
  260. {PROGRAM_HEADER_STMT, "SgProgramHeaderStatement"},
  261. {PROCEDURE_HEADER_STMT, "SgProcedureHeaderStatement"},
  262. {FORTRAN_NONBLOCKED_DO, "SgFortranNonblockedDo"},
  263. {INTERFACE_STATEMENT, "SgInterfaceStatement"},
  264. {PARAMETER_STATEMENT, "SgParameterStatement"},
  265. {COMMON_BLOCK, "SgCommonBlock"},
  266. {MODULE_STATEMENT, "SgModuleStatement"},
  267. {USE_STATEMENT, "SgUseStatement"},
  268. {STOP_OR_PAUSE_STATEMENT, "SgStopOrPauseStatement"},
  269. {IO_STATEMENT, "SgIOStatement"},
  270. {INPUT_OUTPUT_STATEMENT, "SgInputOutputStatement"},
  271. {OPEN_STATEMENT, "SgOpenStatement"},
  272. {CLOSE_STATEMENT, "SgCloseStatement"},
  273. {INQUIRE_STATEMENT, "SgInquireStatement"},
  274. {IO_FILE_CONTROL_STMT, "SgIOFileControlStmt"},
  275. {TEMP_Block_Data_Statement, "SgBlockDataStatement"},
  276. {TEMP_Implicit_Statement, "SgImplicitStatement"},
  277. {TEMP_Statement_Function_Statement, "SgStatementFunctionStatement"},
  278. {TEMP_Where_Statement, "SgWhereStatement"},
  279. {TEMP_Nullify_Statement, "SgNullifyStatement"},
  280. {TEMP_Equivalence_Statement, "SgEquivalenceStatement"},
  281. {TEMP_Derived_Type_Statement, "SgDerivedTypeStatement"},
  282. {TEMP_Attribute_Specification_Statement, "SgAttributeSpecificationStatement"},
  283. {TEMP_Allocate_Statement, "SgAllocateStatement"},
  284. {TEMP_Deallocate_Statement, "SgDeallocateStatement"},
  285. {TEMP_Contains_Statement, "SgContainsStatement"},
  286. {TEMP_Sequence_Statement, "SgSequenceStatement"},
  287. {TEMP_Else_Where_Statement, "SgElseWhereStatement"},
  288. {TEMP_Arithmetic_If_Statement, "SgArithmeticIfStatement"},
  289. {TEMP_Assign_Statement, "SgAssignStatement"},
  290. {TEMP_Computed_Goto_Statement, "SgComputedGotoStatement"},
  291. {TEMP_Assigned_Goto_Statement, "SgAssignedGotoStatement"},
  292. {NAMESPACE_DECLARATION_STMT, "SgNamespaceDeclarationStatement"},
  293. {NAMESPACE_ALIAS_DECLARATION_STMT, "SgNamespaceAliasDeclarationStatement"},
  294. {NAMESPACE_DEFINITION_STMT, "SgNamespaceDefinitionStatement"},
  295. {USING_DECLARATION_STMT, "SgUsingDeclarationStatement"},
  296. {USING_DIRECTIVE_STMT, "SgUsingDirectiveStatement"},
  297. {TEMPLATE_INST_DIRECTIVE_STMT, "SgTemplateInstantiationDirectiveStatement"},
  298. {INCLUDE_DIRECTIVE_STMT, "SgIncludeDirectiveStatement"},
  299. {DEFINE_DIRECTIVE_STMT, "SgDefineDirectiveStatement"},
  300. {UNDEF_DIRECTIVE_STMT, "SgUndefDirectiveStatement"},
  301. {IFDEF_DIRECTIVE_STMT, "SgIfdefDirectiveStatement"},
  302. {IFNDEF_DIRECTIVE_STMT, "SgIfndefDirectiveStatement"},
  303. {IF_DIRECTIVE_STMT, "SgIfDirectiveStatement"},
  304. {DEAD_IF_DIRECTIVE_STMT, "SgDeadIfDirectiveStatement"},
  305. {ELSE_DIRECTIVE_STMT, "SgElseDirectiveStatement"},
  306. {ELSEIF_DIRECTIVE_STMT, "SgElseifDirectiveStatement"},
  307. {ENDIF_DIRECTIVE_STMT, "SgEndifDirectiveStatement"},
  308. {LINE_DIRECTIVE_STMT, "SgLineDirectiveStatement"},
  309. {WARNING_DIRECTIVE_STMT, "SgWarningDirectiveStatement"},
  310. {ERROR_DIRECTIVE_STMT, "SgErrorDirectiveStatement"},
  311. {EMPTY_DIRECTIVE_STMT, "SgEmptyDirectiveStatement"},
  312. {C_LINKAGE_START_STMT, "SgClinkageStartStatement"},
  313. {C_LINKAGE_END_STMT, "SgClinkageEndStatement"},
  314. {VARIABLE_NAME, "SgVariableSymbol"},
  315. {FUNCTYPE_NAME, "SgFunctionTypeSymbol"},
  316. {CLASS_NAME, "SgClassSymbol"},
  317. {TEMPLATE_NAME, "SgTemplateSymbol"},
  318. {ENUM_NAME, "SgEnumSymbol"},
  319. {FIELD_NAME, "SgEnumFieldSymbol"},
  320. {TYPEDEF_NAME, "SgTypedefSymbol"},
  321. {MEMBER_FUNC_NAME, "SgMemberFunctionSymbol"},
  322. {LABEL_NAME, "SgLabelSymbol"},
  323. {DEFAULT_NAME, "SgDefaultSymbol"},
  324. {NAMESPACE_NAME, "SgNamespaceSymbol"},
  325. {INTRINSIC_SYMBOL, "SgIntrinsicSymbol"},
  326. {MODULE_SYMBOL, "SgModuleSymbol"},
  327. {INTERFACE_SYMBOL, "SgInterfaceSymbol"},
  328. {COMMON_SYMBOL, "SgCommonSymbol"},
  329. {TOKEN, "SgToken"},
  330. {Cxx_Grammar_LAST_TAG, "last tag" }
  331. };
  332. #line 1 ""
  333. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  334. // ********************************************************
  335. // member functions specific to each node in the grammar
  336. // ********************************************************
  337. #line 6 "../Grammar/grammarClassDefinitionMacros.macro before marker MEMBER_FUNCTION_DEFINITIONS"
  338. #line 1 ""
  339. #line 1 ""
  340. // Start of memberFunctionString
  341. // End of memberFunctionString
  342. // Start of memberFunctionString
  343. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  344. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  345. SgNode*
  346. SgNode::get_freepointer () const
  347. {
  348. assert (this != NULL);
  349. return p_freepointer;
  350. }
  351. void
  352. SgNode::set_freepointer ( SgNode* freepointer )
  353. {
  354. assert (this != NULL);
  355. set_isModified(true);
  356. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  357. if (p_freepointer != NULL && freepointer != NULL && p_freepointer != freepointer)
  358. {
  359. printf ("Warning: freepointer = %p overwriting valid pointer p_freepointer = %p \n",freepointer,p_freepointer);
  360. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  361. printf ("Error fails assertion (p_freepointer != NULL && freepointer != NULL && p_freepointer != freepointer) is false\n");
  362. ROSE_ASSERT(false);
  363. #endif
  364. }
  365. #endif
  366. p_freepointer = freepointer;
  367. }
  368. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  369. // End of memberFunctionString
  370. // Start of memberFunctionString
  371. #line 331 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Common.code"
  372. // *** COMMON CODE SECTION BEGINS HERE ***
  373. int
  374. SgNode::getVariant() const
  375. {
  376. // This function is used in ROSE while "variant()" is used in SAGE
  377. assert(this != NULL);
  378. return variant();
  379. }
  380. // This function is used in ROSE in treeTraversal code
  381. // eventually replaces getVariant() and variant()
  382. // though after variant() has been removed for a while we will
  383. // want to change the name of variantT() back to variant()
  384. // (since the "T" was ment to stand for temporary).
  385. // When this happens the variantT() will be depricated.
  386. VariantT
  387. SgNode::variantT() const {
  388. return V_SgNode;
  389. }
  390. #if 0
  391. int
  392. SgNode::variant() const
  393. {
  394. // This function is used in SAGE
  395. assert(this != NULL);
  396. return NodeTag;
  397. }
  398. #endif
  399. const char*
  400. SgNode::sage_class_name() const
  401. {
  402. assert(this != NULL);
  403. return "SgNode";
  404. }
  405. std::string
  406. SgNode::class_name() const
  407. {
  408. assert(this != NULL);
  409. return "SgNode";
  410. }
  411. // DQ (11/26/2005): Support for visitor pattern mechanims
  412. // (inferior to ROSE traversal mechanism, experimental).
  413. void
  414. SgNode::executeVisitorMemberFunction (ROSE_VisitorPattern & visitor)
  415. {
  416. ROSE_ASSERT(this != NULL);
  417. visitor.visit(this);
  418. }
  419. // *** COMMON CODE SECTION ENDS HERE ***
  420. // End of memberFunctionString
  421. // Start of memberFunctionString
  422. #line 769 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Node.code"
  423. // ########################################
  424. // Some global variables used within SAGE 3
  425. // ########################################
  426. // declaration of variable to control internal output of debuging information
  427. int SAGE_DEBUG = 0; // default value is zero
  428. // JJW (1/19/2007): Added global variable for whether virtual CFG is
  429. // interprocedural
  430. bool interproceduralControlFlowGraph = false;
  431. // ###############################
  432. // Start of source code for SgNode
  433. // ###############################
  434. // Support for global function type symbol table (moved to be static data pointer)
  435. // DQ (1/31/2006): Modified to build all types in the memory pools
  436. // SgFunctionTypeTable* SgNode::Sgfunc_type_table = new SgFunctionTypeTable();
  437. // SgFunctionTypeTable* SgNode::p_globalFunctionTypeTable = new SgFunctionTypeTable();
  438. SgFunctionTypeTable* SgNode::p_globalFunctionTypeTable = NULL;
  439. // DQ (3/12/2007): Added mangled name map to improve performance of generating mangled names
  440. std::map<SgNode*,std::string> SgNode::p_globalMangledNameMap;
  441. std::map<std::string,int> SgNode::p_shortMangledNameCache;
  442. // DQ (10/5/2007): Added IR node specific function to permit copies, via AST copy(), to be fixedup
  443. // Usually this will correct scopes and in a few cases build child IR nodes that are not traversed
  444. // (and thus shared in the result from the automatically generated copy function).
  445. void
  446. SgNode::fixupCopy(SgNode* copy, SgCopyHelp & help) const
  447. {
  448. // This is the empty default inplementation, not a problem if it is called!
  449. }
  450. // DQ (1/31/2006): We might want this function to be automaticaly generated
  451. // except that then we could not support the assertion. Also we
  452. // don't have to set this function, though perhaps the interface function
  453. // should be implemented to set it just on general principles.
  454. SgFunctionTypeTable*
  455. SgNode::get_globalFunctionTypeTable()
  456. {
  457. // DQ (1/31/2006): If there is no global function type symbol table then build one
  458. if (p_globalFunctionTypeTable == NULL)
  459. {
  460. // printf ("In SgNode::get_globalFunctionTypeTable(): p_globalFunctionTypeTable == NULL (allocating the global function type symbol table) \n");
  461. p_globalFunctionTypeTable = new SgFunctionTypeTable();
  462. ROSE_ASSERT(p_globalFunctionTypeTable != NULL);
  463. // p_globalFunctionTypeTable->set_parent(???);
  464. }
  465. ROSE_ASSERT(p_globalFunctionTypeTable != NULL);
  466. return p_globalFunctionTypeTable;
  467. }
  468. void
  469. SgNode::set_globalFunctionTypeTable ( SgFunctionTypeTable* globalFunctionTypeTable )
  470. {
  471. p_globalFunctionTypeTable = globalFunctionTypeTable;
  472. }
  473. // DQ (3/17/2007): return reference to the global mangled name map (the use
  474. // of this map is a performance optimization).
  475. std::map<SgNode*,std::string> &
  476. SgNode::get_globalMangledNameMap()
  477. {
  478. return p_globalMangledNameMap;
  479. }
  480. #if 0
  481. std::map<SgNode*,std::string> &
  482. SgNode:: get_mangledNameCache()
  483. {
  484. return p_mangledNameCache;
  485. }
  486. #endif
  487. std::map<std::string, int> &
  488. SgNode:: get_shortMangledNameCache()
  489. {
  490. return p_shortMangledNameCache;
  491. }
  492. // DQ (3/17/2007): return reference to the global mangled name map (the use
  493. // of this map is a performance optimization).
  494. void
  495. SgNode::clearGlobalMangledNameMap()
  496. {
  497. // Remove all elements from the globalMangledNameMap
  498. // p_globalMangledNameMap.erase(p_globalMangledNameMap.begin(),p_globalMangledNameMap.end());
  499. p_globalMangledNameMap.clear();
  500. // DQ (6/26/2007): The function types require the same mangled names be generated across
  501. // clears of the p_globalMangledNameMap cache. Clearing the short name map breaks this.
  502. // It might be that we don't want to clear the short name map to permit the same mangled
  503. // names to be regenerated. However, for the purposes of AST merge this is not a problem.
  504. // p_shortMangledNameCache.clear();
  505. }
  506. #if 0
  507. // DQ (3/12/2007): Not clear how to do this!
  508. SgName
  509. SgNode::lookupMangledName(const SgNode* node) const
  510. {
  511. string returnString;
  512. // DQ (3/12/2007): Experiment with mangled name map (caching for performance improvement)
  513. const SgName name = "__global__";
  514. SgGlobal* global = const_cast<SgGlobal*>(this);
  515. std::map<SgNode*,std::string>::iterator i = p_globalMangledNameMap.find(global);
  516. if (i != p_globalMangledNameMap.end())
  517. {
  518. return i->second.c_str();
  519. }
  520. else
  521. {
  522. p_globalMangledNameMap[global] = name;
  523. return name;
  524. }
  525. return SgName(returnString);
  526. }
  527. #endif
  528. // DQ (4/10/2006): These are the default virtual function definitions (each returns an error)
  529. void
  530. SgNode::addNewAttribute( std::string s, AstAttribute* a )
  531. {
  532. printf ("Error: calling SgNode::addNewAttribute(%s) \n",s.c_str());
  533. ROSE_ASSERT(false);
  534. }
  535. void
  536. SgNode::setAttribute( std::string s, AstAttribute* a )
  537. {
  538. printf ("Error: calling SgNode::setAttribute(%s) \n",s.c_str());
  539. ROSE_ASSERT(false);
  540. }
  541. AstAttribute*
  542. SgNode::getAttribute(std::string s) const
  543. {
  544. printf ("Error: calling SgNode::getAttribute(%s) \n",s.c_str());
  545. ROSE_ASSERT(false);
  546. return NULL;
  547. }
  548. void
  549. SgNode::updateAttribute( std::string s, AstAttribute* a )
  550. {
  551. // formerly called: replace
  552. printf ("Error: calling SgNode::updateAttribute(%s) \n",s.c_str());
  553. ROSE_ASSERT(false);
  554. }
  555. void
  556. SgNode::removeAttribute(std::string s)
  557. {
  558. printf ("Error: calling SgNode::removeAttribute(%s) \n",s.c_str());
  559. ROSE_ASSERT(false);
  560. }
  561. bool
  562. SgNode::attributeExists(std::string s) const
  563. {
  564. printf ("Error: calling SgNode::attributeExists(%s) \n",s.c_str());
  565. ROSE_ASSERT(false);
  566. }
  567. int
  568. SgNode::numberOfAttributes() const
  569. {
  570. int returnValue = 0;
  571. return returnValue;
  572. }
  573. AstAttributeMechanism*
  574. SgNode::get_attributeMechanism() const
  575. {
  576. // DQ (4/10/2006): virtual function defined at the SgNode and redefined whereever there is
  577. // an AstAttributeMechanism defined! Note that there is no set function defined.
  578. return NULL;
  579. }
  580. void
  581. SgNode::set_attributeMechanism(AstAttributeMechanism* a)
  582. {
  583. // Nothing to do here, but we need this virtual function so that the correct access
  584. // function will be call on IR nodes where the AstAttributeMechanism is defined as
  585. // a data member.
  586. printf ("Error: SgNode::set_attributeMechanism(AstAttributeMechanism* a) has been called \n");
  587. ROSE_ASSERT(false);
  588. }
  589. #if 0
  590. void
  591. SgNode::print( std::ostream* os, /* 0 uses the default */
  592. int maxdepth) /* controlling function*/
  593. {
  594. Sg_print_info().reset(os, maxdepth);
  595. this->_print(0);
  596. }
  597. bool
  598. SgNode::_print(int depth) const
  599. {
  600. return Sg_print_info().output_class(this,sage_class_name(), depth + 1);
  601. }
  602. #endif
  603. #if 0
  604. //! implementation in base class - overridden by SgLocatedNode::directives(ostream&)
  605. void
  606. SgNode::directives(std::ostream& os)
  607. {
  608. // to be overridden by SgLocatedNode::directives(ostream&)
  609. }
  610. #endif
  611. #if 0
  612. void
  613. SgNode::unparse(SgUnparse_Info& info, std::ostream& os)
  614. {
  615. /* nothing to be done in general: only comments for statements*/
  616. directives(os);
  617. logical_unparse(info,os);
  618. }
  619. void
  620. SgNode::unparse_helper(SgUnparse_Info& info, std::ostream& os)
  621. {
  622. }
  623. void
  624. SgNode::logical_unparse(SgUnparse_Info& info, std::ostream& os)
  625. {
  626. }
  627. #endif
  628. void
  629. SgNode::post_construction_initialization()
  630. {
  631. // default implementation does nothing!
  632. }
  633. // DQ (7/23/2005): Let these be automatically generated by ROSETTA!
  634. // See note above where these are proptotyped, they have to be defined
  635. // explicitly to avoid endless recursion!
  636. void
  637. SgNode::set_isModified ( bool isModified)
  638. {
  639. p_isModified = isModified;
  640. }
  641. bool
  642. SgNode::get_isModified () const
  643. {
  644. return p_isModified;
  645. }
  646. bool
  647. SgNode::get_isVisited () const
  648. {
  649. // The p_isVisited flag has been removed, it is an error to call this function.
  650. assert (this != NULL);
  651. printf ("Error: The p_isVisited flag has been removed, it is an error to call this function (get_isVisited). \n");
  652. ROSE_ASSERT(false);
  653. return true;
  654. }
  655. void
  656. SgNode::set_isVisited ( bool isVisited )
  657. {
  658. // The p_isVisited flag has been removed, it is an error to call this function.
  659. assert (this != NULL);
  660. printf ("Error: The p_isVisited flag has been removed, it is an error to call this function (set_isVisited). \n");
  661. ROSE_ASSERT(false);
  662. set_isModified(true);
  663. // p_isVisited = isVisited;
  664. /* */
  665. }
  666. // ! Permits specification of parent node (connects the AST tree)
  667. /* ! This function is called internally to connect the elements of the grammar to form the AST.
  668. */
  669. void
  670. SgNode::set_parent ( SgNode* parent )
  671. {
  672. // ROSE_ASSERT (parent != NULL); // QY: should allow setting parent to NULL when detaching SgNodes
  673. // DQ (9/24/2004): Enforce this simple rule!
  674. ROSE_ASSERT(this != NULL);
  675. ROSE_ASSERT(this != parent);
  676. // printf ("In SgNode::set_parent(): Setting parent of %p = %s to %p = %s \n",this,class_name().c_str(),parent,parent->class_name().c_str());
  677. p_parent = parent;
  678. // ROSE_ASSERT( ( this != (SgNode*)(0xb484411c) ) || ( parent != (SgNode*)(0xb46fe008) ) );
  679. // I think this should be always be true, so let's inforce it (this happends for test2005_64.C)
  680. if ( ( variantT() == V_SgClassDeclaration ) && ( parent->variantT() == V_SgFunctionParameterList ) )
  681. {
  682. printf ("Warning: Found case in set_parent() where this is a SgClassDeclaration and parent is a SgFunctionParameterList \n");
  683. // get_file_info()->display("Warning: Found case in set_parent() where this is a SgClassDeclaration and parent is a SgFunctionParameterList");
  684. }
  685. // ROSE_ASSERT( ( variantT() != V_SgClassDeclaration ) || ( parent->variantT() != V_SgFunctionParameterList ) );
  686. // We should not be setting the parent on SgType IR nodes
  687. ROSE_ASSERT( isSgType(this) == NULL );
  688. }
  689. /*! \brief Set the parent node.
  690. This function is called internally to connect the elements of the grammar to form the
  691. AST. This is the backward reference up the tree.
  692. \internal We can't have ROSETTA build these access functions since we want specific
  693. checking of values for NULL pointers (parent point is NULL only for SgProject)
  694. */
  695. SgNode*
  696. SgNode::get_parent () const
  697. {
  698. ROSE_ASSERT(this != NULL);
  699. SgNode* returnNode = p_parent;
  700. // DQ (5/24/2006): I would like to allow SgSymbols to have a valid parent pointer since it can be used to reference
  701. // the symbol table as a way to support better debugging within the AST merge mechanims.
  702. // Sage II semantics: Types and Symbols always have a NULL parent (This is the way it is implemented (from Sage II))
  703. // if ( (isSgType( const_cast<SgNode*>(this) ) != NULL) || (isSgSymbol( const_cast<SgNode*>(this) ) != NULL) )
  704. if ( isSgType( const_cast<SgNode*>(this) ) != NULL )
  705. returnNode = NULL;
  706. return returnNode;
  707. }
  708. // DQ (3/8/2007): Added more efficent implementation to support AST consitency tests and other work.
  709. //! Query function for if the input IR nodes is a child of the current IR node.
  710. bool
  711. SgNode::isChild ( SgNode* node ) const
  712. {
  713. return (getChildIndex(node) != -1);
  714. }
  715. vector<string>
  716. SgNode::buildCommandLineToSubstituteTransformationFile( const vector<string>& argv, std::string newFileName )
  717. {
  718. int fileNameCounter = 0;
  719. int fileNameLocation = 0;
  720. // return a copy of the commandline input to this function
  721. vector<string> transformation_argv(argv.size());
  722. // printf ("In buildCommandLineToSubstituteTransformationFile(): argc = %d \n",argc);
  723. // copy all the entries in the command line.
  724. for (unsigned int i=0; i < argv.size(); i++)
  725. {
  726. // Count up the number of filenames (if it is ZERO then this is likely a link line called
  727. // using the compiler (required for template processing in C++ with most compilers) if there
  728. // is ONE then this is the source file. Currently their can only be ONE source file specified.
  729. // most options appear as -<option>
  730. // have to process +w2 (warnings option) on some compilers so include +<option>
  731. if ( argv[i].size() < 1 || (argv[i][0] != '-') || (argv[i][0] != '+') )
  732. {
  733. unsigned int length = argv[i].size();
  734. // printf ("Look for file names: argv[%d] = %s length = %d \n",i,argv[i],length);
  735. // look only for .c and .C files (source code files)
  736. // The length has to be greater then 2 or else we will generate a purify error!
  737. if ( (length > 2) && (argv[i][length-2] == '.') && ( (argv[i][length-1] == 'c') || (argv[i][length-1] == 'C') ) )
  738. {
  739. // printf ("Found a filename = %s \n",argv[i]);
  740. // ROSE::sourceFileNamesWithPath [fileNameCounter] = strdup(argv[i]);
  741. // ROSE::sourceFileNamesWithoutPath [fileNameCounter] = strdup(argv[i]);
  742. // argv[i] = "rose_transformation.C";
  743. // transformation_argv[i] = "rose_transformation.C";
  744. transformation_argv[i] = strdup(newFileName.c_str());
  745. // record the location of the filename in the command line and the number of filenames
  746. fileNameLocation = i;
  747. fileNameCounter++;
  748. }
  749. else
  750. {
  751. transformation_argv [i] = argv[i];
  752. }
  753. }
  754. else
  755. {
  756. transformation_argv [i] = argv[i];
  757. }
  758. // printf ("In loop: i = %d \n",i);
  759. }
  760. // For now ets only debug the case of a single file specified on the command line
  761. ROSE_ASSERT (fileNameCounter == 1);
  762. ROSE_ASSERT (fileNameLocation > 0);
  763. // We have found the location of the filename in the command line (now modify it)
  764. // now delete the original file name
  765. // delete argv[fileNameLocation];
  766. // argv[fileNameLocation] = "rose_transformation.C";
  767. // argv[fileNameLocation] = "/home/dquinlan/ROSE/NEW_ROSE/TransformationSpecification/rose_transformation.C";
  768. // argv[fileNameLocation] = "/home/dquinlan2/ROSE/SUN_CC_NOPURIFY/TransformationSpecification/rose_transformation.C";
  769. // argv[fileNameLocation] = "rose_transformation.C";
  770. #if 0
  771. // This is not longer required (EDG sets its
  772. // primary_source_file_name internally from the
  773. // command line directly).
  774. // Since it is a problem to call EDG more than once with
  775. // (EDG comand line processing can only be called once)
  776. // the easiest thing to do is change the name of the primary
  777. // source file. See notes in the TODO document.
  778. EDG_secondarySourceFile = argv[fileNameLocation];
  779. #endif
  780. // printf ("Command line modified to include \"rose_transformation.C\"! \n");
  781. return transformation_argv;
  782. }
  783. std::string
  784. SgNode::unparseToString(SgUnparse_Info* info) const
  785. {
  786. // DQ (4/4/2006): Added optional parameter to customize unparsing
  787. // Generate the string (don't pass a SgUnparse_Info object so that we can use the
  788. // default settings).
  789. std::string outputString = globalUnparseToString(this,info);
  790. return outputString;
  791. }
  792. std::string
  793. SgNode::unparseToCompleteString()
  794. {
  795. // Generate the string (pass a SgUnparse_Info object)
  796. SgUnparse_Info* inputUnparseInfoPointer = new SgUnparse_Info();
  797. inputUnparseInfoPointer->unset_SkipComments(); // generate comments
  798. inputUnparseInfoPointer->unset_SkipWhitespaces(); // generate all whitespaces to format the code
  799. std::string outputString = globalUnparseToString(this,inputUnparseInfoPointer);
  800. return outputString;
  801. }
  802. // DQ (10/8/2007): I would like to get rid of this mechanism in the future.
  803. SgShallowCopy *SgShallowCopy::p_static_instance = NULL;
  804. SgTreeCopy *SgTreeCopy ::p_static_instance = NULL;
  805. void
  806. SgCopyHelp::insertCopiedNodePair( const SgNode* key, SgNode* value )
  807. {
  808. // DQ (10/8/2007): This function support the saving of state used to associated original IR nodes with the copies made of them so that symbols can be updated.
  809. if (copiedNodeMap.find(key) == copiedNodeMap.end())
  810. {
  811. // Add the node to the map...
  812. copiedNodeMap[key] = value;
  813. }
  814. }
  815. SgNode*
  816. SgTreeCopy::copyAst( const SgNode *n )
  817. {
  818. #if 0
  819. if (isSgType( const_cast<SgNode*>(n) ) != NULL)
  820. {
  821. return const_cast<SgNode *>(n);
  822. }
  823. SgNode *nCopy = n->copy(*this);
  824. nCopy->set_parent(NULL);
  825. return nCopy;
  826. #else
  827. // DQ (10/8/2007): I have modified this function to have a single return.
  828. // This function is called by the copy mechanism to copy AST child trees.
  829. SgNode *nCopy = NULL;
  830. // If this is a SgType, then force it to be shared, since all SgTypes are shared.
  831. // if (isSgType( const_cast<SgNode*>(n) ) != NULL)
  832. if (isSgType(n) != NULL)
  833. {
  834. // Share the reference to the IR node.
  835. nCopy = const_cast<SgNode *>(n);
  836. }
  837. else
  838. {
  839. // If this is a class definition then only do a deep copy if it is from a defining class declaration.
  840. const SgClassDefinition* classDefinition = isSgClassDefinition(n);
  841. if (classDefinition != NULL)
  842. {
  843. ROSE_ASSERT(classDefinition->get_parent() != NULL);
  844. SgClassDeclaration* classDeclaration = isSgClassDeclaration(classDefinition->get_parent());
  845. if (classDeclaration == classDeclaration->get_definingDeclaration())
  846. {
  847. // Do a deep copy on this IR node.
  848. nCopy = n->copy(*this);
  849. }
  850. else
  851. {
  852. // Share the reference to the IR node.
  853. nCopy = const_cast<SgNode *>(n);
  854. }
  855. }
  856. else
  857. {
  858. // Do a deep copy on this IR node.
  859. nCopy = n->copy(*this);
  860. }
  861. // Set the parent to NULL, the copy mechanism we set it correctly ...
  862. nCopy->set_parent(NULL);
  863. }
  864. return nCopy;
  865. #endif
  866. }
  867. #if 0
  868. bool SgTreeCopy :: clone_node( const SgNode *n ) const
  869. {
  870. if (isSgType( const_cast<SgNode*>(n) ) != 0)
  871. return false;
  872. return true;
  873. }
  874. #endif
  875. unsigned int
  876. SgNode::cfgIndexForEnd() const {
  877. ROSE_ASSERT (!"CFG functions only work on SgExpression, SgStatement, and SgInitializedName");
  878. return 0;
  879. }
  880. bool
  881. SgNode::cfgIsIndexInteresting(unsigned int) const {
  882. ROSE_ASSERT (!"CFG functions only work on SgExpression, SgStatement, and SgInitializedName");
  883. return false;
  884. }
  885. unsigned int
  886. SgNode::cfgFindChildIndex(SgNode*) {
  887. ROSE_ASSERT (!"CFG functions only work on SgExpression, SgStatement, and SgInitializedName");
  888. return 0;
  889. }
  890. unsigned int
  891. SgNode::cfgFindNextChildIndex(SgNode*) {
  892. ROSE_ASSERT (!"CFG functions only work on SgExpression, SgStatement, and SgInitializedName");
  893. return 0;
  894. }
  895. std::vector<VirtualCFG::CFGEdge>
  896. SgNode::cfgOutEdges(unsigned int) {
  897. ROSE_ASSERT (!"CFG functions only work on SgExpression, SgStatement, and SgInitializedName");
  898. return std::vector<VirtualCFG::CFGEdge>();
  899. }
  900. std::vector<VirtualCFG::CFGEdge>
  901. SgNode::cfgInEdges(unsigned int) {
  902. ROSE_ASSERT (!"CFG functions only work on SgExpression, SgStatement, and SgInitializedName");
  903. return std::vector<VirtualCFG::CFGEdge>();
  904. }
  905. // End of memberFunctionString
  906. // Start of memberFunctionString
  907. #line 1362 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Node.code"
  908. #if 0
  909. bool SgNode::error()
  910. {
  911. // Put error checking here
  912. ROSE_ASSERT (this != NULL);
  913. if (getVariant() != NodeTag)
  914. {
  915. printf ("Error in SgNode::error(): SgNode object has a %s variant \n",
  916. Cxx_GrammarTerminalNames[getVariant()].name);
  917. // printf ("Error in SgNode::error() \n");
  918. ROSE_ABORT();
  919. }
  920. // ROSE_ASSERT (getVariant() == SgNodeTag);
  921. ROSE_ASSERT (getVariant() == NodeTag);
  922. return false; // //::error();
  923. }
  924. #endif
  925. // End of memberFunctionString
  926. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarVariantFunctionDefinitionMacros.macro"
  927. int
  928. SgNode::variant() const
  929. {
  930. // This function is generated from grammarVariantFunctionDefinitionMacros.macro
  931. #ifdef DEBUG
  932. // printf ("In SgNode::variant() const \n");
  933. #endif
  934. assert(this != NULL);
  935. return NodeTag;
  936. }
  937. #line 1 ""
  938. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarIsClassNameFunctionDefinitionMacros.macro"
  939. SgNode* isSgNode ( SgNode* inputDerivedClassPointer )
  940. {
  941. return dynamic_cast<SgNode*>(inputDerivedClassPointer);
  942. }
  943. // DQ (11/8/2003): Added version of functions taking const pointer
  944. const SgNode* isSgNode ( const SgNode* inputDerivedClassPointer )
  945. {
  946. return dynamic_cast<const SgNode*>(inputDerivedClassPointer);
  947. }
  948. #line 1 ""
  949. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  950. /**
  951. \brief Generated destructor
  952. This destructor is automatically generated (by ROSETTA). This destructor
  953. only frees memory of data members associated with the parts of the current IR node which
  954. are NOT traversed. Those data members that are part of a traversal can be freed using
  955. a traversal (calling this destructor on all children in a post-order traversal). Such
  956. a traversal which deletes a whole AST is provided by DeleteSgTree(SgNode*).
  957. \internal All IR nodes with data members specified using setDataPrototype() within ROSETTA
  958. are specified as NO_DELETE is also specified as DEF_TRAVERSAL. Those marked as
  959. NO_TRAVERSAL can be marked as NO_DELETE or DEF_DELETE.
  960. \note All SgSymbol IR nodes are deleted when the symbol table is deleted. Currently most
  961. SgType IR nodes are not deleted (since they are shared). Also, all STL lists of
  962. pointers are not yet implemented to call delete on eash pointer in the container.
  963. (This could be done by derivation from the STL containers to define containers that
  964. automatically deleted their members.)
  965. */
  966. SgNode::~SgNode ()
  967. {
  968. #if 0
  969. // debugging information!
  970. printf ("In SgNode::~SgNode (destructor) \n");
  971. #endif
  972. #if 1
  973. // DQ (6/25/2006): Commented out destructor body to allow the File I/O to work.
  974. // case: not a listType for parent
  975. p_parent = NULL; // non list case
  976. // case: not a listType for isModified
  977. p_isModified = false; // non list case
  978. #line 32 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  979. #endif
  980. }
  981. #line 1 ""
  982. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarConstructorDefinitionMacros.macro"
  983. // Generated constructor
  984. SgNode::SgNode ( )
  985. {
  986. #ifdef DEBUG
  987. // printf ("In SgNode::SgNode () sage_class_name() = %s \n",sage_class_name());
  988. #endif
  989. p_parent = NULL;
  990. p_isModified = false;
  991. p_freepointer = AST_FileIO::IS_VALID_POINTER();
  992. #line 11 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarConstructorDefinitionMacros.macro"
  993. // Test the variant virtual function
  994. assert(NodeTag == variant());
  995. post_construction_initialization();
  996. // Test the isSgNode() function since it has been problematic
  997. assert(isSgNode(this) != NULL);
  998. }
  999. #line 1 ""
  1000. #line 1 ""
  1001. #line 6 "../Grammar/grammarClassDefinitionMacros.macro after marker MEMBER_FUNCTION_DEFINITIONS"
  1002. #line 7 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  1003. // ********************************************************
  1004. // member functions common across all array grammar objects
  1005. // ********************************************************
  1006. #line 1 ""
  1007. #line 1 ""
  1008. #line 1 ""
  1009. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  1010. // ********************************************************
  1011. // member functions specific to each node in the grammar
  1012. // ********************************************************
  1013. #line 6 "../Grammar/grammarClassDefinitionMacros.macro before marker MEMBER_FUNCTION_DEFINITIONS"
  1014. #line 1 ""
  1015. #line 1 ""
  1016. // Start of memberFunctionString
  1017. #line 3893 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Support.code"
  1018. // No functions defined for the GrammarSource
  1019. // End of memberFunctionString
  1020. // Start of memberFunctionString
  1021. #line 331 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Common.code"
  1022. // *** COMMON CODE SECTION BEGINS HERE ***
  1023. int
  1024. SgSupport::getVariant() const
  1025. {
  1026. // This function is used in ROSE while "variant()" is used in SAGE
  1027. assert(this != NULL);
  1028. return variant();
  1029. }
  1030. // This function is used in ROSE in treeTraversal code
  1031. // eventually replaces getVariant() and variant()
  1032. // though after variant() has been removed for a while we will
  1033. // want to change the name of variantT() back to variant()
  1034. // (since the "T" was ment to stand for temporary).
  1035. // When this happens the variantT() will be depricated.
  1036. VariantT
  1037. SgSupport::variantT() const {
  1038. return V_SgSupport;
  1039. }
  1040. #if 0
  1041. int
  1042. SgSupport::variant() const
  1043. {
  1044. // This function is used in SAGE
  1045. assert(this != NULL);
  1046. return SupportTag;
  1047. }
  1048. #endif
  1049. const char*
  1050. SgSupport::sage_class_name() const
  1051. {
  1052. assert(this != NULL);
  1053. return "SgSupport";
  1054. }
  1055. std::string
  1056. SgSupport::class_name() const
  1057. {
  1058. assert(this != NULL);
  1059. return "SgSupport";
  1060. }
  1061. // DQ (11/26/2005): Support for visitor pattern mechanims
  1062. // (inferior to ROSE traversal mechanism, experimental).
  1063. void
  1064. SgSupport::executeVisitorMemberFunction (ROSE_VisitorPattern & visitor)
  1065. {
  1066. ROSE_ASSERT(this != NULL);
  1067. visitor.visit(this);
  1068. }
  1069. // *** COMMON CODE SECTION ENDS HERE ***
  1070. // End of memberFunctionString
  1071. // Start of memberFunctionString
  1072. #line 1387 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Node.code"
  1073. #if 0
  1074. //! Error checking support
  1075. /*! Verifies the following:
  1076. - working getVariant() member function
  1077. - calls base class's error() member function
  1078. Every class has one of these functions.
  1079. */
  1080. bool
  1081. SgSupport::error()
  1082. {
  1083. // Put error checking here
  1084. ROSE_ASSERT (this != NULL);
  1085. if (getVariant() != SupportTag)
  1086. {
  1087. printf ("Error in SgSupport::error(): SgSupport object has a %s variant \n",
  1088. Cxx_GrammarTerminalNames[getVariant()].name);
  1089. // printf ("Error in SgSupport::error() \n");
  1090. ROSE_ABORT();
  1091. }
  1092. ROSE_ASSERT (getVariant() == SupportTag);
  1093. return SgNode::error();
  1094. }
  1095. #endif
  1096. // End of memberFunctionString
  1097. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarVariantFunctionDefinitionMacros.macro"
  1098. int
  1099. SgSupport::variant() const
  1100. {
  1101. // This function is generated from grammarVariantFunctionDefinitionMacros.macro
  1102. #ifdef DEBUG
  1103. // printf ("In SgSupport::variant() const \n");
  1104. #endif
  1105. assert(this != NULL);
  1106. return SupportTag;
  1107. }
  1108. #line 1 ""
  1109. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarIsClassNameFunctionDefinitionMacros.macro"
  1110. SgSupport* isSgSupport ( SgNode* inputDerivedClassPointer )
  1111. {
  1112. return dynamic_cast<SgSupport*>(inputDerivedClassPointer);
  1113. }
  1114. // DQ (11/8/2003): Added version of functions taking const pointer
  1115. const SgSupport* isSgSupport ( const SgNode* inputDerivedClassPointer )
  1116. {
  1117. return dynamic_cast<const SgSupport*>(inputDerivedClassPointer);
  1118. }
  1119. #line 1 ""
  1120. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  1121. /**
  1122. \brief Generated destructor
  1123. This destructor is automatically generated (by ROSETTA). This destructor
  1124. only frees memory of data members associated with the parts of the current IR node which
  1125. are NOT traversed. Those data members that are part of a traversal can be freed using
  1126. a traversal (calling this destructor on all children in a post-order traversal). Such
  1127. a traversal which deletes a whole AST is provided by DeleteSgTree(SgNode*).
  1128. \internal All IR nodes with data members specified using setDataPrototype() within ROSETTA
  1129. are specified as NO_DELETE is also specified as DEF_TRAVERSAL. Those marked as
  1130. NO_TRAVERSAL can be marked as NO_DELETE or DEF_DELETE.
  1131. \note All SgSymbol IR nodes are deleted when the symbol table is deleted. Currently most
  1132. SgType IR nodes are not deleted (since they are shared). Also, all STL lists of
  1133. pointers are not yet implemented to call delete on eash pointer in the container.
  1134. (This could be done by derivation from the STL containers to define containers that
  1135. automatically deleted their members.)
  1136. */
  1137. SgSupport::~SgSupport ()
  1138. {
  1139. #if 0
  1140. // debugging information!
  1141. printf ("In SgSupport::~SgSupport (destructor) \n");
  1142. #endif
  1143. #if 1
  1144. // DQ (6/25/2006): Commented out destructor body to allow the File I/O to work.
  1145. #line 32 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  1146. #endif
  1147. }
  1148. #line 1 ""
  1149. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarConstructorDefinitionMacros.macro"
  1150. // Generated constructor
  1151. SgSupport::SgSupport ( )
  1152. : SgNode()
  1153. {
  1154. #ifdef DEBUG
  1155. // printf ("In SgSupport::SgSupport () sage_class_name() = %s \n",sage_class_name());
  1156. #endif
  1157. // Test the variant virtual function
  1158. assert(SupportTag == variant());
  1159. post_construction_initialization();
  1160. // Test the isSgSupport() function since it has been problematic
  1161. assert(isSgSupport(this) != NULL);
  1162. }
  1163. #line 1 ""
  1164. #line 1 ""
  1165. #line 6 "../Grammar/grammarClassDefinitionMacros.macro after marker MEMBER_FUNCTION_DEFINITIONS"
  1166. #line 7 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  1167. // ********************************************************
  1168. // member functions common across all array grammar objects
  1169. // ********************************************************
  1170. #line 1 ""
  1171. #line 1 ""
  1172. #line 1 ""
  1173. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  1174. // ********************************************************
  1175. // member functions specific to each node in the grammar
  1176. // ********************************************************
  1177. #line 6 "../Grammar/grammarClassDefinitionMacros.macro before marker MEMBER_FUNCTION_DEFINITIONS"
  1178. #line 1 ""
  1179. #line 1 ""
  1180. // Start of memberFunctionString
  1181. // End of memberFunctionString
  1182. // Start of memberFunctionString
  1183. #line 7362 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Support.code"
  1184. // Added to support assignments to string variables.
  1185. SgName::operator std::string () const
  1186. {
  1187. return p_char;
  1188. }
  1189. // DQ (10/5/2007): We no longer need this!
  1190. // Definition of defaultName (use a default parameter)
  1191. // const SgName SgdefaultName("defaultName");
  1192. SgName::SgName()
  1193. : p_char("")
  1194. { }
  1195. unsigned int
  1196. SgName::get_length() const
  1197. {
  1198. ROSE_ASSERT(this != NULL);
  1199. return p_char.size();
  1200. }
  1201. SgName::SgName(const char * str): p_char(str ? str : "") {}
  1202. // DQ (9/9/2004): Added support for conversion of strings to SgName
  1203. // I always wanted this and it was a pain that it didn't exist previously!
  1204. SgName::SgName(const std::string & str): p_char(str) {}
  1205. SgName::SgName(const SgName& n): p_char(n.p_char) {}
  1206. // SgName::SgName(const char *str, int n): p_char(str, n) {} // get first n chars in the string
  1207. int
  1208. SgName::operator!=(const SgName& n1) const
  1209. {
  1210. ROSE_ASSERT(this != NULL);
  1211. return p_char != n1.p_char;
  1212. }
  1213. int
  1214. SgName::operator==(const SgName& n1) const
  1215. {
  1216. ROSE_ASSERT(this != NULL);
  1217. return p_char == n1.p_char;
  1218. }
  1219. int
  1220. SgName::operator<(const SgName& n1) const
  1221. {
  1222. ROSE_ASSERT(this != NULL);
  1223. return p_char < n1.p_char;
  1224. }
  1225. int
  1226. SgName::is_null(void) const
  1227. {
  1228. ROSE_ASSERT(this != NULL);
  1229. return p_char.empty();
  1230. }
  1231. void
  1232. SgName::replace_space(char t)
  1233. {
  1234. ROSE_ASSERT(this != NULL);
  1235. int len = p_char.size();
  1236. for(int i=0; i < len; i++)
  1237. {
  1238. // if last one
  1239. if(p_char[i]==' ')
  1240. {
  1241. if(i==len-1)
  1242. p_char.resize(p_char.size() - 1);
  1243. else
  1244. p_char[i]=t;
  1245. }
  1246. }
  1247. }
  1248. SgName&
  1249. SgName::operator<<(const std::string& str)
  1250. {
  1251. ROSE_ASSERT (this != NULL);
  1252. p_char += str;
  1253. return *this;
  1254. }
  1255. SgName
  1256. SgName::itoname(int val)
  1257. {
  1258. std::ostringstream os;
  1259. os << val;
  1260. return SgName(os.str());
  1261. }
  1262. SgName&
  1263. SgName::operator<<(int val)
  1264. {
  1265. ROSE_ASSERT(this != NULL);
  1266. SgName str = itoname(val);
  1267. p_char += str.p_char;
  1268. return *this;
  1269. }
  1270. SgName&
  1271. SgName::operator=(const SgName& n1)
  1272. {
  1273. ROSE_ASSERT(this != NULL);
  1274. this->p_char = n1.p_char;
  1275. return *this;
  1276. }
  1277. SgName&
  1278. SgName::tail(int n) // keep string after n
  1279. {
  1280. ROSE_ASSERT(this != NULL);
  1281. p_char = (unsigned int)n >= p_char.size() ? "" : p_char.substr(n);
  1282. return *this;
  1283. }
  1284. SgName&
  1285. SgName::head(int n) // keep first n chars
  1286. {
  1287. ROSE_ASSERT(this != NULL);
  1288. p_char = (unsigned int)n >= p_char.size() ? p_char : p_char.substr(0, n);
  1289. return *this;
  1290. }
  1291. const char* SgName::str() const {
  1292. ROSE_ASSERT(this != NULL);
  1293. return p_char.c_str();
  1294. }
  1295. std::string&
  1296. SgName::getString()
  1297. {
  1298. ROSE_ASSERT(this != NULL);
  1299. return p_char;
  1300. }
  1301. const std::string&
  1302. SgName::getString() const
  1303. {
  1304. ROSE_ASSERT(this != NULL);
  1305. return p_char;
  1306. }
  1307. #if 0
  1308. // Removed to prevent confusion about it's used (really should not be a const function)
  1309. SgName::operator char*() const
  1310. {
  1311. return p_char;
  1312. }
  1313. #endif
  1314. // default name to use within initializers for SgName objects
  1315. // const SgName defaultName;
  1316. void SgName::display( const std::string& label ) const
  1317. {
  1318. ROSE_ASSERT(this != NULL);
  1319. std::cout << label << ": " << p_char << "\n";
  1320. }
  1321. // DQ (9/9/2004): friend function
  1322. SgName
  1323. operator+(const SgName & n1, const SgName & n2)
  1324. {
  1325. return SgName(n1.p_char + n2.p_char);
  1326. }
  1327. // DQ (11/15/2004): Added to support general string operations (first used in the unparser)
  1328. SgName &
  1329. SgName::operator+= (const SgName & n1)
  1330. {
  1331. ROSE_ASSERT(this != NULL);
  1332. p_char += n1.p_char;
  1333. return *this;
  1334. }
  1335. SgName
  1336. SgName::assembleQualifiedName(const SgName & scopeQualifiedName, const SgName & localName)
  1337. {
  1338. // DQ (22/2005): Neede to add global scope specifier to handle some pathological cases (see test2005_144.C).
  1339. // DQ (9/9/2004): Supporting function for building qualified names (specialied string concatination)
  1340. // Previous code caused "::" to be inserted too often (e.g. where scope->get_qualified_name() was empty, as in global scope)
  1341. // returnName = scope->get_qualified_name() << "::" << get_name().str();
  1342. // DQ (9/9/2004): We can't assert this since "" evaluates to is_null() being true!
  1343. // ROSE_ASSERT(scopeQualifiedName.is_null() == false);
  1344. SgName returnName;
  1345. // DQ (9/9/2004): So these are redundent tests! (which was pleasant news to me!)
  1346. // if ( (scopeQualifiedName.is_null() == true) || (scopeQualifiedName == "") )
  1347. if ( (scopeQualifiedName.is_null() == true) || (scopeQualifiedName.getString() == "") )
  1348. {
  1349. returnName = localName;
  1350. #if 0
  1351. // DQ (11/29/2004): It seems that any assignment of "" to a SgName forces it to be evaluated so that is_null() == true
  1352. // DQ (11/29/2004): Added checking for is_null() so that returnName would always be a valid name
  1353. if (localName.is_null() == true)
  1354. returnName = "";
  1355. else
  1356. returnName = localName;
  1357. #endif
  1358. }
  1359. else
  1360. {
  1361. // Trap out the case of global scope to avoid building "::::"
  1362. if ( scopeQualifiedName == "::" )
  1363. {
  1364. // Avoid building "::::"
  1365. returnName = scopeQualifiedName.getString() + localName.getString();
  1366. }
  1367. else
  1368. {
  1369. returnName = scopeQualifiedName.getString() + "::" + localName.getString();
  1370. }
  1371. }
  1372. // returnName = scopeQualifiedName << "::" << localName.str();
  1373. // ROSE_ASSERT(returnName.is_null() == false);
  1374. return returnName;
  1375. }
  1376. // End of memberFunctionString
  1377. // Start of memberFunctionString
  1378. #line 331 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Common.code"
  1379. // *** COMMON CODE SECTION BEGINS HERE ***
  1380. int
  1381. SgName::getVariant() const
  1382. {
  1383. // This function is used in ROSE while "variant()" is used in SAGE
  1384. assert(this != NULL);
  1385. return variant();
  1386. }
  1387. // This function is used in ROSE in treeTraversal code
  1388. // eventually replaces getVariant() and variant()
  1389. // though after variant() has been removed for a while we will
  1390. // want to change the name of variantT() back to variant()
  1391. // (since the "T" was ment to stand for temporary).
  1392. // When this happens the variantT() will be depricated.
  1393. VariantT
  1394. SgName::variantT() const {
  1395. return V_SgName;
  1396. }
  1397. #if 0
  1398. int
  1399. SgName::variant() const
  1400. {
  1401. // This function is used in SAGE
  1402. assert(this != NULL);
  1403. return NameTag;
  1404. }
  1405. #endif
  1406. const char*
  1407. SgName::sage_class_name() const
  1408. {
  1409. assert(this != NULL);
  1410. return "SgName";
  1411. }
  1412. std::string
  1413. SgName::class_name() const
  1414. {
  1415. assert(this != NULL);
  1416. return "SgName";
  1417. }
  1418. // DQ (11/26/2005): Support for visitor pattern mechanims
  1419. // (inferior to ROSE traversal mechanism, experimental).
  1420. void
  1421. SgName::executeVisitorMemberFunction (ROSE_VisitorPattern & visitor)
  1422. {
  1423. ROSE_ASSERT(this != NULL);
  1424. visitor.visit(this);
  1425. }
  1426. // *** COMMON CODE SECTION ENDS HERE ***
  1427. // End of memberFunctionString
  1428. // Start of memberFunctionString
  1429. #line 1387 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Node.code"
  1430. #if 0
  1431. //! Error checking support
  1432. /*! Verifies the following:
  1433. - working getVariant() member function
  1434. - calls base class's error() member function
  1435. Every class has one of these functions.
  1436. */
  1437. bool
  1438. SgName::error()
  1439. {
  1440. // Put error checking here
  1441. ROSE_ASSERT (this != NULL);
  1442. if (getVariant() != NameTag)
  1443. {
  1444. printf ("Error in SgName::error(): SgName object has a %s variant \n",
  1445. Cxx_GrammarTerminalNames[getVariant()].name);
  1446. // printf ("Error in SgName::error() \n");
  1447. ROSE_ABORT();
  1448. }
  1449. ROSE_ASSERT (getVariant() == NameTag);
  1450. return SgSupport::error();
  1451. }
  1452. #endif
  1453. // End of memberFunctionString
  1454. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarVariantFunctionDefinitionMacros.macro"
  1455. int
  1456. SgName::variant() const
  1457. {
  1458. // This function is generated from grammarVariantFunctionDefinitionMacros.macro
  1459. #ifdef DEBUG
  1460. // printf ("In SgName::variant() const \n");
  1461. #endif
  1462. assert(this != NULL);
  1463. return NameTag;
  1464. }
  1465. #line 1 ""
  1466. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarIsClassNameFunctionDefinitionMacros.macro"
  1467. SgName* isSgName ( SgNode* inputDerivedClassPointer )
  1468. {
  1469. return dynamic_cast<SgName*>(inputDerivedClassPointer);
  1470. }
  1471. // DQ (11/8/2003): Added version of functions taking const pointer
  1472. const SgName* isSgName ( const SgNode* inputDerivedClassPointer )
  1473. {
  1474. return dynamic_cast<const SgName*>(inputDerivedClassPointer);
  1475. }
  1476. #line 1 ""
  1477. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  1478. /**
  1479. \brief Generated destructor
  1480. This destructor is automatically generated (by ROSETTA). This destructor
  1481. only frees memory of data members associated with the parts of the current IR node which
  1482. are NOT traversed. Those data members that are part of a traversal can be freed using
  1483. a traversal (calling this destructor on all children in a post-order traversal). Such
  1484. a traversal which deletes a whole AST is provided by DeleteSgTree(SgNode*).
  1485. \internal All IR nodes with data members specified using setDataPrototype() within ROSETTA
  1486. are specified as NO_DELETE is also specified as DEF_TRAVERSAL. Those marked as
  1487. NO_TRAVERSAL can be marked as NO_DELETE or DEF_DELETE.
  1488. \note All SgSymbol IR nodes are deleted when the symbol table is deleted. Currently most
  1489. SgType IR nodes are not deleted (since they are shared). Also, all STL lists of
  1490. pointers are not yet implemented to call delete on eash pointer in the container.
  1491. (This could be done by derivation from the STL containers to define containers that
  1492. automatically deleted their members.)
  1493. */
  1494. SgName::~SgName ()
  1495. {
  1496. #if 0
  1497. // debugging information!
  1498. printf ("In SgName::~SgName (destructor) \n");
  1499. #endif
  1500. #if 1
  1501. // DQ (6/25/2006): Commented out destructor body to allow the File I/O to work.
  1502. // case: not a listType for char
  1503. p_char = ""; // non list case
  1504. #line 32 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  1505. #endif
  1506. }
  1507. #line 1 ""
  1508. #line 1 ""
  1509. #line 6 "../Grammar/grammarClassDefinitionMacros.macro after marker MEMBER_FUNCTION_DEFINITIONS"
  1510. #line 7 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  1511. // ********************************************************
  1512. // member functions common across all array grammar objects
  1513. // ********************************************************
  1514. #line 1 ""
  1515. #line 1 ""
  1516. #line 1 ""
  1517. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  1518. // ********************************************************
  1519. // member functions specific to each node in the grammar
  1520. // ********************************************************
  1521. #line 6 "../Grammar/grammarClassDefinitionMacros.macro before marker MEMBER_FUNCTION_DEFINITIONS"
  1522. #line 1 ""
  1523. #line 1 ""
  1524. // Start of memberFunctionString
  1525. // End of memberFunctionString
  1526. // Start of memberFunctionString
  1527. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  1528. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  1529. SgName
  1530. SgSymbolTable::get_name () const
  1531. {
  1532. assert (this != NULL);
  1533. return p_name;
  1534. }
  1535. void
  1536. SgSymbolTable::set_name ( SgName name )
  1537. {
  1538. assert (this != NULL);
  1539. set_isModified(true);
  1540. p_name = name;
  1541. }
  1542. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  1543. // End of memberFunctionString
  1544. // Start of memberFunctionString
  1545. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  1546. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  1547. bool
  1548. SgSymbolTable::get_no_name () const
  1549. {
  1550. assert (this != NULL);
  1551. return p_no_name;
  1552. }
  1553. void
  1554. SgSymbolTable::set_no_name ( bool no_name )
  1555. {
  1556. assert (this != NULL);
  1557. set_isModified(true);
  1558. p_no_name = no_name;
  1559. }
  1560. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  1561. // End of memberFunctionString
  1562. // Start of memberFunctionString
  1563. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  1564. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  1565. rose_hash_multimap*
  1566. SgSymbolTable::get_table () const
  1567. {
  1568. assert (this != NULL);
  1569. return p_table;
  1570. }
  1571. void
  1572. SgSymbolTable::set_table ( rose_hash_multimap* table )
  1573. {
  1574. assert (this != NULL);
  1575. set_isModified(true);
  1576. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  1577. if (p_table != NULL && table != NULL && p_table != table)
  1578. {
  1579. printf ("Warning: table = %p overwriting valid pointer p_table = %p \n",table,p_table);
  1580. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  1581. printf ("Error fails assertion (p_table != NULL && table != NULL && p_table != table) is false\n");
  1582. ROSE_ASSERT(false);
  1583. #endif
  1584. }
  1585. #endif
  1586. p_table = table;
  1587. }
  1588. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  1589. // End of memberFunctionString
  1590. // Start of memberFunctionString
  1591. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  1592. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  1593. SgNodeSet
  1594. SgSymbolTable::get_symbolSet () const
  1595. {
  1596. assert (this != NULL);
  1597. return p_symbolSet;
  1598. }
  1599. void
  1600. SgSymbolTable::set_symbolSet ( SgNodeSet symbolSet )
  1601. {
  1602. assert (this != NULL);
  1603. set_isModified(true);
  1604. p_symbolSet = symbolSet;
  1605. }
  1606. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  1607. // End of memberFunctionString
  1608. // Start of memberFunctionString
  1609. #line 3898 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Support.code"
  1610. // DQ (2/19/2007): Added mechanism to turn off expensive error checking!
  1611. #define SYMBOL_TABLE_ERROR_CHECKING 1
  1612. // DQ (7/24/2005): Make this a constant in the function if it is not used elsewhere!
  1613. // #define SYMTBL_INIT_SZ 16
  1614. SgSymbolTable::SgSymbolTable()
  1615. : p_no_name(true)
  1616. {
  1617. // This should always be a non-null pointer (and never shared)!
  1618. int symbolTableSize = 17;
  1619. p_table = new BaseHashType(symbolTableSize);
  1620. ROSE_ASSERT (p_table != NULL);
  1621. }
  1622. // DQ (2/19/2007): I have put it back into use as a way of
  1623. // customizing the size of the underlying hash tables to be
  1624. // larger for certain scopes (e.g global scope usually has a
  1625. // lot more symbols.
  1626. // DQ (1/31/2007): This function is not used!
  1627. SgSymbolTable::SgSymbolTable(int symbolTableSize)
  1628. : p_no_name(true)
  1629. {
  1630. // This should always be a non-null pointer (and never shared)!
  1631. // AJ (10/21/2004): Adjusted implementation to use new STL hash map interface
  1632. // p_table = new SgSymbolHashMultiMap(sz);
  1633. p_table = new BaseHashType(symbolTableSize);
  1634. ROSE_ASSERT (p_table != NULL);
  1635. }
  1636. std::ostream & operator<< ( std::ostream & os, const rose_hash_multimap::iterator & rhm_it )
  1637. {
  1638. // DQ (1/19/2006): Error reported by Michelle Strout when compiled with g++ 4.0.2 on 64 bit machines
  1639. // os << " pair (" << (*rhm_it).first.str() << "," << (int)((*rhm_it).second) << ")";
  1640. os << " pair (" << (*rhm_it).first.str() << "," << ((*rhm_it).second) << ")";
  1641. return os;
  1642. }
  1643. SgName
  1644. SgSymbolTable::get_name( const SgNode* node) const
  1645. {
  1646. // DQ (2/20/2007): This function is used to get the name for the different types of declarations used to build symbols.
  1647. SgName name;
  1648. switch (node->variantT())
  1649. {
  1650. // We could implement a function on the selective nodes that generated the symbol
  1651. // name (the name used for the input of associated symbols in the symbol table).
  1652. case V_SgLabelStatement:
  1653. {
  1654. const SgLabelStatement* labelStatement = isSgLabelStatement(node);
  1655. name = labelStatement->get_label();
  1656. break;
  1657. }
  1658. case V_SgClassDeclaration:
  1659. case V_SgDerivedTypeStatement:
  1660. {
  1661. const SgClassDeclaration* classDeclaration = isSgClassDeclaration(node);
  1662. name = classDeclaration->get_name();
  1663. break;
  1664. }
  1665. case V_SgTemplateInstantiationDecl:
  1666. {
  1667. const SgTemplateInstantiationDecl* templateInstantiationDeclaration = isSgTemplateInstantiationDecl(node);
  1668. // Note that get_name() returns a name with arguments such as "class_template<int>" while get_templateName() returns the template name withouth arguments.
  1669. // name = templateInstantiationDeclaration->get_templateName();
  1670. // printf ("In SgSymbolTable::find(const SgStatement*): case V_SgTemplateInstantiationDecl, using get_name() = %s instead of get_templateName() = %s \n",
  1671. // templateInstantiationDeclaration->get_name().str(),templateInstantiationDeclaration->get_templateName().str());
  1672. // printf ("Base class get_name() = %s \n",templateInstantiationDeclaration->SgClassDeclaration::get_name().str());
  1673. name = templateInstantiationDeclaration->get_name();
  1674. break;
  1675. }
  1676. case V_SgEnumDeclaration:
  1677. {
  1678. const SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(node);
  1679. name = enumDeclaration->get_name();
  1680. break;
  1681. }
  1682. case V_SgFunctionDeclaration:
  1683. case V_SgProgramHeaderStatement:
  1684. case V_SgProcedureHeaderStatement:
  1685. case V_SgMemberFunctionDeclaration:
  1686. {
  1687. const SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(node);
  1688. // printf ("functionDeclaration = %p \n",functionDeclaration);
  1689. // printf ("functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->get_definingDeclaration());
  1690. // printf ("functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->get_firstNondefiningDeclaration());
  1691. name = functionDeclaration->get_name();
  1692. break;
  1693. }
  1694. // DQ (2/14/2007): Note that for template-based declarations there is a process where within the post-processing of
  1695. // the AST the names are updated from the EDG form (e.g. "template_name___Lnnn"), to the template specialization
  1696. // form (e.g. "template_name<int>"). Since the symbol references only one of the declarations, if there are defining
  1697. // declarations and non-defining declarations, the name can be changed in the declaration but not in the associated symbol.
  1698. // Details of this situation require more clarification.
  1699. case V_SgTemplateInstantiationFunctionDecl:
  1700. {
  1701. const SgTemplateInstantiationFunctionDecl* functionDeclaration = isSgTemplateInstantiationFunctionDecl(node);
  1702. // printf ("functionDeclaration = %p \n",functionDeclaration);
  1703. // printf ("functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->get_definingDeclaration());
  1704. // printf ("functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->get_firstNondefiningDeclaration());
  1705. // DQ (2/14/2007): The name used to insert symbols into the symbol table is the one returned by get_name(),
  1706. // get_templateName returns the name of the template which is required for code generation (where for
  1707. // functions the specialization is not required or not allowed).
  1708. // name = functionDeclaration->get_templateName();
  1709. name = functionDeclaration->get_name();
  1710. break;
  1711. }
  1712. case V_SgTemplateInstantiationMemberFunctionDecl:
  1713. {
  1714. const SgTemplateInstantiationMemberFunctionDecl* functionDeclaration = isSgTemplateInstantiationMemberFunctionDecl(node);
  1715. // printf ("functionDeclaration = %p \n",functionDeclaration);
  1716. // printf ("functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->get_definingDeclaration());
  1717. // printf ("functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->get_firstNondefiningDeclaration());
  1718. // DQ (2/14/2007): The name used to insert symbols into the symbol table is the one returned by get_name(),
  1719. // get_templateName returns the name of the template which is required for code generation (where for
  1720. // functions the specialization is not required or not allowed).
  1721. // name = functionDeclaration->get_templateName();
  1722. name = functionDeclaration->get_name();
  1723. break;
  1724. }
  1725. case V_SgNamespaceDeclarationStatement:
  1726. {
  1727. const SgNamespaceDeclarationStatement* namespaceDeclarationStatement = isSgNamespaceDeclarationStatement(node);
  1728. name = namespaceDeclarationStatement->get_name();
  1729. break;
  1730. }
  1731. case V_SgTemplateDeclaration:
  1732. {
  1733. const SgTemplateDeclaration* templateDeclaration = isSgTemplateDeclaration(node);
  1734. name = templateDeclaration->get_name();
  1735. break;
  1736. }
  1737. case V_SgTypedefDeclaration:
  1738. {
  1739. const SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(node);
  1740. name = typedefDeclaration->get_name();
  1741. break;
  1742. }
  1743. case V_SgFunctionType:
  1744. {
  1745. const SgFunctionType* functionType = isSgFunctionType(node);
  1746. name = functionType->get_mangled();
  1747. break;
  1748. }
  1749. case V_SgInitializedName:
  1750. {
  1751. const SgInitializedName* initializedName = isSgInitializedName(node);
  1752. name = initializedName->get_name();
  1753. break;
  1754. }
  1755. default:
  1756. {
  1757. printf ("SgSymbolTable::get_name(SgNode*) undefined for %s \n",node->class_name().c_str());
  1758. ROSE_ASSERT(false);
  1759. }
  1760. }
  1761. return name;
  1762. }
  1763. #if 0
  1764. // DQ (3/10/2007): This approach in the end, didn't work. So I think this can be removed!
  1765. // What about the variations for defining vs. first non-defining declarations
  1766. // we could match up the different types of declarations!
  1767. unsigned int
  1768. SgSymbolTable::generateUniqueNumberForMatchingSymbol( SgDeclarationStatement* symbolBasis ) const
  1769. {
  1770. // DQ (2/20/2007): This function supports the AST merge mechansim, but is general
  1771. // and may be useful for the mangled name generation in the future. For symbols
  1772. // in the symbol table for a specific scope that have matching names (typically
  1773. // originating as un-named structs or enums) this function requires a unique number
  1774. // for each instance.
  1775. #if 1
  1776. printf ("In SgSymbolTable::generateUniqueNumberForMatchingSymbol() symbolBasis = %p \n",symbolBasis);
  1777. #endif
  1778. ROSE_ASSERT(p_table != NULL);
  1779. SgName nm = get_name(symbolBasis);
  1780. unsigned int counter = 0;
  1781. hash_iterator p_iterator = p_table->find(nm);
  1782. ROSE_ASSERT(symbolBasis != NULL);
  1783. SgDeclarationStatement* symbolBasisDefiningDeclaration = symbolBasis->get_definingDeclaration();
  1784. SgDeclarationStatement* symbolBasisNondefiningDeclaration = symbolBasis->get_firstNondefiningDeclaration();
  1785. ROSE_ASSERT(symbolBasisDefiningDeclaration != NULL);
  1786. ROSE_ASSERT(symbolBasisNondefiningDeclaration != NULL);
  1787. // loop over all symbols of the same name
  1788. while (p_iterator != p_table->end() && p_iterator->first == nm)
  1789. {
  1790. // only count matching symbol types (with the same name)
  1791. if ( p_iterator->second->get_symbol_basis()->variantT() == symbolBasis->variantT() )
  1792. {
  1793. // return the count when we have found the symbol basis (or matching of it's defining or nondefining declarations)
  1794. SgDeclarationStatement* tmp_symbolBasis = isSgDeclarationStatement(p_iterator->second->get_symbol_basis());
  1795. ROSE_ASSERT(tmp_symbolBasis != NULL);
  1796. // Exit loop on condition of definingDeclaration
  1797. if (symbolBasisDefiningDeclaration != NULL)
  1798. {
  1799. SgDeclarationStatement* tmp_symbolBasisDefiningDeclaration = tmp_symbolBasis->get_definingDeclaration();
  1800. ROSE_ASSERT(tmp_symbolBasisDefiningDeclaration != NULL);
  1801. if (symbolBasisDefiningDeclaration == tmp_symbolBasisDefiningDeclaration)
  1802. break;
  1803. }
  1804. // Exit loop on condition of firstNondefiningDeclaration
  1805. if (symbolBasisNondefiningDeclaration != NULL)
  1806. {
  1807. SgDeclarationStatement* tmp_symbolBasisNondefiningDeclaration = tmp_symbolBasis->get_firstNondefiningDeclaration();
  1808. ROSE_ASSERT(tmp_symbolBasisNondefiningDeclaration != NULL);
  1809. if (symbolBasisNondefiningDeclaration == tmp_symbolBasisNondefiningDeclaration)
  1810. break;
  1811. }
  1812. }
  1813. counter++;
  1814. p_iterator++;
  1815. }
  1816. #if 1
  1817. printf ("Leaving SgSymbolTable::generateUniqueNumberForMatchingSymbol() = %d \n",counter);
  1818. #endif
  1819. return counter;
  1820. }
  1821. #endif
  1822. /* ************************************************************************
  1823. INSERT FUNCTIONS
  1824. ************************************************************************/
  1825. void
  1826. SgSymbolTable::insert ( const SgName & nm , SgSymbol *sp )
  1827. {
  1828. // DQ (2/14/2007): Added assertion!
  1829. ROSE_ASSERT(this != NULL);
  1830. // DQ (2/19/2007): Added additional assertion!
  1831. ROSE_ASSERT (p_table != NULL);
  1832. // DQ (2/14/2007): Added assertion!
  1833. ROSE_ASSERT (sp != NULL);
  1834. #if 0
  1835. // #if SYMBOL_TABLE_ERROR_CHECKING
  1836. // SgFunctionTypeSymbol does not have a valid get_symbol_basis(), so skip this case!
  1837. if (isSgFunctionTypeSymbol(sp) == NULL)
  1838. {
  1839. if (sp->get_symbol_basis() == NULL)
  1840. {
  1841. printf ("Error (sp->get_symbol_basis() == NULL): name = %s sp = %p = %s \n",nm.str(),sp,sp->class_name().c_str());
  1842. }
  1843. ROSE_ASSERT(sp->get_symbol_basis() != NULL);
  1844. #if 0
  1845. // This outputs a message for every use of the insert function (for non function type symbols) useful for tracing through bugs
  1846. printf ("In SgSymbolTable::insert(%s,%p) into SgSymbolTable = %p = %s of scope = %p = %s sp = %p = %s sp->get_symbol_basis() = %p = %s \n",
  1847. nm.str(),sp,this,this->class_name().c_str(),this->get_parent(),this->get_parent()->class_name().c_str(),
  1848. sp,sp->class_name().c_str(),sp->get_symbol_basis(),sp->get_symbol_basis()->class_name().c_str());
  1849. #endif
  1850. }
  1851. #endif
  1852. // DQ (3/10/2007): This is a simpler assertion equivalent to the one above but without generating any error output
  1853. ROSE_ASSERT(isSgFunctionTypeSymbol(sp) != NULL || sp->get_symbol_basis() != NULL);
  1854. // DQ (3/10/2007): Test for if the symbol exists
  1855. ROSE_ASSERT (p_symbolSet.find(sp) == p_symbolSet.end());
  1856. #if 0
  1857. // #if SYMBOL_TABLE_ERROR_CHECKING
  1858. // DQ (2/19/2007): These is no need to do both of these since exists(sp) is more complete test!
  1859. // DQ (2/25/2007): except that it is helpful to know which one fails.
  1860. ROSE_ASSERT(exists(nm,sp) == false);
  1861. ROSE_ASSERT(exists(sp) == false);
  1862. // DQ (2/14/2007): error checking (make sure that no two symbols are represented by the same basis declaration).
  1863. // But skip such tests on the SgFunctionTypeSymbol (only used for the function type table)
  1864. if (isSgFunctionTypeSymbol(sp) == NULL)
  1865. {
  1866. // set<SgNode*> existingSymbolBasisDeclarations;
  1867. map<SgNode*, hash_multimap<SgName, SgSymbol*, hash_Name, eqstr>::iterator > existingSymbolBasisDeclarations;
  1868. SgNode* sp_associatedDeclaration = sp->get_symbol_basis();
  1869. ROSE_ASSERT(sp_associatedDeclaration != NULL);
  1870. hash_multimap<SgName, SgSymbol*, hash_Name, eqstr>::iterator i = get_table()->begin();
  1871. while (i != get_table()->end())
  1872. {
  1873. // test if symbol is in set
  1874. SgNode* associatedDeclaration = i->second->get_symbol_basis();
  1875. ROSE_ASSERT(associatedDeclaration != NULL);
  1876. // Check if this declaration has previously been used with another symbol!
  1877. if (existingSymbolBasisDeclarations.find( sp_associatedDeclaration ) == existingSymbolBasisDeclarations.end())
  1878. {
  1879. // Add this declaration to the list associated with symbols in the table
  1880. // existingSymbolBasisDeclarations.insert( associatedDeclaration );
  1881. existingSymbolBasisDeclarations[associatedDeclaration] = i;
  1882. }
  1883. else
  1884. {
  1885. printf ("Error in symbol table located in parent = %p = %s \n",get_parent(),get_parent()->class_name().c_str());
  1886. ROSE_ASSERT(get_parent() != NULL);
  1887. get_parent()->get_file_info()->display("Error in symbol table");
  1888. string associatedDeclarationName = SageInterface::get_name(sp_associatedDeclaration);
  1889. // DQ (2/15/2007): Output the name of the symbol being inserted, the declaration associated with it,
  1890. // and the name of the symbol previously inserted with the same associated declaration.
  1891. printf ("Symbol sp = %p = %s already associated with declaration = %p = %s (name = %s) in symbol table i = %p = %s \n",
  1892. sp,sp->class_name().c_str(),sp_associatedDeclaration,sp_associatedDeclaration->class_name().c_str(),
  1893. associatedDeclarationName.c_str(),existingSymbolBasisDeclarations[sp_associatedDeclaration]->second,existingSymbolBasisDeclarations[sp_associatedDeclaration]->second->class_name().c_str());
  1894. associatedDeclaration->get_file_info()->display("Dual use of associatedDeclaration in source: debug");
  1895. printf ("existingSymbolBasisDeclarations[sp_associatedDeclaration]->first = %s second = %p \n",
  1896. existingSymbolBasisDeclarations[sp_associatedDeclaration]->first.str(),
  1897. existingSymbolBasisDeclarations[sp_associatedDeclaration]->second);
  1898. ROSE_ASSERT(false);
  1899. }
  1900. i++;
  1901. }
  1902. }
  1903. #endif
  1904. // Now, finally insert it into the symbol table
  1905. // std::pair<const SgName,SgSymbol*> npair(nm,sp);
  1906. // p_table->insert(npair);
  1907. p_table->insert(std::pair<const SgName,SgSymbol*>(nm,sp));
  1908. // DQ (5/11/2006): set the parent to avoid NULL pointers
  1909. sp->set_parent(this);
  1910. // DQ (3/10/2007): Insert this symbol into p_symbolSet which we use for fast tests of existance in the
  1911. // symbol table when we don't use the name. This helps detect where symbols have been entered using one
  1912. // name and either reentered using an second name or the name changed and the symbol had not been properly
  1913. // unloaded and reloaded into the symbol table. Since the names are not stored in the symbol, but computed
  1914. // from associated declaration this is an easy error to make and we detect this by backing up the test for
  1915. // if a symbol exists using a name with a test for if the symbol exists using ANY possible name (a search
  1916. // for the symbol independent of the name). To avoid this being a linear search of the symbol table (too
  1917. // slow) we implement a set of symbols to permit fast tests for existence.
  1918. p_symbolSet.insert(sp);
  1919. #if 0
  1920. // #if SYMBOL_TABLE_ERROR_CHECKING
  1921. // Error checking
  1922. ROSE_ASSERT(exists(nm) == true);
  1923. ROSE_ASSERT(exists(nm,sp) == true);
  1924. ROSE_ASSERT(exists(sp) == true);
  1925. #endif
  1926. #if 0
  1927. // #if SYMBOL_TABLE_ERROR_CHECKING
  1928. // DQ (2/14/2007): Added error checking!
  1929. if (nm != sp->get_name())
  1930. {
  1931. printf ("Warning: symbol name does not match name used to input associated symbol into symbol table! sp = %p = %s nm = \"%s\" sp->get_name() = \"%s\" \n",sp,sp->class_name().c_str(),nm.str(),sp->get_name().str());
  1932. ROSE_ASSERT(sp->get_symbol_basis() != NULL);
  1933. ROSE_ASSERT(sp->get_symbol_basis()->get_file_info() != NULL);
  1934. sp->get_symbol_basis()->get_file_info()->display("Error in source: debug");
  1935. ROSE_ASSERT(false);
  1936. }
  1937. #endif
  1938. #if 0
  1939. // We can't test this because where symbols are inserted (EDG/SageIII translation) the scopes are not set yet (done in AST post-processing).
  1940. // DQ (2/14/2007): Added error checking!
  1941. SgStatement* statement = isSgStatement(sp->get_symbol_basis());
  1942. if (statement != NULL)
  1943. {
  1944. // printf ("In loop: p_iterator->second = %p = %s statement = %p = %s \n",p_iterator->second,p_iterator->second->class_name().c_str(),statement,statement->class_name().c_str());
  1945. // SgNode* symbolBasis = p_iterator->second->get_symbol_basis();
  1946. SgSymbol* symbolFromTable = statement->get_symbol_from_symbol_table();
  1947. ROSE_ASSERT(symbolFromTable != NULL);
  1948. ROSE_ASSERT(symbolFromTable == sp);
  1949. }
  1950. else
  1951. {
  1952. SgInitializedName* initializedName = isSgInitializedName(sp->get_symbol_basis());
  1953. if (initializedName != NULL)
  1954. {
  1955. // printf ("In loop: p_iterator->second = %p = %s statement = %p = %s \n",p_iterator->second,p_iterator->second->class_name().c_str(),statement,statement->class_name().c_str());
  1956. // SgNode* symbolBasis = p_iterator->second->get_symbol_basis();
  1957. SgSymbol* symbolFromTable = initializedName->get_symbol_from_symbol_table();
  1958. ROSE_ASSERT(symbolFromTable != NULL);
  1959. ROSE_ASSERT(symbolFromTable == sp);
  1960. }
  1961. else
  1962. {
  1963. printf ("Unknown symbol_base for input symbol sp = %p = %s sp->get_symbol_basis() = %p = %s \n",sp,sp->class_name().c_str(),sp->get_symbol_basis(),sp->get_symbol_basis()->class_name().c_str());
  1964. ROSE_ASSERT(false);
  1965. }
  1966. }
  1967. #endif
  1968. }
  1969. /* ************************************************************************
  1970. REMOVE FUNCTIONS
  1971. ************************************************************************/
  1972. // DQ (2/6/2007): This is too dangerous for use in ROSE (deletes all
  1973. // possible SgSymbols that match the input name independent of type).
  1974. // It is however currently used in the global function type symbol table
  1975. // so we have named this function to make its purpose more clear.
  1976. // This function is not likely called except where complex function type
  1977. // symbol table editing is required. Since SgFunctionTypeSymbols are
  1978. // shared removing such symbols is a rather dangerous actvity!
  1979. void
  1980. SgSymbolTable::remove_function_type( const SgName & name )
  1981. {
  1982. // This is non-destructive (does not delete the symbol, only removes it from the symbol table).
  1983. ROSE_ASSERT (p_table != NULL);
  1984. list<hash_multimap<SgName, SgSymbol*, hash_Name, eqstr>::iterator> deleteList;
  1985. hash_multimap<SgName, SgSymbol*, hash_Name, eqstr>::iterator it = get_table()->find(name);
  1986. while (it != get_table()->end() && (*it).first == name)
  1987. {
  1988. ROSE_ASSERT(it->second->variantT() == V_SgFunctionTypeSymbol);
  1989. deleteList.push_back(it);
  1990. it++;
  1991. }
  1992. // Now remove the copy of the symbol from the symbol table and insert the shared symbol
  1993. list<hash_multimap<SgName, SgSymbol*, hash_Name, eqstr>::iterator>::iterator i = deleteList.begin();
  1994. while (i != deleteList.end())
  1995. {
  1996. // DQ (5/9/2007): Moved to after the call to "p_symbolSet.erase((*i)->second);"
  1997. // Remove the existing symbol (associated with the function declaration we will be deleting from the AST.
  1998. // printf ("Erasing symbol %p from symbol table %p in scope = %p \n",(*i)->second,this,this->get_parent());
  1999. // get_table()->erase(*i);
  2000. // DQ (3/10/2007): Remove the symbol from the symbol set used to test for if the symbol exists
  2001. p_symbolSet.erase((*i)->second);
  2002. // Remove the existing symbol (associated with the function declaration we will be deleting from the AST.
  2003. // printf ("Erasing symbol %p from symbol table %p in scope = %p \n",(*i)->second,this,this->get_parent());
  2004. get_table()->erase(*i);
  2005. i++;
  2006. }
  2007. }
  2008. SgSymbol*
  2009. SgSymbolTable::find( const SgInitializedName* initializedName)
  2010. {
  2011. ROSE_ASSERT(p_table != NULL);
  2012. ROSE_ASSERT(initializedName != NULL);
  2013. // printf ("Inside of SgSymbolTable::find( const SgInitializedName* ): initializedName = %p = %s \n",initializedName,SageInterface::get_name(initializedName).c_str());
  2014. SgSymbol* returnSymbol = NULL;
  2015. SgName name = initializedName->get_name();
  2016. // printf ("Inside of SgSymbolTable::find( const SgInitializedName* ): name = %s \n",name.str());
  2017. p_iterator = p_table->find(name);
  2018. while (p_iterator != p_table->end() && (*p_iterator).first == name)
  2019. {
  2020. ROSE_ASSERT(p_iterator->second != NULL);
  2021. SgNode* symbolBasis = p_iterator->second->get_symbol_basis();
  2022. // printf ("In loop: p_iterator->second = %p symbolBasis = %p initializedName = %p \n",p_iterator->second,symbolBasis,initializedName);
  2023. // printf ("In loop: symbolBasis->variantT() = %d statement->variantT() = %d \n",symbolBasis->variantT(),initializedName->variantT());
  2024. ROSE_ASSERT(symbolBasis != NULL);
  2025. if (isSgInitializedName(symbolBasis) != NULL)
  2026. {
  2027. // printf ("found a SgInitializedName \n");
  2028. returnSymbol = p_iterator->second;
  2029. if (returnSymbol->get_symbol_basis() == initializedName)
  2030. {
  2031. // printf ("returnSymbol->get_symbol_basis() == initializedName returnSymbol = %p = %s \n",returnSymbol,returnSymbol->class_name().c_str());
  2032. return returnSymbol;
  2033. }
  2034. else
  2035. {
  2036. // printf ("returnSymbol->get_symbol_basis() != initializedName \n");
  2037. }
  2038. }
  2039. else
  2040. {
  2041. // printf ("Some other symbol was found (no matching variants) \n");
  2042. }
  2043. p_iterator++;
  2044. }
  2045. // DQ (2/13/2007): Fixed bug that returns a valid pointer even when there was no match to the input statement!
  2046. // return returnSymbol;
  2047. return NULL;
  2048. }
  2049. SgSymbol*
  2050. SgSymbolTable::find( const SgFunctionType* functionType)
  2051. {
  2052. ROSE_ASSERT(p_table != NULL);
  2053. ROSE_ASSERT(functionType != NULL);
  2054. // printf ("Inside of SgSymbolTable::find( const SgFunctionType* ): functionType = %p = %s \n",functionType,SageInterface::get_name(functionType).c_str());
  2055. SgSymbol* returnSymbol = NULL;
  2056. SgName name = functionType->get_mangled();
  2057. p_iterator = p_table->find(name);
  2058. while (p_iterator != p_table->end() && (*p_iterator).first == name)
  2059. {
  2060. if (isSgSymbol((*p_iterator).second)->variantT() == functionType->variantT())
  2061. {
  2062. returnSymbol = p_iterator->second;
  2063. if (returnSymbol->get_symbol_basis() == functionType)
  2064. return returnSymbol;
  2065. }
  2066. p_iterator++;
  2067. }
  2068. // DQ (2/13/2007): Fixed bug that returns a valid pointer even when there was no match to the input statement!
  2069. // return returnSymbol;
  2070. return NULL;
  2071. }
  2072. SgSymbol*
  2073. SgSymbolTable::find( const SgStatement* statement)
  2074. {
  2075. ROSE_ASSERT(p_table != NULL);
  2076. ROSE_ASSERT(statement != NULL);
  2077. // printf ("Inside of SgSymbolTable::find( const SgStatement* ): statement = %p = %s = %s \n",statement,statement->class_name().c_str(),SageInterface::get_name(statement).c_str());
  2078. SgSymbol* returnSymbol = NULL;
  2079. SgName name = get_name(statement);
  2080. #if 0
  2081. // This code is replaced by the SgSymbolTable::get_name() function.
  2082. switch (statement->variantT())
  2083. {
  2084. // We could implement a function on the selective statements that generated the symbol
  2085. // name (the name used for the input of associated symbols in the symbol table).
  2086. case V_SgLabelStatement:
  2087. {
  2088. const SgLabelStatement* labelStatement = isSgLabelStatement(statement);
  2089. name = labelStatement->get_label();
  2090. break;
  2091. }
  2092. case V_SgClassDeclaration:
  2093. {
  2094. const SgClassDeclaration* classDeclaration = isSgClassDeclaration(statement);
  2095. name = classDeclaration->get_name();
  2096. break;
  2097. }
  2098. case V_SgTemplateInstantiationDecl:
  2099. {
  2100. const SgTemplateInstantiationDecl* templateInstantiationDeclaration = isSgTemplateInstantiationDecl(statement);
  2101. // Note that get_name() returns a name with arguments such as "class_template<int>" while get_templateName() returns the template name withouth arguments.
  2102. // name = templateInstantiationDeclaration->get_templateName();
  2103. // printf ("In SgSymbolTable::find(const SgStatement*): case V_SgTemplateInstantiationDecl, using get_name() = %s instead of get_templateName() = %s \n",
  2104. // templateInstantiationDeclaration->get_name().str(),templateInstantiationDeclaration->get_templateName().str());
  2105. // printf ("Base class get_name() = %s \n",templateInstantiationDeclaration->SgClassDeclaration::get_name().str());
  2106. name = templateInstantiationDeclaration->get_name();
  2107. break;
  2108. }
  2109. case V_SgEnumDeclaration:
  2110. {
  2111. const SgEnumDeclaration* enumDeclaration = isSgEnumDeclaration(statement);
  2112. name = enumDeclaration->get_name();
  2113. break;
  2114. }
  2115. case V_SgFunctionDeclaration:
  2116. case V_SgMemberFunctionDeclaration:
  2117. {
  2118. const SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(statement);
  2119. // printf ("functionDeclaration = %p \n",functionDeclaration);
  2120. // printf ("functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->get_definingDeclaration());
  2121. // printf ("functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->get_firstNondefiningDeclaration());
  2122. name = functionDeclaration->get_name();
  2123. break;
  2124. }
  2125. // DQ (2/14/2007): Note that for template-based declarations there is a process where within the post-processing of
  2126. // the AST the names are updated from the EDG form (e.g. "template_name___Lnnn"), to the template specialization
  2127. // form (e.g. "template_name<int>"). Since the symbol references only one of the declarations, if there are defining
  2128. // declarations and non-defining declarations, the name can be changed in the declaration but not in the associated symbol.
  2129. // Details of this situation require more clarification.
  2130. case V_SgTemplateInstantiationFunctionDecl:
  2131. {
  2132. const SgTemplateInstantiationFunctionDecl* functionDeclaration = isSgTemplateInstantiationFunctionDecl(statement);
  2133. // printf ("functionDeclaration = %p \n",functionDeclaration);
  2134. // printf ("functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->get_definingDeclaration());
  2135. // printf ("functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->get_firstNondefiningDeclaration());
  2136. // DQ (2/14/2007): The name used to insert symbols into the symbol table is the one returned by get_name(),
  2137. // get_templateName returns the name of the template which is required for code generation (where for
  2138. // functions the specialization is not required or not allowed).
  2139. // name = functionDeclaration->get_templateName();
  2140. name = functionDeclaration->get_name();
  2141. break;
  2142. }
  2143. case V_SgTemplateInstantiationMemberFunctionDecl:
  2144. {
  2145. const SgTemplateInstantiationMemberFunctionDecl* functionDeclaration = isSgTemplateInstantiationMemberFunctionDecl(statement);
  2146. // printf ("functionDeclaration = %p \n",functionDeclaration);
  2147. // printf ("functionDeclaration->get_definingDeclaration() = %p \n",functionDeclaration->get_definingDeclaration());
  2148. // printf ("functionDeclaration->get_firstNondefiningDeclaration() = %p \n",functionDeclaration->get_firstNondefiningDeclaration());
  2149. // DQ (2/14/2007): The name used to insert symbols into the symbol table is the one returned by get_name(),
  2150. // get_templateName returns the name of the template which is required for code generation (where for
  2151. // functions the specialization is not required or not allowed).
  2152. // name = functionDeclaration->get_templateName();
  2153. name = functionDeclaration->get_name();
  2154. break;
  2155. }
  2156. case V_SgNamespaceDeclarationStatement:
  2157. {
  2158. const SgNamespaceDeclarationStatement* namespaceDeclarationStatement = isSgNamespaceDeclarationStatement(statement);
  2159. name = namespaceDeclarationStatement->get_name();
  2160. break;
  2161. }
  2162. case V_SgTemplateDeclaration:
  2163. {
  2164. const SgTemplateDeclaration* templateDeclaration = isSgTemplateDeclaration(statement);
  2165. name = templateDeclaration->get_name();
  2166. break;
  2167. }
  2168. case V_SgTypedefDeclaration:
  2169. {
  2170. const SgTypedefDeclaration* typedefDeclaration = isSgTypedefDeclaration(statement);
  2171. name = typedefDeclaration->get_name();
  2172. break;
  2173. }
  2174. default:
  2175. {
  2176. printf ("SgSymbolTable::find(SgStatement*) undefined for %s \n",statement->class_name().c_str());
  2177. ROSE_ASSERT(false);
  2178. }
  2179. }
  2180. #endif
  2181. // printf ("Inside of SgSymbolTable::find( const SgStatement* ): name = %s \n",name.str());
  2182. // Get a quick pointer into the symbol table using the name (log n complexity)
  2183. p_iterator = p_table->find(name);
  2184. // Once we have p_iterator set via the name we don't typically have more than one iteration
  2185. while (p_iterator != p_table->end() && (*p_iterator).first == name)
  2186. {
  2187. ROSE_ASSERT(p_iterator->second != NULL);
  2188. #if 0
  2189. printf ("In loop: p_iterator->second = %p statement = %p \n",p_iterator->second,statement);
  2190. printf ("In loop: p_iterator->second = %p = %s statement = %p = %s \n",p_iterator->second,p_iterator->second->class_name().c_str(),statement,statement->class_name().c_str());
  2191. #endif
  2192. // This is a virtual function call (not defined for function type symbols)
  2193. SgNode* symbolBasis = p_iterator->second->get_symbol_basis();
  2194. #if 0
  2195. printf ("In loop: symbolBasis->variantT() = %d = %s statement->variantT() = %d = %s \n",
  2196. symbolBasis->variantT(),Cxx_GrammarTerminalNames[symbolBasis->variantT()].name,
  2197. statement->variantT(),Cxx_GrammarTerminalNames[statement->variantT()].name);
  2198. #endif
  2199. ROSE_ASSERT(symbolBasis != NULL);
  2200. if (symbolBasis->variantT() == statement->variantT())
  2201. {
  2202. // printf ("matching variants \n");
  2203. returnSymbol = p_iterator->second;
  2204. // This is a very presice test which might be a problem because of defining and non-defining versions
  2205. // of declarations (we might be able to always use the non-defining declaration in these cases. The
  2206. // switch which computes the names could normalize this aspect.
  2207. if (returnSymbol->get_symbol_basis() == statement)
  2208. {
  2209. // printf ("returnSymbol->get_symbol_basis() == statement returnSymbol = %p = %s \n",returnSymbol,returnSymbol->class_name().c_str());
  2210. return returnSymbol;
  2211. }
  2212. else
  2213. {
  2214. // printf ("returnSymbol->get_symbol_basis() != statement \n");
  2215. }
  2216. }
  2217. else
  2218. {
  2219. // printf ("Some other symbol was found (no matching variants) \n");
  2220. }
  2221. p_iterator++;
  2222. }
  2223. // DQ (2/13/2007): Fixed bug that returns a valid pointer even when there was no match to the input statement!
  2224. // return returnSymbol;
  2225. return NULL;
  2226. }
  2227. void
  2228. SgSymbolTable::remove( const SgSymbol* symbol )
  2229. {
  2230. // This is used for the handled of non function type symbol tables, and is more useful when the
  2231. // symbols don't have unique names.
  2232. // This is non-destructive (does not delete the symbol, only removes it from the symbol table).
  2233. ROSE_ASSERT (p_table != NULL);
  2234. #if 1
  2235. // #if SYMBOL_TABLE_ERROR_CHECKING
  2236. // This is an expensive linear time search of the symbol table!
  2237. ROSE_ASSERT(exists(symbol) == true);
  2238. #endif
  2239. // This is a virtual function call
  2240. SgName name = symbol->get_name();
  2241. #if 0
  2242. // printf ("In SgSymbolTable::remove(SgSymbol* symbol = %p = %s = %s) from SgSymbolTable = %p \n",symbol,symbol->class_name().c_str(),SageInterface::get_name(symbol).c_str(),this);
  2243. SgNode* symbolBasis = symbol->get_symbol_basis();
  2244. ROSE_ASSERT(symbolBasis != NULL);
  2245. printf ("In SgSymbolTable::remove(SgSymbol* symbol = %p = %s = %s) symbol_basis = %p = %s = %s from SgSymbolTable = %p \n",
  2246. symbol,symbol->class_name().c_str(),SageInterface::get_name(symbol).c_str(),
  2247. symbolBasis,symbolBasis->class_name().c_str(),SageInterface::get_name(symbolBasis).c_str(),this);
  2248. #endif
  2249. hash_multimap<SgName, SgSymbol*, hash_Name, eqstr>::iterator elementToDelete = get_table()->end();
  2250. hash_multimap<SgName, SgSymbol*, hash_Name, eqstr>::iterator it = get_table()->find(name);
  2251. while ( (it != get_table()->end()) && (elementToDelete == get_table()->end()) && ((*it).first == name) )
  2252. {
  2253. // printf ("Looking for symbol to remove (Make sure that we find the correct element) \n");
  2254. // Make sure that we find the correct element
  2255. if (it->second == symbol)
  2256. {
  2257. // printf ("Found iterator for symbol = %p \n",symbol);
  2258. elementToDelete = it;
  2259. }
  2260. it++;
  2261. }
  2262. #if 0
  2263. // #if SYMBOL_TABLE_ERROR_CHECKING
  2264. // DQ (2/11/2007): This is part of making the symbol table use more precise.
  2265. if (elementToDelete == get_table()->end())
  2266. {
  2267. printf ("Error: could not find symbol name = %s in symbol table (restart search using symbol pointer) \n",name.str());
  2268. // DQ (2/19/2007): Added assertion to exit on error! Enforcing this allows us to
  2269. // make sure that the complexity is not linear in the size of the symbol table!
  2270. ROSE_ASSERT(false);
  2271. hash_multimap<SgName, SgSymbol*, hash_Name, eqstr>::iterator i = get_table()->begin();
  2272. while ( (i != get_table()->end()) && (elementToDelete == get_table()->end()) )
  2273. {
  2274. // printf ("Looking for symbol to remove (Make sure that we find the correct element) \n");
  2275. // Make sure that we find the correct element
  2276. if (i->second == symbol)
  2277. {
  2278. // printf ("Found iterator for symbol = %p \n",symbol);
  2279. elementToDelete = i;
  2280. }
  2281. i++;
  2282. }
  2283. if (elementToDelete != get_table()->end())
  2284. {
  2285. printf ("Warning: found symbol = %p = %s stored under a different name = %s \n",symbol,symbol->class_name().c_str(),elementToDelete->first.str());
  2286. printf ("Location of problem in source code: \n");
  2287. SgDeclarationStatement* declarationStatement = isSgDeclarationStatement(symbol->get_symbol_basis());
  2288. if (declarationStatement != NULL)
  2289. {
  2290. printf ("declarationStatement = %p = %s \n",declarationStatement,declarationStatement->class_name().c_str());
  2291. declarationStatement->get_startOfConstruct()->display("location of problem: debug");
  2292. }
  2293. ROSE_ASSERT(false);
  2294. }
  2295. }
  2296. #endif
  2297. #if 0
  2298. // DQ (2/13/2007): Now we really have an error to report
  2299. // Make sure we found the input element to be removed!
  2300. if (elementToDelete == get_table()->end())
  2301. {
  2302. printf ("Error: could not find symbol = %p name = %s in symbol table (failed to find symbol pointer under any name) \n",symbol,name.str());
  2303. ROSE_ASSERT(false);
  2304. }
  2305. #endif
  2306. ROSE_ASSERT(elementToDelete != get_table()->end());
  2307. // DQ (5/9/2007): Moved to after the call to "p_symbolSet.erase(elementToDelete->second);"
  2308. // get_table()->erase(elementToDelete);
  2309. // DQ (3/10/2007): Remove the symbol from the symbol set used to test for if the symbol exists
  2310. // p_symbolSet.erase(symbol);
  2311. p_symbolSet.erase(elementToDelete->second);
  2312. get_table()->erase(elementToDelete);
  2313. }
  2314. #if 0
  2315. // *****************************************************************
  2316. // DQ (2/6/2007): These are just too dangerous to use directly.
  2317. // Use the versions which take a declaration or a symbol explicitly.
  2318. // *****************************************************************
  2319. /* ************************************************************************
  2320. DQ (1/30/2007): Added remove functions for each sort of SgSymbol IR node
  2321. ************************************************************************
  2322. void remove_function ( const SgName & );
  2323. void remove_class ( const SgName & );
  2324. void remove_enum ( const SgName & );
  2325. void remove_typedef ( const SgName & );
  2326. void remove_label ( const SgName & );
  2327. void remove_var ( const SgName & );
  2328. void remove_enum_field ( const SgName & );
  2329. void remove_function_type ( const SgName & );
  2330. void remove_namespace ( const SgName & );
  2331. */
  2332. #error "DEAD CODE!"
  2333. void
  2334. SgSymbolTable::remove_function( const SgName & name )
  2335. {
  2336. ROSE_ASSERT(p_table != NULL);
  2337. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator> deleteList;
  2338. p_iterator = p_table->find(name);
  2339. while (p_iterator != p_table->end() && (*p_iterator).first == name)
  2340. {
  2341. if (isSgFunctionSymbol((*p_iterator).second))
  2342. {
  2343. deleteList.push_back(p_iterator);
  2344. }
  2345. p_iterator++;
  2346. }
  2347. // Now remove the copy of the symbol from the symbol table and insert the shared symbol
  2348. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator>::iterator i = deleteList.begin();
  2349. while (i != deleteList.end())
  2350. {
  2351. get_table()->erase(*i);
  2352. // DQ (3/10/2007): Remove the symbol from the symbol set used to test for if the symbol exists
  2353. p_symbolSet.erase(i->second);
  2354. i++;
  2355. }
  2356. }
  2357. #error "DEAD CODE!"
  2358. void
  2359. SgSymbolTable::remove_class( const SgName & name )
  2360. {
  2361. ROSE_ASSERT(p_table != NULL);
  2362. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator> deleteList;
  2363. p_iterator = p_table->find(name);
  2364. while (p_iterator != p_table->end() && (*p_iterator).first == name)
  2365. {
  2366. if (isSgClassSymbol((*p_iterator).second))
  2367. {
  2368. deleteList.push_back(p_iterator);
  2369. }
  2370. p_iterator++;
  2371. }
  2372. // Now remove the copy of the symbol from the symbol table and insert the shared symbol
  2373. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator>::iterator i = deleteList.begin();
  2374. while (i != deleteList.end())
  2375. {
  2376. // DQ (5/9/2007): Moved to after the call to "p_symbolSet.erase(i->second);"
  2377. // get_table()->erase(*i);
  2378. // DQ (3/10/2007): Remove the symbol from the symbol set used to test for if the symbol exists
  2379. p_symbolSet.erase(i->second);
  2380. get_table()->erase(*i);
  2381. i++;
  2382. }
  2383. }
  2384. #error "DEAD CODE!"
  2385. void
  2386. SgSymbolTable::remove_enum( const SgName & name )
  2387. {
  2388. ROSE_ASSERT(p_table != NULL);
  2389. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator> deleteList;
  2390. p_iterator = p_table->find(name);
  2391. while (p_iterator != p_table->end() && (*p_iterator).first == name)
  2392. {
  2393. if (isSgEnumSymbol((*p_iterator).second))
  2394. {
  2395. deleteList.push_back(p_iterator);
  2396. }
  2397. p_iterator++;
  2398. }
  2399. // Now remove the copy of the symbol from the symbol table and insert the shared symbol
  2400. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator>::iterator i = deleteList.begin();
  2401. while (i != deleteList.end())
  2402. {
  2403. get_table()->erase(*i);
  2404. // DQ (3/10/2007): Remove the symbol from the symbol set used to test for if the symbol exists
  2405. p_symbolSet.erase(i->second);
  2406. i++;
  2407. }
  2408. }
  2409. #error "DEAD CODE!"
  2410. void
  2411. SgSymbolTable::remove_label( const SgName & name )
  2412. {
  2413. printf ("Error: not implemented yet! \n");
  2414. ROSE_ASSERT(false);
  2415. ROSE_ASSERT(p_table != NULL);
  2416. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator> deleteList;
  2417. p_iterator = p_table->find(name);
  2418. while (p_iterator != p_table->end() && (*p_iterator).first == name)
  2419. {
  2420. if (isSgEnumSymbol((*p_iterator).second))
  2421. {
  2422. deleteList.push_back(p_iterator);
  2423. }
  2424. p_iterator++;
  2425. }
  2426. // Now remove the copy of the symbol from the symbol table and insert the shared symbol
  2427. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator>::iterator i = deleteList.begin();
  2428. while (i != deleteList.end())
  2429. {
  2430. get_table()->erase(*i);
  2431. // DQ (3/10/2007): Remove the symbol from the symbol set used to test for if the symbol exists
  2432. p_symbolSet.erase(i->second);
  2433. i++;
  2434. }
  2435. }
  2436. #error "DEAD CODE!"
  2437. void
  2438. SgSymbolTable::remove_var( const SgName & name )
  2439. {
  2440. printf ("Error: not implemented yet! \n");
  2441. ROSE_ASSERT(false);
  2442. ROSE_ASSERT(p_table != NULL);
  2443. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator> deleteList;
  2444. p_iterator = p_table->find(name);
  2445. while (p_iterator != p_table->end() && (*p_iterator).first == name)
  2446. {
  2447. if (isSgEnumSymbol((*p_iterator).second))
  2448. {
  2449. deleteList.push_back(p_iterator);
  2450. }
  2451. p_iterator++;
  2452. }
  2453. // Now remove the copy of the symbol from the symbol table and insert the shared symbol
  2454. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator>::iterator i = deleteList.begin();
  2455. while (i != deleteList.end())
  2456. {
  2457. get_table()->erase(*i);
  2458. // DQ (3/10/2007): Remove the symbol from the symbol set used to test for if the symbol exists
  2459. p_symbolSet.erase(i->second);
  2460. i++;
  2461. }
  2462. }
  2463. #error "DEAD CODE!"
  2464. void
  2465. SgSymbolTable::remove_function_type( const SgName & name )
  2466. {
  2467. printf ("Error: not implemented yet! \n");
  2468. ROSE_ASSERT(false);
  2469. ROSE_ASSERT(p_table != NULL);
  2470. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator> deleteList;
  2471. p_iterator = p_table->find(name);
  2472. while (p_iterator != p_table->end() && (*p_iterator).first == name)
  2473. {
  2474. if (isSgEnumSymbol((*p_iterator).second))
  2475. {
  2476. deleteList.push_back(p_iterator);
  2477. }
  2478. p_iterator++;
  2479. }
  2480. // Now remove the copy of the symbol from the symbol table and insert the shared symbol
  2481. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator>::iterator i = deleteList.begin();
  2482. while (i != deleteList.end())
  2483. {
  2484. get_table()->erase(*i);
  2485. // DQ (3/10/2007): Remove the symbol from the symbol set used to test for if the symbol exists
  2486. p_symbolSet.erase(i->second);
  2487. i++;
  2488. }
  2489. }
  2490. #error "DEAD CODE!"
  2491. void
  2492. SgSymbolTable::remove_namespace( const SgName & name )
  2493. {
  2494. printf ("Error: not implemented yet! \n");
  2495. ROSE_ASSERT(false);
  2496. ROSE_ASSERT(p_table != NULL);
  2497. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator> deleteList;
  2498. p_iterator = p_table->find(name);
  2499. while (p_iterator != p_table->end() && (*p_iterator).first == name)
  2500. {
  2501. if (isSgEnumSymbol((*p_iterator).second))
  2502. {
  2503. deleteList.push_back(p_iterator);
  2504. }
  2505. p_iterator++;
  2506. }
  2507. // Now remove the copy of the symbol from the symbol table and insert the shared symbol
  2508. list<hash_multimap<const SgName, SgSymbol*, hash_Name, eqstr>::iterator>::iterator i = deleteList.begin();
  2509. while (i != deleteList.end())
  2510. {
  2511. get_table()->erase(*i);
  2512. // DQ (3/10/2007): Remove the symbol from the symbol set used to test for if the symbol exists
  2513. p_symbolSet.erase(i->second);
  2514. i++;
  2515. }
  2516. }
  2517. #error "DEAD CODE!"
  2518. #endif
  2519. /* ************************************************************************
  2520. FIND FUNCTIONS
  2521. ************************************************************************/
  2522. // DQ (2/10/2007): This is a depricated function
  2523. int
  2524. SgSymbolTable::find(const SgName & nm, SgSymbol *sp)
  2525. {
  2526. ROSE_ASSERT(p_table != NULL);
  2527. // if(!p_table)
  2528. // return NULL;
  2529. // DQ (5/22/2006): Made this a local variable
  2530. // hash_iterator p_iterator = p_table->find(nm);
  2531. p_iterator = p_table->find(nm);
  2532. // while (p_iterator != p_table->end() && (*p_iterator).first == nm)
  2533. while (p_iterator != p_table->end() && p_iterator->first == nm)
  2534. {
  2535. p_name = nm;
  2536. p_no_name = false;
  2537. // if( ((SgSymbol *)(*p_iterator).second) == sp )
  2538. if( p_iterator->second == sp )
  2539. return true;
  2540. p_iterator++;
  2541. }
  2542. return false;
  2543. }
  2544. // DQ (1/31/2007): New functions that will replace the depricated find() member function
  2545. bool
  2546. SgSymbolTable::exists ( const SgName & nm ) const
  2547. {
  2548. ROSE_ASSERT(p_table != NULL);
  2549. return p_table->find(nm) != p_table->end();
  2550. }
  2551. // DQ (1/31/2007): New functions that will replace the depricated find() member function
  2552. bool
  2553. SgSymbolTable::exists ( const SgSymbol *sp ) const
  2554. {
  2555. #if 0
  2556. // DQ (2/19/2007): Make sure that this sort of expensive symbol table is not called if SYMBOL_TABLE_ERROR_CHECKING is not active
  2557. #if SYMBOL_TABLE_ERROR_CHECKING == 0
  2558. printf ("Error: Expensive symbol table tests being called while SYMBOL_TABLE_ERROR_CHECKING == 0 \n");
  2559. ROSE_ASSERT(false);
  2560. #endif
  2561. // This is the more expensive implementation but more useful for error checking!
  2562. bool returnValue = false;
  2563. ROSE_ASSERT(p_table != NULL);
  2564. hash_iterator i = p_table->begin();
  2565. while ( returnValue == false && i != p_table->end() )
  2566. {
  2567. // if ((SgSymbol *)(i->second) == sp )
  2568. if ( i->second == sp )
  2569. returnValue = true;
  2570. i++;
  2571. }
  2572. return returnValue;
  2573. #else
  2574. // DQ (3/10/2007): We can now use the stored p_symbolSet (STL set of SgNode*) to do this test more efficiently.
  2575. // return p_symbolSet.find(sp) != p_symbolSet.end();
  2576. return p_symbolSet.find(const_cast<SgSymbol*>(sp)) != p_symbolSet.end();
  2577. #endif
  2578. }
  2579. // DQ (1/31/2007): New functions that will replace the depricated find() member function
  2580. bool
  2581. SgSymbolTable::exists ( const SgName & nm, SgSymbol *sp ) const
  2582. {
  2583. #if 0
  2584. bool returnValue = false;
  2585. ROSE_ASSERT(p_table != NULL);
  2586. hash_iterator i = p_table->find(nm);
  2587. while ( returnValue == false && i != p_table->end() && i->first == nm )
  2588. {
  2589. if ( i->second == sp )
  2590. returnValue = true;
  2591. i++;
  2592. }
  2593. return returnValue;
  2594. #else
  2595. // DQ (3/10/2007): We can now use the stored p_symbolSet (STL set of SgNode*) to do this test more efficiently.
  2596. // Since we if we find the symbol it exists, we can test the name separately
  2597. // bool returnValue = false;
  2598. // Test if the symbol is in the set, else the name is not relavant to the existence
  2599. if (p_symbolSet.find(sp) != p_symbolSet.end())
  2600. {
  2601. // Now look to make sure that we have an entry with the correct name (and pointer value)
  2602. hash_iterator p_iterator = p_table->find(nm);
  2603. while (p_iterator != p_table->end() && p_iterator->first == nm)
  2604. {
  2605. if ( p_iterator->second == sp )
  2606. {
  2607. // This allows us to short-circuit the rest of the iterations
  2608. return true;
  2609. }
  2610. p_iterator++;
  2611. }
  2612. }
  2613. return false;
  2614. #endif
  2615. }
  2616. /* ************************************************************************
  2617. DQ (1/30/2007): Added remove functions for each sort of SgSymbol IR node
  2618. ************************************************************************
  2619. SgSymbol* find_any(const SgName &);
  2620. SgVariableSymbol* find_variable(const SgName &);
  2621. SgClassSymbol* find_class(const SgName &);
  2622. SgFunctionSymbol* find_function(const SgName&);
  2623. SgFunctionSymbol* find_function_type(const SgName&, const SgType*);
  2624. SgTypedefSymbol* find_typedef(const SgName &);
  2625. SgEnumSymbol* find_enum(const SgName &);
  2626. SgEnumFieldSymbol* find_enum_field(const SgName &);
  2627. SgLabelSymbol* find_label(const SgName &) const;
  2628. SgNamespaceSymbol* find_namespace(const SgName &);
  2629. */
  2630. SgSymbol*
  2631. SgSymbolTable::findany(const SgName &nm)
  2632. {
  2633. return find_any(nm);
  2634. }
  2635. SgSymbol*
  2636. SgSymbolTable::find_any(const SgName &nm)
  2637. {
  2638. ROSE_ASSERT(p_table != NULL);
  2639. if(p_table)
  2640. {
  2641. // DQ (5/22/2006): Made this a local variable
  2642. // hash_iterator p_iterator = p_table->find(nm);
  2643. p_iterator = p_table->find(nm);
  2644. if (p_iterator != p_table->end() && p_iterator->first == nm)
  2645. {
  2646. p_name = nm;
  2647. p_no_name = false;
  2648. return (SgSymbol *) p_iterator->second;
  2649. }
  2650. }
  2651. return NULL;
  2652. }
  2653. // DQ (1/30/2007): Added these back into ROSE.
  2654. SgTypedefSymbol*
  2655. SgSymbolTable::find_typedef(const SgName &nm)
  2656. {
  2657. ROSE_ASSERT(p_table != NULL);
  2658. if(p_table)
  2659. {
  2660. p_iterator=p_table->find(nm);
  2661. while(p_iterator != p_table->end() && p_iterator->first == nm)
  2662. {
  2663. // if(isSgTypedefSymbol((*p_iterator).second))
  2664. if ( p_iterator->second->variantT() == V_SgTypedefSymbol)
  2665. {
  2666. p_name=nm;
  2667. p_no_name = false;
  2668. return (SgTypedefSymbol *) p_iterator->second;
  2669. }
  2670. p_iterator++;
  2671. }
  2672. }
  2673. return NULL;
  2674. }
  2675. // DQ (1/30/2007): Added these back into ROSE.
  2676. SgEnumSymbol*
  2677. SgSymbolTable::find_enum(const SgName &nm)
  2678. {
  2679. ROSE_ASSERT(p_table != NULL);
  2680. if(p_table != NULL)
  2681. {
  2682. p_iterator=p_table->find(nm);
  2683. while(p_iterator != p_table->end() && (*p_iterator).first == nm)
  2684. {
  2685. // if (isSgEnumSymbol((*p_iterator).second))
  2686. if ( p_iterator->second->variantT() == V_SgEnumSymbol)
  2687. {
  2688. p_name = nm;
  2689. p_no_name = false;
  2690. return (SgEnumSymbol *) p_iterator->second;
  2691. }
  2692. p_iterator++;
  2693. }
  2694. }
  2695. return NULL;
  2696. }
  2697. // DQ (1/30/2007): Added these back into ROSE.
  2698. SgEnumFieldSymbol*
  2699. SgSymbolTable::find_enum_field(const SgName &nm)
  2700. {
  2701. ROSE_ASSERT(p_table != NULL);
  2702. if(p_table)
  2703. {
  2704. p_iterator=p_table->find(nm);
  2705. while(p_iterator != p_table->end() && p_iterator->first == nm)
  2706. {
  2707. // if (isSgEnumFieldSymbol((*p_iterator).second))
  2708. if ( p_iterator->second->variantT() == V_SgEnumFieldSymbol)
  2709. {
  2710. p_name=nm;
  2711. p_no_name = false;
  2712. return (SgEnumFieldSymbol *) p_iterator->second;
  2713. }
  2714. p_iterator++;
  2715. }
  2716. }
  2717. return NULL;
  2718. }
  2719. SgVariableSymbol*
  2720. SgSymbolTable::findvar(const SgName &nm)
  2721. {
  2722. return find_variable(nm);
  2723. }
  2724. SgVariableSymbol*
  2725. SgSymbolTable::find_variable(const SgName &nm)
  2726. {
  2727. ROSE_ASSERT(p_table != NULL);
  2728. if(p_table)
  2729. {
  2730. p_iterator=p_table->find(nm);
  2731. while(p_iterator != p_table->end() && (*p_iterator).first==nm)
  2732. {
  2733. // if(isSgVariableSymbol((*p_iterator).second))
  2734. if ( p_iterator->second->variantT() == V_SgVariableSymbol)
  2735. {
  2736. p_name = nm;
  2737. p_no_name = false;
  2738. return (SgVariableSymbol *) p_iterator->second;
  2739. }
  2740. p_iterator++;
  2741. }
  2742. }
  2743. return NULL;
  2744. }
  2745. SgClassSymbol*
  2746. SgSymbolTable::findclass(const SgName &nm)
  2747. {
  2748. return find_class(nm);
  2749. }
  2750. SgClassSymbol*
  2751. SgSymbolTable::find_class(const SgName &nm)
  2752. {
  2753. ROSE_ASSERT(p_table != NULL);
  2754. if (p_table != NULL)
  2755. {
  2756. p_iterator=p_table->find(nm);
  2757. while (p_iterator != p_table->end() && (*p_iterator).first==nm)
  2758. {
  2759. // if (isSgClassSymbol((*p_iterator).second))
  2760. if ( p_iterator->second->variantT() == V_SgClassSymbol)
  2761. {
  2762. p_name = nm;
  2763. p_no_name = false;
  2764. return (SgClassSymbol *) p_iterator->second;
  2765. }
  2766. p_iterator++;
  2767. }
  2768. }
  2769. return NULL;
  2770. }
  2771. SgFunctionTypeSymbol*
  2772. SgSymbolTable::findfunctype(const SgName &nm)
  2773. {
  2774. return find_function_type(nm);
  2775. }
  2776. SgFunctionTypeSymbol*
  2777. SgSymbolTable::find_function_type(const SgName &nm)
  2778. {
  2779. ROSE_ASSERT(p_table != NULL);
  2780. SgFunctionTypeSymbol* returnFunctionType = NULL;
  2781. hash_iterator i = p_table->find(nm);
  2782. // if (i != p_table->end() && isSgFunctionTypeSymbol((*i).second))
  2783. if (i != p_table->end() && i->second->variantT() == V_SgFunctionTypeSymbol)
  2784. {
  2785. // return (SgFunctionTypeSymbol *) i->second;
  2786. returnFunctionType = (SgFunctionTypeSymbol *) i->second;
  2787. }
  2788. // return NULL;
  2789. return returnFunctionType;
  2790. }
  2791. SgLabelSymbol*
  2792. SgSymbolTable::find_label(const SgName &nm)
  2793. {
  2794. ROSE_ASSERT(p_table != NULL);
  2795. if (p_table)
  2796. {
  2797. p_iterator = p_table->find(nm);
  2798. while (p_iterator != p_table->end() && (*p_iterator).first == nm)
  2799. {
  2800. // if (isSgNamespaceSymbol((*p_iterator).second))
  2801. if ( p_iterator->second->variantT() == V_SgLabelSymbol)
  2802. {
  2803. p_name = nm;
  2804. p_no_name = false;
  2805. return (SgLabelSymbol *) p_iterator->second;
  2806. }
  2807. p_iterator++;
  2808. }
  2809. }
  2810. return NULL;
  2811. }
  2812. // DQ (1/30/2007): Added these back into ROSE.
  2813. SgNamespaceSymbol*
  2814. SgSymbolTable::find_namespace ( const SgName & nm )
  2815. {
  2816. ROSE_ASSERT(p_table != NULL);
  2817. if (p_table)
  2818. {
  2819. p_iterator = p_table->find(nm);
  2820. while (p_iterator != p_table->end() && (*p_iterator).first == nm)
  2821. {
  2822. // if (isSgNamespaceSymbol((*p_iterator).second))
  2823. if ( p_iterator->second->variantT() == V_SgNamespaceSymbol)
  2824. {
  2825. p_name = nm;
  2826. p_no_name = false;
  2827. return (SgNamespaceSymbol *) p_iterator->second;
  2828. }
  2829. p_iterator++;
  2830. }
  2831. }
  2832. return NULL;
  2833. }
  2834. SgFunctionSymbol*
  2835. SgSymbolTable::findfunc(const SgName &nm, const SgType* t)
  2836. {
  2837. return find_function(nm,t);
  2838. }
  2839. SgFunctionSymbol*
  2840. SgSymbolTable::find_function (const SgName &nm, const SgType* t)
  2841. {
  2842. // AS (083006): cleaned up logic so that the function only have one return statement.
  2843. SgFunctionSymbol *s = NULL;
  2844. ROSE_ASSERT(p_table != NULL);
  2845. if(p_table)
  2846. {
  2847. // AJ (10/21/2004): Adjusted implementation to use new STL hash map interface
  2848. // SgSymbolHashBase::iterator i=p_table->find(nm);
  2849. // JW and AS (08/30/06) changed to use equal range rather than find and
  2850. // iterating through the hash table. This is an optimization.
  2851. std::pair<hash_iterator, hash_iterator> range = p_table->equal_range(nm);
  2852. for (hash_iterator i = range.first; i != range.second; ++i)
  2853. {
  2854. // s = isSgFunctionSymbol((*i).second);
  2855. s = isSgFunctionSymbol(i->second);
  2856. if ( (s != NULL) && (s->get_declaration()->get_type() == t))
  2857. {
  2858. p_name = nm;
  2859. p_no_name = false;
  2860. // return ((SgFunctionSymbol *)(*i).second);
  2861. break;
  2862. }
  2863. }
  2864. }
  2865. return s;
  2866. }
  2867. SgFunctionSymbol*
  2868. SgSymbolTable::findfunc(const SgName &nm)
  2869. {
  2870. return find_function(nm);
  2871. }
  2872. SgFunctionSymbol*
  2873. SgSymbolTable::find_function(const SgName &nm)
  2874. {
  2875. ROSE_ASSERT(p_table != NULL);
  2876. if(p_table)
  2877. {
  2878. p_iterator =p_table->find(nm);
  2879. while(p_iterator != p_table->end())
  2880. {
  2881. // if(isSgFunctionSymbol((*p_iterator).second))
  2882. if ( p_iterator->second->variantT() == V_SgFunctionSymbol)
  2883. {
  2884. p_name = nm;
  2885. p_no_name = false;
  2886. return (SgFunctionSymbol *) p_iterator->second;
  2887. }
  2888. p_iterator++;
  2889. }
  2890. }
  2891. return NULL;
  2892. }
  2893. SgTemplateSymbol*
  2894. SgSymbolTable::find_template(const SgName &nm)
  2895. {
  2896. ROSE_ASSERT(p_table != NULL);
  2897. if(p_table)
  2898. {
  2899. p_iterator =p_table->find(nm);
  2900. while(p_iterator != p_table->end())
  2901. {
  2902. // if(isSgTemplateSymbol((*p_iterator).second))
  2903. if ( p_iterator->second->variantT() == V_SgTemplateSymbol)
  2904. {
  2905. p_name = nm;
  2906. p_no_name = false;
  2907. return (SgTemplateSymbol *) p_iterator->second;
  2908. }
  2909. p_iterator++;
  2910. }
  2911. }
  2912. return NULL;
  2913. }
  2914. /* ************************************************************************
  2915. DQ (1/30/2007): Added remove functions for each sort of SgSymbol IR node
  2916. ************************************************************************
  2917. SgSymbol* find_any();
  2918. SgVariableSymbol* find_variable();
  2919. SgClassSymbol* find_class();
  2920. SgFunctionSymbol* find_function();
  2921. SgFunctionSymbol* find_function_type();
  2922. SgTypedefSymbol* find_typedef();
  2923. SgEnumSymbol* find_enum();
  2924. SgEnumFieldSymbol* find_enum_field();
  2925. SgLabelSymbol* find_label();
  2926. SgNamespaceSymbol* find_namespace();
  2927. */
  2928. // DQ (9/7/2006): Previously removed functionality, restored by request from Beata at ANL.
  2929. SgSymbol*
  2930. SgSymbolTable::findfirstany()
  2931. {
  2932. return find_any();
  2933. }
  2934. SgSymbol*
  2935. SgSymbolTable::find_any()
  2936. {
  2937. ROSE_ASSERT(p_table != NULL);
  2938. if(p_table)
  2939. {
  2940. p_iterator = p_table->begin();
  2941. p_no_name = true;
  2942. if(p_iterator != p_table->end())
  2943. // return ((SgSymbol *) (*p_iterator).second);
  2944. return (SgSymbol *) p_iterator->second;
  2945. }
  2946. return NULL;
  2947. }
  2948. // DQ (9/7/2006): Previously removed functionality, restored by request from Beata at ANL.
  2949. SgVariableSymbol*
  2950. SgSymbolTable::findfirstvar()
  2951. {
  2952. return find_variable();
  2953. }
  2954. SgVariableSymbol*
  2955. SgSymbolTable::find_variable()
  2956. {
  2957. ROSE_ASSERT(p_table != NULL);
  2958. if(p_table)
  2959. {
  2960. p_iterator = p_table->begin();
  2961. p_no_name = true;
  2962. while(p_iterator != p_table->end())
  2963. {
  2964. // if(isSgVariableSymbol((*p_iterator).second))
  2965. // return ((SgVariableSymbol *)(*p_iterator).second);
  2966. if (p_iterator->second->variantT() == V_SgVariableSymbol)
  2967. return (SgVariableSymbol *) p_iterator->second;
  2968. p_iterator++;
  2969. }
  2970. }
  2971. return NULL;
  2972. }
  2973. // DQ (1/30/2007): Added these back into ROSE.
  2974. SgClassSymbol*
  2975. SgSymbolTable::findfirstclass()
  2976. {
  2977. return find_class();
  2978. }
  2979. SgClassSymbol*
  2980. SgSymbolTable::find_class()
  2981. {
  2982. ROSE_ASSERT(p_table != NULL);
  2983. if (p_table)
  2984. {
  2985. p_iterator = p_table->begin();
  2986. p_no_name = true;
  2987. while (p_iterator != p_table->end())
  2988. {
  2989. // if (isSgClassSymbol((*p_iterator).second))
  2990. // return ((SgClassSymbol *)(*p_iterator).second);
  2991. if (p_iterator->second->variantT() == V_SgClassSymbol)
  2992. return (SgClassSymbol *) p_iterator->second;
  2993. p_iterator++;
  2994. }
  2995. }
  2996. return NULL;
  2997. }
  2998. // DQ (1/30/2007): Added these back into ROSE.
  2999. SgFunctionSymbol*
  3000. SgSymbolTable::findfirstfunction()
  3001. {
  3002. return find_function();
  3003. }
  3004. SgFunctionSymbol*
  3005. SgSymbolTable::find_function()
  3006. {
  3007. ROSE_ASSERT(p_table != NULL);
  3008. if(p_table)
  3009. {
  3010. p_iterator = p_table->begin();
  3011. p_no_name = true;
  3012. while(p_iterator != p_table->end())
  3013. {
  3014. // if(isSgFunctionSymbol((*p_iterator).second))
  3015. // return ((SgFunctionSymbol *)(*p_iterator).second);
  3016. if (p_iterator->second->variantT() == V_SgFunctionSymbol)
  3017. return (SgFunctionSymbol *) p_iterator->second;
  3018. p_iterator++;
  3019. }
  3020. }
  3021. return NULL;
  3022. }
  3023. #if 0
  3024. // DQ (1/30/2007): Added to make the interface consistant
  3025. // This function is not requires since SgFunctionTypeSymbols
  3026. // are stored into their own function table. So this is
  3027. // equivalent to STL function "begin()".
  3028. SgFunctionSymbol*
  3029. SgSymbolTable::find_function_type()
  3030. {
  3031. ROSE_ASSERT(p_table != NULL);
  3032. if(p_table)
  3033. {
  3034. p_iterator = p_table->begin();
  3035. p_no_name = true;
  3036. while(p_iterator != p_table->end())
  3037. {
  3038. // if(isSgFunctionSymbol((*p_iterator).second))
  3039. // return ((SgFunctionSymbol *)(*p_iterator).second);
  3040. if (p_iterator->second->variantT() == V_SgFunctionTypeSymbol)
  3041. return (SgFunctionTypeSymbol *) p_iterator->second;
  3042. p_iterator++;
  3043. }
  3044. }
  3045. return NULL;
  3046. }
  3047. #endif
  3048. SgTypedefSymbol*
  3049. SgSymbolTable::find_typedef()
  3050. {
  3051. ROSE_ASSERT(p_table != NULL);
  3052. if (p_table)
  3053. {
  3054. p_iterator = p_table->begin();
  3055. p_no_name = true;
  3056. while (p_iterator != p_table->end())
  3057. {
  3058. // if (isSgTypedefSymbol((*p_iterator).second))
  3059. // return ((SgTypedefSymbol *)(*p_iterator).second);
  3060. if (p_iterator->second->variantT() == V_SgTypedefSymbol)
  3061. return (SgTypedefSymbol *) p_iterator->second;
  3062. p_iterator++;
  3063. }
  3064. }
  3065. return NULL;
  3066. }
  3067. SgEnumSymbol*
  3068. SgSymbolTable::find_enum()
  3069. {
  3070. ROSE_ASSERT(p_table != NULL);
  3071. if (p_table)
  3072. {
  3073. p_iterator = p_table->begin();
  3074. p_no_name = true;
  3075. while (p_iterator != p_table->end())
  3076. {
  3077. // if (isSgEnumSymbol((*p_iterator).second))
  3078. // return ((SgEnumSymbol *)(*p_iterator).second);
  3079. if (p_iterator->second->variantT() == V_SgEnumSymbol)
  3080. return (SgEnumSymbol *) p_iterator->second;
  3081. p_iterator++;
  3082. }
  3083. }
  3084. return NULL;
  3085. }
  3086. SgEnumFieldSymbol*
  3087. SgSymbolTable::find_enum_field()
  3088. {
  3089. ROSE_ASSERT(p_table != NULL);
  3090. if (p_table)
  3091. {
  3092. p_iterator = p_table->begin();
  3093. p_no_name = true;
  3094. while (p_iterator != p_table->end())
  3095. {
  3096. // if (isSgEnumFieldSymbol((*p_iterator).second))
  3097. // return ((SgEnumFieldSymbol *)(*p_iterator).second);
  3098. if (p_iterator->second->variantT() == V_SgEnumFieldSymbol)
  3099. return (SgEnumFieldSymbol *) p_iterator->second;
  3100. p_iterator++;
  3101. }
  3102. }
  3103. return NULL;
  3104. }
  3105. SgLabelSymbol*
  3106. SgSymbolTable::find_label()
  3107. {
  3108. ROSE_ASSERT(p_table != NULL);
  3109. if (p_table)
  3110. {
  3111. p_iterator = p_table->begin();
  3112. p_no_name = true;
  3113. while (p_iterator != p_table->end())
  3114. {
  3115. // if (isSgLabelSymbol((*p_iterator).second))
  3116. // return ((SgLabelSymbol *)(*p_iterator).second);
  3117. if (p_iterator->second->variantT() == V_SgLabelSymbol)
  3118. return (SgLabelSymbol *) p_iterator->second;
  3119. p_iterator++;
  3120. }
  3121. }
  3122. return NULL;
  3123. }
  3124. SgNamespaceSymbol*
  3125. SgSymbolTable::find_namespace()
  3126. {
  3127. ROSE_ASSERT(p_table != NULL);
  3128. if (p_table)
  3129. {
  3130. p_iterator = p_table->begin();
  3131. p_no_name = true;
  3132. while (p_iterator != p_table->end())
  3133. {
  3134. // if (isSgNamespaceSymbol((*p_iterator).second))
  3135. // return ((SgNamespaceSymbol *)(*p_iterator).second);
  3136. if (p_iterator->second->variantT() == V_SgNamespaceSymbol)
  3137. return (SgNamespaceSymbol *) p_iterator->second;
  3138. p_iterator++;
  3139. }
  3140. }
  3141. return NULL;
  3142. }
  3143. SgTemplateSymbol*
  3144. SgSymbolTable::find_template()
  3145. {
  3146. ROSE_ASSERT(p_table != NULL);
  3147. if (p_table)
  3148. {
  3149. p_iterator = p_table->begin();
  3150. p_no_name = true;
  3151. while (p_iterator != p_table->end())
  3152. {
  3153. // if (isSgTemplateSymbol((*p_iterator).second))
  3154. // return ((SgTemplateSymbol *)(*p_iterator).second);
  3155. if (p_iterator->second->variantT() == V_SgTemplateSymbol)
  3156. return (SgTemplateSymbol *) p_iterator->second;
  3157. p_iterator++;
  3158. }
  3159. }
  3160. return NULL;
  3161. }
  3162. /* ************************************************************************
  3163. DQ (1/30/2007): Added remove functions for each sort of SgSymbol IR node
  3164. ************************************************************************
  3165. SgSymbol* next_any();
  3166. SgVariableSymbol* next_variable();
  3167. SgClassSymbol* next_class();
  3168. SgFunctionSymbol* next_function();
  3169. SgTypedefSymbol* next_typedef();
  3170. SgEnumSymbol* next_enum();
  3171. SgEnumFieldSymbol* next_enum_field();
  3172. SgLabelSymbol* next_label();
  3173. SgNamespaceSymbol* next_namespace();
  3174. */
  3175. // DQ (9/7/2006): Previously removed functionality, restored by request from Beata at ANL.
  3176. SgSymbol*
  3177. SgSymbolTable::nextany()
  3178. {
  3179. return next_any();
  3180. }
  3181. SgSymbol*
  3182. SgSymbolTable::next_any()
  3183. {
  3184. ROSE_ASSERT(p_table != NULL);
  3185. if(p_table)
  3186. {
  3187. p_iterator++;
  3188. // DQ (10/8/2007): Is there a use of find that would be O(log n) and be a faster way to return the next matching entry?
  3189. while( p_iterator != p_table->end() )
  3190. {
  3191. if( p_no_name || (*p_iterator).first == p_name )
  3192. return (SgSymbol *) p_iterator->second;
  3193. p_iterator++;
  3194. }
  3195. }
  3196. return NULL;
  3197. }
  3198. // DQ (9/7/2006): Previously removed functionality, restored by request from Beata at ANL.
  3199. SgVariableSymbol*
  3200. SgSymbolTable::nextvar()
  3201. {
  3202. return next_variable();
  3203. }
  3204. SgVariableSymbol*
  3205. SgSymbolTable::next_variable()
  3206. {
  3207. ROSE_ASSERT(p_table != NULL);
  3208. if (p_table != NULL)
  3209. {
  3210. p_iterator++;
  3211. // DQ (10/8/2007): Is there a use of find that would be O(log n) and be a faster way to return the next matching entry?
  3212. while( p_iterator != p_table->end() && (p_no_name || (*p_iterator).first==p_name))
  3213. {
  3214. if (isSgVariableSymbol((*p_iterator).second))
  3215. return ((SgVariableSymbol *) (*p_iterator).second);
  3216. p_iterator++;
  3217. }
  3218. }
  3219. return NULL;
  3220. }
  3221. // DQ (1/30/2007): Added these back into ROSE.
  3222. SgClassSymbol*
  3223. SgSymbolTable::nextclass()
  3224. {
  3225. return next_class();
  3226. }
  3227. SgClassSymbol*
  3228. SgSymbolTable::next_class()
  3229. {
  3230. ROSE_ASSERT(p_table != NULL);
  3231. if(p_table)
  3232. {
  3233. p_iterator++; // go to next one
  3234. // DQ (10/8/2007): Is there a use of find that would be O(log n) and be a faster way to return the next matching entry?
  3235. while( p_iterator != p_table->end() && (p_no_name || (*p_iterator).first==p_name))
  3236. {
  3237. if(isSgClassSymbol((*p_iterator).second))
  3238. return ((SgClassSymbol *)(*p_iterator).second);
  3239. p_iterator++;
  3240. }
  3241. }
  3242. return NULL;
  3243. }
  3244. // DQ (1/30/2007): Added these back into ROSE.
  3245. SgFunctionSymbol*
  3246. SgSymbolTable::nextfunc()
  3247. {
  3248. return next_function();
  3249. }
  3250. SgFunctionSymbol*
  3251. SgSymbolTable::next_function()
  3252. {
  3253. ROSE_ASSERT(p_table != NULL);
  3254. if(p_table)
  3255. {
  3256. p_iterator++;
  3257. // DQ (10/8/2007): Is there a use of find that would be O(log n) and be a faster way to return the next matching entry?
  3258. while( p_iterator != p_table->end() && (p_no_name || (*p_iterator).first==p_name))
  3259. {
  3260. if(isSgFunctionSymbol((*p_iterator).second))
  3261. return ((SgFunctionSymbol *)(*p_iterator).second);
  3262. p_iterator++;
  3263. }
  3264. }
  3265. return NULL;
  3266. }
  3267. SgTypedefSymbol*
  3268. SgSymbolTable::next_typedef()
  3269. {
  3270. ROSE_ASSERT(p_table != NULL);
  3271. if (p_table != NULL)
  3272. {
  3273. p_iterator++;
  3274. // DQ (10/8/2007): Is there a use of find that would be O(log n) and be a faster way to return the next matching entry?
  3275. while( p_iterator != p_table->end() && (p_no_name || (*p_iterator).first==p_name))
  3276. {
  3277. if (isSgTypedefSymbol((*p_iterator).second))
  3278. return ((SgTypedefSymbol *) (*p_iterator).second);
  3279. p_iterator++;
  3280. }
  3281. }
  3282. return NULL;
  3283. }
  3284. // DQ (1/30/2007): Added this as a new member function.
  3285. SgEnumSymbol*
  3286. SgSymbolTable::next_enum()
  3287. {
  3288. ROSE_ASSERT(p_table != NULL);
  3289. if(p_table)
  3290. {
  3291. p_iterator++;
  3292. // DQ (10/8/2007): Is there a use of find that would be O(log n) and be a faster way to return the next matching entry?
  3293. while( p_iterator != p_table->end() && (p_no_name || (*p_iterator).first==p_name))
  3294. {
  3295. if(isSgEnumSymbol((*p_iterator).second))
  3296. return ((SgEnumSymbol *)(*p_iterator).second);
  3297. p_iterator++;
  3298. }
  3299. }
  3300. return NULL;
  3301. }
  3302. // DQ (1/30/2007): Added this as a new member function.
  3303. SgEnumFieldSymbol*
  3304. SgSymbolTable::next_enum_field()
  3305. {
  3306. ROSE_ASSERT(p_table != NULL);
  3307. if(p_table)
  3308. {
  3309. p_iterator++;
  3310. // DQ (10/8/2007): Is there a use of find that would be O(log n) and be a faster way to return the next matching entry?
  3311. while( p_iterator != p_table->end() && (p_no_name || (*p_iterator).first==p_name))
  3312. {
  3313. if(isSgEnumFieldSymbol((*p_iterator).second))
  3314. return ((SgEnumFieldSymbol *)(*p_iterator).second);
  3315. p_iterator++;
  3316. }
  3317. }
  3318. return NULL;
  3319. }
  3320. SgLabelSymbol*
  3321. SgSymbolTable::next_label()
  3322. {
  3323. ROSE_ASSERT(p_table != NULL);
  3324. if (p_table != NULL)
  3325. {
  3326. p_iterator++;
  3327. // DQ (10/8/2007): Is there a use of find that would be O(log n) and be a faster way to return the next matching entry?
  3328. while( p_iterator != p_table->end() && (p_no_name || (*p_iterator).first==p_name))
  3329. {
  3330. if (isSgLabelSymbol((*p_iterator).second))
  3331. return ((SgLabelSymbol *) (*p_iterator).second);
  3332. p_iterator++;
  3333. }
  3334. }
  3335. return NULL;
  3336. }
  3337. SgNamespaceSymbol*
  3338. SgSymbolTable::next_namespace()
  3339. {
  3340. ROSE_ASSERT(p_table != NULL);
  3341. if (p_table != NULL)
  3342. {
  3343. p_iterator++;
  3344. // DQ (10/8/2007): Is there a use of find that would be O(log n) and be a faster way to return the next matching entry?
  3345. while( p_iterator != p_table->end() && (p_no_name || (*p_iterator).first==p_name))
  3346. {
  3347. if (isSgNamespaceSymbol((*p_iterator).second))
  3348. return ((SgNamespaceSymbol *) (*p_iterator).second);
  3349. p_iterator++;
  3350. }
  3351. }
  3352. return NULL;
  3353. }
  3354. SgTemplateSymbol*
  3355. SgSymbolTable::next_template()
  3356. {
  3357. ROSE_ASSERT(p_table != NULL);
  3358. if (p_table != NULL)
  3359. {
  3360. p_iterator++;
  3361. // DQ (10/8/2007): Is there a use of find that would be O(log n) and be a faster way to return the next matching entry?
  3362. while( p_iterator != p_table->end() && (p_no_name || (*p_iterator).first==p_name))
  3363. {
  3364. if (isSgTemplateSymbol((*p_iterator).second))
  3365. return ((SgTemplateSymbol *) (*p_iterator).second);
  3366. p_iterator++;
  3367. }
  3368. }
  3369. return NULL;
  3370. }
  3371. #if 1
  3372. // DQ (1/30/2007): Added these back into ROSE.
  3373. SgSymbol*
  3374. SgSymbolTable::operator[](const SgName & nm)
  3375. {
  3376. ROSE_ASSERT(p_table != NULL);
  3377. if (p_table != NULL)
  3378. {
  3379. // AJ (10/21/2004): Adjusted implementation to use new STL hash map interface
  3380. // SgSymbolHashBase::iterator i=p_table->find(nm);
  3381. hash_iterator i=p_table->find(nm);
  3382. if (i != p_table->end())
  3383. return (*i).second;
  3384. }
  3385. return NULL;
  3386. }
  3387. #endif
  3388. // AJ (10/21/2004): Adjusted implementation to use new STL hash map interface
  3389. int
  3390. SgSymbolTable::size() const
  3391. {
  3392. ROSE_ASSERT(p_table != NULL);
  3393. return p_table->size();
  3394. }
  3395. // AJ (10/21/2004): Adjusted implementation to use new STL hash map interface
  3396. int
  3397. SgSymbolTable::count(const SgName &nm) const
  3398. {
  3399. // DQ (1/30/2007): assertion added
  3400. ROSE_ASSERT(p_table != NULL);
  3401. return p_table->count(nm);
  3402. }
  3403. void
  3404. SgSymbolTable::print(std::ostream& os)
  3405. {
  3406. ROSE_ASSERT(p_table != NULL);
  3407. if (p_table != NULL)
  3408. {
  3409. #if 0
  3410. SgSymbolHashBase::iterator i=p_table->begin();
  3411. int idx = 0;
  3412. while (i != p_table->end())
  3413. {
  3414. os << "[" << idx << "] " << (*i).first << "--";
  3415. SgFunctionTypeSymbol *f=isSgFunctionTypeSymbol((*i).second);
  3416. if (f)
  3417. {
  3418. isSgFunctionType(f->get_type())->sym_print(os);
  3419. }
  3420. SgFunctionSymbol *ft = isSgFunctionSymbol((*i).second);
  3421. if (ft)
  3422. {
  3423. isSgFunctionType(ft->get_declaration()->get_type())->sym_print(os);
  3424. }
  3425. os << count((*i).first) << endl;
  3426. i++; idx++;
  3427. }
  3428. #else
  3429. printf ("ERROR: sym_print function not implemented in SAGE3! \n");
  3430. ROSE_ABORT();
  3431. #endif
  3432. }
  3433. else
  3434. {
  3435. os << "Pointer to symbol table is NULL \n";
  3436. }
  3437. }
  3438. void
  3439. SgSymbolTable::print( std::string label, VariantT nodeType )
  3440. {
  3441. printf ("Printing out the data within the symbol table (p_table = %p,label = %s size = %zu): \n",p_table,label.c_str(),size());
  3442. printf ("Internal static data: p_no_name: %s p_name = %s \n",(p_no_name == true) ? "true" : "false",p_name.str());
  3443. // These are just static data used internally for some of the symbol lookup functions (symbol tables are not given names).
  3444. // printf ("SymbolTable has a name: %s \n",(p_no_name == true) ? "NO: it has no name" : "YES: it does have a name");
  3445. // if (p_no_name == false)
  3446. // printf ("SymbolTable name = %s \n",p_name.str());
  3447. // DQ (2/16/2006): This is a SgScopeStatement except for the SgSymbolTable used in the global function type symbol table
  3448. // SgScopeStatement* parentNode = isSgScopeStatement(get_parent());
  3449. SgNode* parentNode = get_parent();
  3450. ROSE_ASSERT(parentNode != NULL);
  3451. printf ("Symbol table has parent = %p = %s \n",parentNode,parentNode->class_name().c_str());
  3452. // DQ (6/23/2005): It is not a problem for the global function table to not have a name!
  3453. // else
  3454. // ROSE_ASSERT (p_name.str() == NULL);
  3455. ROSE_ASSERT(p_table != NULL);
  3456. if (p_table != NULL)
  3457. {
  3458. // AJ (10/21/2004): Adjusted implementation to use new STL hash map interface
  3459. // SgSymbolHashBase::iterator i = p_table->begin();
  3460. hash_iterator i = p_table->begin();
  3461. int idx = 0;
  3462. while (i != p_table->end())
  3463. {
  3464. // DQ: removed SgName casting operator to char*
  3465. // cout << "[" << idx << "] " << (*i).first;
  3466. // cout << "[" << idx << "] " << (*i).first.str();
  3467. ROSE_ASSERT ( isSgSymbol( (*i).second ) != NULL );
  3468. // printf ("Symbol number: %d (pair.first (SgName) = %s) pair.second (SgSymbol) sage_class_name() = %s \n",
  3469. // idx,(*i).first.str(),(*i).second->sage_class_name());
  3470. SgSymbol* symbol = isSgSymbol((*i).second);
  3471. ROSE_ASSERT ( symbol != NULL );
  3472. SgType* type = symbol->get_type();
  3473. // DQ (5/7/2004): modified to allow for get_type() to return NULL
  3474. // ROSE_ASSERT ( type != NULL );
  3475. SgNamedType* namedType = isSgNamedType(type);
  3476. SgName nameOfType;
  3477. if (namedType != NULL)
  3478. {
  3479. nameOfType = namedType->get_name();
  3480. // char* nameString = namedType->get_name().str();
  3481. // printf ("Type is: (named type) = %s \n",nameString);
  3482. }
  3483. else
  3484. {
  3485. // DQ (5/7/2004): modified to allow for get_type() to return NULL
  3486. if (type != NULL)
  3487. {
  3488. // printf ("Type is: type->sage_class_name() = %s \n",type->sage_class_name());
  3489. nameOfType = type->sage_class_name();
  3490. }
  3491. else
  3492. {
  3493. // printf ("Type is: No type found in symbol (likely a possible error!) \n");
  3494. switch(symbol->variantT())
  3495. {
  3496. case V_SgNamespaceSymbol:
  3497. {
  3498. // This is a normal case where the type will be a null pointer!
  3499. nameOfType = "symbol's type is NULL (normal for SgNamespaceSymbol)";
  3500. break;
  3501. }
  3502. case V_SgTemplateSymbol:
  3503. {
  3504. // This is a normal case where the type will be a null pointer!
  3505. nameOfType = "symbol's type is NULL (normal for SgTemplateSymbol)";
  3506. break;
  3507. }
  3508. default:
  3509. {
  3510. // This is likely an error, I think
  3511. nameOfType = "unkown type name (likely a possible error!)";
  3512. break;
  3513. }
  3514. }
  3515. }
  3516. }
  3517. bool outputSymbolInfo = (nodeType == V_SgSymbol) || (symbol->variantT() == nodeType);
  3518. // Output of symbol information
  3519. SgNode* symbolBasis = i->second->get_symbol_basis();
  3520. if (symbolBasis != NULL)
  3521. {
  3522. ROSE_ASSERT(symbolBasis != NULL);
  3523. if (outputSymbolInfo == true)
  3524. {
  3525. printf ("Symbol %4d: name = %s SgSymbol = %p = %s type = %p = %s = %s get_symbol_basis() = %p = %s = %s \n",
  3526. idx,(*i).first.str(),(*i).second,(*i).second->class_name().c_str(),type,(type != NULL) ? type->class_name().c_str() : "NULL" ,
  3527. nameOfType.str(),symbolBasis,symbolBasis->class_name().c_str(),SageInterface::get_name(symbolBasis).c_str());
  3528. }
  3529. }
  3530. else
  3531. {
  3532. if (outputSymbolInfo == true)
  3533. {
  3534. printf ("Warning Symbol %4d: name = %s SgSymbol = %p = %s type = %p = %s = %s get_symbol_basis() = NULL \n",
  3535. idx,(*i).first.str(),(*i).second,(*i).second->class_name().c_str(),type,(type != NULL) ? type->class_name().c_str() : "NULL" ,
  3536. nameOfType.str());
  3537. }
  3538. }
  3539. SgName mangledName;
  3540. SgSymbol* symbolFromTable = (*i).second;
  3541. ROSE_ASSERT(symbolFromTable != NULL);
  3542. switch(symbolFromTable->variantT())
  3543. {
  3544. case V_SgFunctionSymbol:
  3545. {
  3546. SgFunctionSymbol* symbol = isSgFunctionSymbol(symbolFromTable);
  3547. ROSE_ASSERT(symbol != NULL);
  3548. SgFunctionDeclaration* functionDeclaration = symbol->get_declaration();
  3549. mangledName = functionDeclaration->get_mangled_name();
  3550. break;
  3551. }
  3552. case V_SgMemberFunctionSymbol:
  3553. {
  3554. SgMemberFunctionSymbol* symbol = isSgMemberFunctionSymbol(symbolFromTable);
  3555. ROSE_ASSERT(symbol != NULL);
  3556. SgFunctionDeclaration* functionDeclaration = symbol->get_declaration();
  3557. mangledName = functionDeclaration->get_mangled_name();
  3558. break;
  3559. }
  3560. case V_SgClassSymbol:
  3561. {
  3562. SgClassSymbol* symbol = isSgClassSymbol(symbolFromTable);
  3563. ROSE_ASSERT(symbol != NULL);
  3564. SgClassDeclaration* classDeclaration = symbol->get_declaration();
  3565. mangledName = classDeclaration->get_mangled_name();
  3566. break;
  3567. }
  3568. case V_SgEnumFieldSymbol:
  3569. {
  3570. SgEnumFieldSymbol* symbol = isSgEnumFieldSymbol(symbolFromTable);
  3571. ROSE_ASSERT(symbol != NULL);
  3572. SgInitializedName* enumFieldName = symbol->get_declaration();
  3573. mangledName = enumFieldName->get_mangled_name();
  3574. break;
  3575. }
  3576. case V_SgEnumSymbol:
  3577. {
  3578. SgEnumSymbol* symbol = isSgEnumSymbol(symbolFromTable);
  3579. ROSE_ASSERT(symbol != NULL);
  3580. SgEnumDeclaration* enumDeclaration = symbol->get_declaration();
  3581. mangledName = enumDeclaration->get_mangled_name();
  3582. break;
  3583. }
  3584. case V_SgFunctionTypeSymbol:
  3585. {
  3586. SgFunctionTypeSymbol* symbol = isSgFunctionTypeSymbol(symbolFromTable);
  3587. ROSE_ASSERT(symbol != NULL);
  3588. mangledName = symbol->get_name();
  3589. printf ("A SgFunctionTypeSymbol also has a pointer to a SgType = %p \n",symbol->get_type());
  3590. break;
  3591. }
  3592. case V_SgLabelSymbol:
  3593. {
  3594. SgLabelSymbol* symbol = isSgLabelSymbol(symbolFromTable);
  3595. ROSE_ASSERT(symbol != NULL);
  3596. SgLabelStatement* labelStatement = symbol->get_declaration();
  3597. mangledName = labelStatement->get_label();
  3598. break;
  3599. }
  3600. case V_SgNamespaceSymbol:
  3601. {
  3602. SgNamespaceSymbol* symbol = isSgNamespaceSymbol(symbolFromTable);
  3603. ROSE_ASSERT(symbol != NULL);
  3604. SgNamespaceDeclarationStatement* namespaceDeclaration = symbol->get_declaration();
  3605. mangledName = namespaceDeclaration->get_mangled_name();
  3606. printf ("A SgNamespaceSymbol also has a name = %s \n",symbol->get_name().str());
  3607. break;
  3608. }
  3609. case V_SgTemplateSymbol:
  3610. {
  3611. SgTemplateSymbol* symbol = isSgTemplateSymbol(symbolFromTable);
  3612. ROSE_ASSERT(symbol != NULL);
  3613. SgTemplateDeclaration* templateDeclaration = symbol->get_declaration();
  3614. mangledName = templateDeclaration->get_mangled_name();
  3615. break;
  3616. }
  3617. case V_SgTypedefSymbol:
  3618. {
  3619. SgTypedefSymbol* symbol = isSgTypedefSymbol(symbolFromTable);
  3620. ROSE_ASSERT(symbol != NULL);
  3621. SgTypedefDeclaration* typedefDeclaration = symbol->get_declaration();
  3622. mangledName = typedefDeclaration->get_mangled_name();
  3623. break;
  3624. }
  3625. case V_SgVariableSymbol:
  3626. {
  3627. SgVariableSymbol* symbol = isSgVariableSymbol(symbolFromTable);
  3628. ROSE_ASSERT(symbol != NULL);
  3629. SgInitializedName* initializedName = symbol->get_declaration();
  3630. mangledName = initializedName->get_mangled_name();
  3631. break;
  3632. }
  3633. default:
  3634. {
  3635. mangledName = "unknown mangled name";
  3636. printf ("Error: SgSymbol not handled (%s) \n",symbolFromTable->class_name().c_str());
  3637. // DQ (6/8/2007): Make this case fail so we can detect this error.
  3638. ROSE_ASSERT(false);
  3639. }
  3640. }
  3641. if (outputSymbolInfo == true)
  3642. {
  3643. printf (" Symbol's associated mangled name = %s \n",mangledName.str());
  3644. // This is useful for the output of the function types when the global function type symbol table is output.
  3645. // handle case of function symbol (unparse the funtion type)
  3646. SgFunctionTypeSymbol *f = isSgFunctionTypeSymbol((*i).second);
  3647. if (f != NULL)
  3648. {
  3649. #if 1
  3650. // f->get_type()->unparse(); cout << endl;
  3651. std::cout << " function: " << f->get_type()->unparseToString() << endl;
  3652. #else
  3653. // printf ("ERROR: unparse function for symbol type not implemented in SAGE3! \n");
  3654. // ROSE_ABORT();
  3655. #endif
  3656. }
  3657. }
  3658. // Increment the symbol table's symble iterator
  3659. i++;
  3660. // Increment the symbol counter (used for output)
  3661. idx++;
  3662. }
  3663. }
  3664. else
  3665. {
  3666. // DQ (6/27/2005): I think this is an error (we should always have a valid symbol table)
  3667. printf ("Pointer to symbol table is NULL \n");
  3668. ROSE_ASSERT(false);
  3669. }
  3670. }
  3671. set<SgNode*>
  3672. SgSymbolTable::get_symbols() const
  3673. {
  3674. // DQ (2/15/2007): generate a set of SgNode* so that we can use them for set difference against the delete list in AST merge.
  3675. set<SgNode*> returnSet;
  3676. ROSE_ASSERT(p_table != NULL);
  3677. hash_multimap<SgName, SgSymbol*, hash_Name, eqstr>::iterator i = get_table()->begin();
  3678. while (i != p_table->end())
  3679. {
  3680. ROSE_ASSERT(i->second != NULL);
  3681. returnSet.insert(i->second);
  3682. i++;
  3683. }
  3684. return returnSet;
  3685. }
  3686. // End of memberFunctionString
  3687. // Start of memberFunctionString
  3688. #line 331 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Common.code"
  3689. // *** COMMON CODE SECTION BEGINS HERE ***
  3690. int
  3691. SgSymbolTable::getVariant() const
  3692. {
  3693. // This function is used in ROSE while "variant()" is used in SAGE
  3694. assert(this != NULL);
  3695. return variant();
  3696. }
  3697. // This function is used in ROSE in treeTraversal code
  3698. // eventually replaces getVariant() and variant()
  3699. // though after variant() has been removed for a while we will
  3700. // want to change the name of variantT() back to variant()
  3701. // (since the "T" was ment to stand for temporary).
  3702. // When this happens the variantT() will be depricated.
  3703. VariantT
  3704. SgSymbolTable::variantT() const {
  3705. return V_SgSymbolTable;
  3706. }
  3707. #if 0
  3708. int
  3709. SgSymbolTable::variant() const
  3710. {
  3711. // This function is used in SAGE
  3712. assert(this != NULL);
  3713. return SymbolTableTag;
  3714. }
  3715. #endif
  3716. const char*
  3717. SgSymbolTable::sage_class_name() const
  3718. {
  3719. assert(this != NULL);
  3720. return "SgSymbolTable";
  3721. }
  3722. std::string
  3723. SgSymbolTable::class_name() const
  3724. {
  3725. assert(this != NULL);
  3726. return "SgSymbolTable";
  3727. }
  3728. // DQ (11/26/2005): Support for visitor pattern mechanims
  3729. // (inferior to ROSE traversal mechanism, experimental).
  3730. void
  3731. SgSymbolTable::executeVisitorMemberFunction (ROSE_VisitorPattern & visitor)
  3732. {
  3733. ROSE_ASSERT(this != NULL);
  3734. visitor.visit(this);
  3735. }
  3736. // *** COMMON CODE SECTION ENDS HERE ***
  3737. // End of memberFunctionString
  3738. // Start of memberFunctionString
  3739. #line 1387 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Node.code"
  3740. #if 0
  3741. //! Error checking support
  3742. /*! Verifies the following:
  3743. - working getVariant() member function
  3744. - calls base class's error() member function
  3745. Every class has one of these functions.
  3746. */
  3747. bool
  3748. SgSymbolTable::error()
  3749. {
  3750. // Put error checking here
  3751. ROSE_ASSERT (this != NULL);
  3752. if (getVariant() != SymbolTableTag)
  3753. {
  3754. printf ("Error in SgSymbolTable::error(): SgSymbolTable object has a %s variant \n",
  3755. Cxx_GrammarTerminalNames[getVariant()].name);
  3756. // printf ("Error in SgSymbolTable::error() \n");
  3757. ROSE_ABORT();
  3758. }
  3759. ROSE_ASSERT (getVariant() == SymbolTableTag);
  3760. return SgSupport::error();
  3761. }
  3762. #endif
  3763. // End of memberFunctionString
  3764. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarVariantFunctionDefinitionMacros.macro"
  3765. int
  3766. SgSymbolTable::variant() const
  3767. {
  3768. // This function is generated from grammarVariantFunctionDefinitionMacros.macro
  3769. #ifdef DEBUG
  3770. // printf ("In SgSymbolTable::variant() const \n");
  3771. #endif
  3772. assert(this != NULL);
  3773. return SymbolTableTag;
  3774. }
  3775. #line 1 ""
  3776. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarIsClassNameFunctionDefinitionMacros.macro"
  3777. SgSymbolTable* isSgSymbolTable ( SgNode* inputDerivedClassPointer )
  3778. {
  3779. return dynamic_cast<SgSymbolTable*>(inputDerivedClassPointer);
  3780. }
  3781. // DQ (11/8/2003): Added version of functions taking const pointer
  3782. const SgSymbolTable* isSgSymbolTable ( const SgNode* inputDerivedClassPointer )
  3783. {
  3784. return dynamic_cast<const SgSymbolTable*>(inputDerivedClassPointer);
  3785. }
  3786. #line 1 ""
  3787. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  3788. /**
  3789. \brief Generated destructor
  3790. This destructor is automatically generated (by ROSETTA). This destructor
  3791. only frees memory of data members associated with the parts of the current IR node which
  3792. are NOT traversed. Those data members that are part of a traversal can be freed using
  3793. a traversal (calling this destructor on all children in a post-order traversal). Such
  3794. a traversal which deletes a whole AST is provided by DeleteSgTree(SgNode*).
  3795. \internal All IR nodes with data members specified using setDataPrototype() within ROSETTA
  3796. are specified as NO_DELETE is also specified as DEF_TRAVERSAL. Those marked as
  3797. NO_TRAVERSAL can be marked as NO_DELETE or DEF_DELETE.
  3798. \note All SgSymbol IR nodes are deleted when the symbol table is deleted. Currently most
  3799. SgType IR nodes are not deleted (since they are shared). Also, all STL lists of
  3800. pointers are not yet implemented to call delete on eash pointer in the container.
  3801. (This could be done by derivation from the STL containers to define containers that
  3802. automatically deleted their members.)
  3803. */
  3804. SgSymbolTable::~SgSymbolTable ()
  3805. {
  3806. #if 0
  3807. // debugging information!
  3808. printf ("In SgSymbolTable::~SgSymbolTable (destructor) \n");
  3809. #endif
  3810. #if 1
  3811. // DQ (6/25/2006): Commented out destructor body to allow the File I/O to work.
  3812. delete p_table;
  3813. // case: not a listType for name
  3814. p_name = ""; // non list case
  3815. // case: not a listType for no_name
  3816. p_no_name = false; // non list case
  3817. // case: not a listType for table
  3818. p_table = NULL; // non list case
  3819. #line 32 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  3820. #endif
  3821. }
  3822. #line 1 ""
  3823. #line 1 ""
  3824. #line 6 "../Grammar/grammarClassDefinitionMacros.macro after marker MEMBER_FUNCTION_DEFINITIONS"
  3825. #line 7 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  3826. // ********************************************************
  3827. // member functions common across all array grammar objects
  3828. // ********************************************************
  3829. #line 1 ""
  3830. #line 1 ""
  3831. #line 1 ""
  3832. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  3833. // ********************************************************
  3834. // member functions specific to each node in the grammar
  3835. // ********************************************************
  3836. #line 6 "../Grammar/grammarClassDefinitionMacros.macro before marker MEMBER_FUNCTION_DEFINITIONS"
  3837. #line 1 ""
  3838. #line 1 ""
  3839. // Start of memberFunctionString
  3840. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  3841. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  3842. Sg_File_Info*
  3843. SgInitializedName::get_startOfConstruct () const
  3844. {
  3845. assert (this != NULL);
  3846. return p_startOfConstruct;
  3847. }
  3848. void
  3849. SgInitializedName::set_startOfConstruct ( Sg_File_Info* startOfConstruct )
  3850. {
  3851. assert (this != NULL);
  3852. set_isModified(true);
  3853. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  3854. if (p_startOfConstruct != NULL && startOfConstruct != NULL && p_startOfConstruct != startOfConstruct)
  3855. {
  3856. printf ("Warning: startOfConstruct = %p overwriting valid pointer p_startOfConstruct = %p \n",startOfConstruct,p_startOfConstruct);
  3857. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  3858. printf ("Error fails assertion (p_startOfConstruct != NULL && startOfConstruct != NULL && p_startOfConstruct != startOfConstruct) is false\n");
  3859. ROSE_ASSERT(false);
  3860. #endif
  3861. }
  3862. #endif
  3863. p_startOfConstruct = startOfConstruct;
  3864. }
  3865. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  3866. // End of memberFunctionString
  3867. // Start of memberFunctionString
  3868. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  3869. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  3870. SgName
  3871. SgInitializedName::get_name () const
  3872. {
  3873. assert (this != NULL);
  3874. return p_name;
  3875. }
  3876. void
  3877. SgInitializedName::set_name ( SgName name )
  3878. {
  3879. assert (this != NULL);
  3880. set_isModified(true);
  3881. p_name = name;
  3882. }
  3883. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  3884. // End of memberFunctionString
  3885. // Start of memberFunctionString
  3886. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  3887. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  3888. SgType*
  3889. SgInitializedName::get_typeptr () const
  3890. {
  3891. assert (this != NULL);
  3892. return p_typeptr;
  3893. }
  3894. void
  3895. SgInitializedName::set_typeptr ( SgType* typeptr )
  3896. {
  3897. assert (this != NULL);
  3898. set_isModified(true);
  3899. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  3900. if (p_typeptr != NULL && typeptr != NULL && p_typeptr != typeptr)
  3901. {
  3902. printf ("Warning: typeptr = %p overwriting valid pointer p_typeptr = %p \n",typeptr,p_typeptr);
  3903. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  3904. printf ("Error fails assertion (p_typeptr != NULL && typeptr != NULL && p_typeptr != typeptr) is false\n");
  3905. ROSE_ASSERT(false);
  3906. #endif
  3907. }
  3908. #endif
  3909. p_typeptr = typeptr;
  3910. }
  3911. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  3912. // End of memberFunctionString
  3913. // Start of memberFunctionString
  3914. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  3915. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  3916. SgInitializer*
  3917. SgInitializedName::get_initptr () const
  3918. {
  3919. assert (this != NULL);
  3920. return p_initptr;
  3921. }
  3922. void
  3923. SgInitializedName::set_initptr ( SgInitializer* initptr )
  3924. {
  3925. assert (this != NULL);
  3926. set_isModified(true);
  3927. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  3928. if (p_initptr != NULL && initptr != NULL && p_initptr != initptr)
  3929. {
  3930. printf ("Warning: initptr = %p overwriting valid pointer p_initptr = %p \n",initptr,p_initptr);
  3931. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  3932. printf ("Error fails assertion (p_initptr != NULL && initptr != NULL && p_initptr != initptr) is false\n");
  3933. ROSE_ASSERT(false);
  3934. #endif
  3935. }
  3936. #endif
  3937. p_initptr = initptr;
  3938. }
  3939. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  3940. // End of memberFunctionString
  3941. // Start of memberFunctionString
  3942. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  3943. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  3944. SgInitializedName*
  3945. SgInitializedName::get_prev_decl_item () const
  3946. {
  3947. assert (this != NULL);
  3948. return p_prev_decl_item;
  3949. }
  3950. void
  3951. SgInitializedName::set_prev_decl_item ( SgInitializedName* prev_decl_item )
  3952. {
  3953. assert (this != NULL);
  3954. set_isModified(true);
  3955. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  3956. if (p_prev_decl_item != NULL && prev_decl_item != NULL && p_prev_decl_item != prev_decl_item)
  3957. {
  3958. printf ("Warning: prev_decl_item = %p overwriting valid pointer p_prev_decl_item = %p \n",prev_decl_item,p_prev_decl_item);
  3959. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  3960. printf ("Error fails assertion (p_prev_decl_item != NULL && prev_decl_item != NULL && p_prev_decl_item != prev_decl_item) is false\n");
  3961. ROSE_ASSERT(false);
  3962. #endif
  3963. }
  3964. #endif
  3965. p_prev_decl_item = prev_decl_item;
  3966. }
  3967. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  3968. // End of memberFunctionString
  3969. // Start of memberFunctionString
  3970. // End of memberFunctionString
  3971. // Start of memberFunctionString
  3972. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  3973. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  3974. SgDeclarationStatement*
  3975. SgInitializedName::get_declptr () const
  3976. {
  3977. assert (this != NULL);
  3978. return p_declptr;
  3979. }
  3980. void
  3981. SgInitializedName::set_declptr ( SgDeclarationStatement* declptr )
  3982. {
  3983. assert (this != NULL);
  3984. set_isModified(true);
  3985. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  3986. if (p_declptr != NULL && declptr != NULL && p_declptr != declptr)
  3987. {
  3988. printf ("Warning: declptr = %p overwriting valid pointer p_declptr = %p \n",declptr,p_declptr);
  3989. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  3990. printf ("Error fails assertion (p_declptr != NULL && declptr != NULL && p_declptr != declptr) is false\n");
  3991. ROSE_ASSERT(false);
  3992. #endif
  3993. }
  3994. #endif
  3995. p_declptr = declptr;
  3996. }
  3997. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  3998. // End of memberFunctionString
  3999. // Start of memberFunctionString
  4000. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  4001. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  4002. SgScopeStatement*
  4003. SgInitializedName::get_scope () const
  4004. {
  4005. assert (this != NULL);
  4006. return p_scope;
  4007. }
  4008. void
  4009. SgInitializedName::set_scope ( SgScopeStatement* scope )
  4010. {
  4011. assert (this != NULL);
  4012. set_isModified(true);
  4013. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  4014. if (p_scope != NULL && scope != NULL && p_scope != scope)
  4015. {
  4016. printf ("Warning: scope = %p overwriting valid pointer p_scope = %p \n",scope,p_scope);
  4017. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  4018. printf ("Error fails assertion (p_scope != NULL && scope != NULL && p_scope != scope) is false\n");
  4019. ROSE_ASSERT(false);
  4020. #endif
  4021. }
  4022. #endif
  4023. p_scope = scope;
  4024. }
  4025. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  4026. // End of memberFunctionString
  4027. // Start of memberFunctionString
  4028. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  4029. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  4030. SgInitializedName::preinitialization_enum
  4031. SgInitializedName::get_preinitialization () const
  4032. {
  4033. assert (this != NULL);
  4034. return p_preinitialization;
  4035. }
  4036. void
  4037. SgInitializedName::set_preinitialization ( SgInitializedName::preinitialization_enum preinitialization )
  4038. {
  4039. assert (this != NULL);
  4040. set_isModified(true);
  4041. p_preinitialization = preinitialization;
  4042. }
  4043. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  4044. // End of memberFunctionString
  4045. // Start of memberFunctionString
  4046. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  4047. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  4048. AstAttributeMechanism*
  4049. SgInitializedName::get_attributeMechanism () const
  4050. {
  4051. assert (this != NULL);
  4052. return p_attributeMechanism;
  4053. }
  4054. void
  4055. SgInitializedName::set_attributeMechanism ( AstAttributeMechanism* attributeMechanism )
  4056. {
  4057. assert (this != NULL);
  4058. set_isModified(true);
  4059. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  4060. if (p_attributeMechanism != NULL && attributeMechanism != NULL && p_attributeMechanism != attributeMechanism)
  4061. {
  4062. printf ("Warning: attributeMechanism = %p overwriting valid pointer p_attributeMechanism = %p \n",attributeMechanism,p_attributeMechanism);
  4063. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  4064. printf ("Error fails assertion (p_attributeMechanism != NULL && attributeMechanism != NULL && p_attributeMechanism != attributeMechanism) is false\n");
  4065. ROSE_ASSERT(false);
  4066. #endif
  4067. }
  4068. #endif
  4069. p_attributeMechanism = attributeMechanism;
  4070. }
  4071. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  4072. // End of memberFunctionString
  4073. // Start of memberFunctionString
  4074. #line 836 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Support.code"
  4075. #if 0
  4076. // DQ (4/10/2006): Removed in favor of implementation at SgNode using
  4077. // a pointer and the interface represented directly at the SgNode
  4078. AstAttributeMechanism &
  4079. SgInitializedName::attribute()
  4080. {
  4081. // DQ (1/2/2006): This function preserves as much of
  4082. // the syntax of attribute being a public data member.
  4083. if (p_attribute == NULL)
  4084. {
  4085. printf ("Error: p_attribute == NULL (node = %s) \n",class_name().c_str());
  4086. ROSE_ASSERT(false);
  4087. }
  4088. return *p_attribute;
  4089. }
  4090. #endif
  4091. void
  4092. SgInitializedName::addNewAttribute( std::string s, AstAttribute* a )
  4093. {
  4094. if (get_attributeMechanism() == NULL)
  4095. {
  4096. set_attributeMechanism( new AstAttributeMechanism() );
  4097. ROSE_ASSERT(get_attributeMechanism() != NULL);
  4098. }
  4099. get_attributeMechanism()->add(s,a);
  4100. }
  4101. void
  4102. SgInitializedName::setAttribute( std::string s, AstAttribute* a )
  4103. {
  4104. if (get_attributeMechanism() == NULL)
  4105. {
  4106. set_attributeMechanism( new AstAttributeMechanism() );
  4107. ROSE_ASSERT(get_attributeMechanism() != NULL);
  4108. }
  4109. get_attributeMechanism()->set(s,a);
  4110. }
  4111. AstAttribute*
  4112. SgInitializedName::getAttribute(std::string s) const
  4113. {
  4114. ROSE_ASSERT(get_attributeMechanism() != NULL);
  4115. AstAttribute* returnValue = get_attributeMechanism()->operator[](s);
  4116. ROSE_ASSERT(returnValue != NULL);
  4117. return returnValue;
  4118. }
  4119. void
  4120. SgInitializedName::updateAttribute( std::string s, AstAttribute* a )
  4121. {
  4122. // formerly called: replace
  4123. ROSE_ASSERT(get_attributeMechanism() != NULL);
  4124. get_attributeMechanism()->replace(s,a);
  4125. }
  4126. void
  4127. SgInitializedName::removeAttribute(std::string s)
  4128. {
  4129. ROSE_ASSERT(get_attributeMechanism() != NULL);
  4130. get_attributeMechanism()->remove(s);
  4131. // DQ (1/2/2006): If we have no more attributes then remove the attribute container
  4132. int remainingCount = numberOfAttributes();
  4133. // printf ("In AstTextAttributesHandling::visit(): remaining number of attributes = %d \n",remainingCount);
  4134. if (remainingCount == 0)
  4135. {
  4136. delete get_attributeMechanism();
  4137. set_attributeMechanism(NULL);
  4138. }
  4139. }
  4140. bool
  4141. SgInitializedName::attributeExists(std::string s) const
  4142. {
  4143. bool returnValue = false;
  4144. if (get_attributeMechanism() != NULL)
  4145. returnValue = get_attributeMechanism()->exists(s);
  4146. return returnValue;
  4147. }
  4148. int
  4149. SgInitializedName::numberOfAttributes() const
  4150. {
  4151. int returnValue = 0;
  4152. if (get_attributeMechanism() != NULL)
  4153. returnValue = get_attributeMechanism()->size();
  4154. return returnValue;
  4155. }
  4156. // End of memberFunctionString
  4157. // Start of memberFunctionString
  4158. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  4159. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  4160. SgInitializedName::asm_register_name_enum
  4161. SgInitializedName::get_register_name_code () const
  4162. {
  4163. assert (this != NULL);
  4164. return p_register_name_code;
  4165. }
  4166. void
  4167. SgInitializedName::set_register_name_code ( SgInitializedName::asm_register_name_enum register_name_code )
  4168. {
  4169. assert (this != NULL);
  4170. set_isModified(true);
  4171. p_register_name_code = register_name_code;
  4172. }
  4173. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  4174. // End of memberFunctionString
  4175. // Start of memberFunctionString
  4176. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  4177. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  4178. std::string
  4179. SgInitializedName::get_register_name_string () const
  4180. {
  4181. assert (this != NULL);
  4182. return p_register_name_string;
  4183. }
  4184. void
  4185. SgInitializedName::set_register_name_string ( std::string register_name_string )
  4186. {
  4187. assert (this != NULL);
  4188. set_isModified(true);
  4189. p_register_name_string = register_name_string;
  4190. }
  4191. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  4192. // End of memberFunctionString
  4193. // Start of memberFunctionString
  4194. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  4195. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  4196. bool
  4197. SgInitializedName::get_requiresGlobalNameQualificationOnType () const
  4198. {
  4199. assert (this != NULL);
  4200. return p_requiresGlobalNameQualificationOnType;
  4201. }
  4202. void
  4203. SgInitializedName::set_requiresGlobalNameQualificationOnType ( bool requiresGlobalNameQualificationOnType )
  4204. {
  4205. assert (this != NULL);
  4206. set_isModified(true);
  4207. p_requiresGlobalNameQualificationOnType = requiresGlobalNameQualificationOnType;
  4208. }
  4209. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  4210. // End of memberFunctionString
  4211. // Start of memberFunctionString
  4212. #line 6420 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Support.code"
  4213. // DQ (2/6/2007): Get the associated symbol from the symbol table in the stored scope
  4214. SgSymbol*
  4215. SgInitializedName::get_symbol_from_symbol_table() const
  4216. {
  4217. ROSE_ASSERT(get_scope() != NULL);
  4218. ROSE_ASSERT(get_scope()->get_symbol_table() != NULL);
  4219. return get_scope()->get_symbol_table()->find(this);
  4220. }
  4221. #if 0
  4222. SgInitializedName::~SgInitializedName()
  4223. {
  4224. /*delete p_ptr;*/
  4225. }
  4226. SgInitializedName::SgInitializedName()
  4227. : p_typeptr(0), p_initptr(0), p_declptr(0),
  4228. // p_itemptr(0), p_prev_itemptr(0),
  4229. p_is_initializer(1)
  4230. {
  4231. }
  4232. #endif
  4233. Sg_File_Info*
  4234. SgInitializedName::get_file_info() const
  4235. {
  4236. // This redefines get_file_info() as it is implemented for a SgLocatedNode
  4237. // to use the "get_startOfConstruct()" for consistancy with SgLocatedNode IR nodes.
  4238. return get_startOfConstruct();
  4239. }
  4240. void
  4241. SgInitializedName::set_file_info(Sg_File_Info* X)
  4242. {
  4243. // This redefines set_file_info() as it is implemented for a SgLocatedNode
  4244. // to use the "set_startOfConstruct()" for consistancy with SgLocatedNode IR nodes.
  4245. return set_startOfConstruct(X);
  4246. }
  4247. SgStorageModifier &
  4248. SgInitializedName::get_storageModifier()
  4249. {
  4250. ROSE_ASSERT (this != NULL);
  4251. ROSE_ASSERT (p_storageModifier != NULL);
  4252. return *p_storageModifier;
  4253. }
  4254. SgName
  4255. SgInitializedName::get_qualified_name() const
  4256. {
  4257. // DQ (8/22/2005): This function is similar to the one for SgClassDeclaration.
  4258. // This function calls get_scope() which uses the parent pointers, thus
  4259. // it should not be called before the parent pointers are set (within the AST fixup after
  4260. // the Sage III AST is fully constructed).
  4261. // printf ("In SgInitializedName::get_qualified_name() name = %s \n",get_name().str());
  4262. SgName returnName;
  4263. // The semantics of get_scope is that it can never be NULL (SgGlobal returns itself as its scope!)
  4264. SgScopeStatement* scope = get_scope();
  4265. ROSE_ASSERT(scope != NULL);
  4266. returnName = SgName::assembleQualifiedName(scope->get_qualified_name(),get_name());
  4267. // printf ("In SgInitializedName::get_qualified_name() returnName = %s \n",returnName.str());
  4268. return returnName;
  4269. }
  4270. void
  4271. SgInitializedName::post_construction_initialization()
  4272. {
  4273. // printf ("In SgInitializedName::post_construction_initialization() this = %p \n",this);
  4274. p_storageModifier = new SgStorageModifier();
  4275. ROSE_ASSERT (p_storageModifier != NULL);
  4276. p_storageModifier->setDefault();
  4277. // DQ (6/20/2006): Set the parent of the SgStorageModifier
  4278. p_storageModifier->set_parent(this);
  4279. // DQ (4/10/2006): Removed in favor of implementation at SgNode using
  4280. // a pointer and the interface represented directly at the SgNode
  4281. // DQ (1/17/2006): Added initialization to prevent valgrind warning.
  4282. p_attributeMechanism = NULL;
  4283. // DQ (11/19/2004): Added to support explicit scopes for variables within variable declarations.
  4284. p_scope = NULL;
  4285. // DQ (12/17/2006): Added semantics that constructors (which are structural) should set the parents of their inputs.
  4286. if (p_initptr != NULL)
  4287. {
  4288. // printf ("In SgInitializedName::post_construction_initialization(): resetting parent of valid initializer (p_initptr = %p) \n",p_initptr);
  4289. p_initptr->set_parent(this);
  4290. }
  4291. }
  4292. // This constructor is specific to the creation of SgInitializedName objects used as initializers
  4293. SgInitializedName::SgInitializedName
  4294. ( const SgName& name, SgType *typeptr, SgInitializer* iptr,
  4295. SgDeclarationStatement *declptr,
  4296. // QY:11/2/04 remove itemptr
  4297. // SgInitializedName *itemptr,
  4298. SgInitializedName *prev_itemptr ) ROSE_DEPRECATED_FUNCTION
  4299. // DQ (1/18/2006): name change to make consistant with virtual SgNode::get_file_info()
  4300. // DQ (11/20/2004): Reodered elements of pre-initialization list to avoid compiler warnings
  4301. // : p_file_info(NULL), // Note that file_info is a new data member and is set explicitly after construction
  4302. : p_startOfConstruct(NULL), // Note that file_info is a new data member and is set explicitly after construction
  4303. p_name(name),
  4304. p_typeptr(typeptr),
  4305. // p_itemptr(itemptr), Removed constructor parameter list
  4306. p_initptr(iptr),
  4307. p_prev_decl_item(prev_itemptr),
  4308. p_is_initializer(true),
  4309. // DQ (6/18/2006): declptr was not being used to set the internal p_declptr data member.
  4310. // p_declptr(NULL),
  4311. p_declptr(declptr),
  4312. // DQ (11/20/2004): Added additional initialization of remaining data members
  4313. p_storageModifier(NULL),
  4314. p_scope(NULL),
  4315. // DQ (3/1/2005): Added to avoid valgrind warning about uninitialized use
  4316. p_preinitialization(e_unknown_preinitialization),
  4317. // DQ (4/10/2006): Removed in favor of implementation at SgNode using
  4318. // a pointer and the interface represented directly at the SgNode
  4319. // DQ (1/17/2006): Moved attribute mechanism to specific IR nodes (Added initialization to prevent valgrind warning)
  4320. p_attributeMechanism(NULL),
  4321. // DQ (7/31/2006): Added support for asm declarations on variables (using GNU register codes)
  4322. p_register_name_code(SgInitializedName::e_invalid_register),
  4323. // DQ (8/9/2006): Added support for asm declarations on variables (using strings)
  4324. p_register_name_string(""),
  4325. // DQ (10/10/2007): Added support for initialization of this data member (reported as uninitialized by valgrind).
  4326. p_requiresGlobalNameQualificationOnType(false)
  4327. {
  4328. post_construction_initialization();
  4329. }
  4330. // DQ (8/4/2006): This constructor adds the newer fileInfo data member to the constructor parameter list.
  4331. // We might soon depricate the older constructor.
  4332. SgInitializedName::SgInitializedName
  4333. ( Sg_File_Info* fileInfo, const SgName& name, SgType *typeptr, SgInitializer* iptr,
  4334. SgDeclarationStatement *declptr, SgScopeStatement* scope, SgInitializedName *prev_itemptr )
  4335. // : p_file_info(fileInfo), // Note that file_info is a new data member and is set explicitly after construction
  4336. : p_startOfConstruct(fileInfo), // Note that file_info is a new data member and is set explicitly after construction
  4337. p_name(name),
  4338. p_typeptr(typeptr),
  4339. p_initptr(iptr),
  4340. p_prev_decl_item(prev_itemptr),
  4341. p_is_initializer(true),
  4342. p_declptr(declptr),
  4343. p_storageModifier(NULL),
  4344. p_scope(NULL),
  4345. p_preinitialization(e_unknown_preinitialization),
  4346. p_attributeMechanism(NULL),
  4347. p_register_name_code(SgInitializedName::e_invalid_register),
  4348. p_register_name_string(""),
  4349. // DQ (10/10/2007): Added support for initialization of this data member (reported as uninitialized by valgrind).
  4350. p_requiresGlobalNameQualificationOnType(false)
  4351. {
  4352. post_construction_initialization();
  4353. }
  4354. SgInitializedName::SgInitializedName (const SgInitializedName& ptr)
  4355. {
  4356. p_name = ptr.p_name;
  4357. p_typeptr = ptr.p_typeptr;
  4358. p_initptr = ptr.p_initptr;
  4359. // DQ (12/17/2006): Added semantics that constructors (which are structural) should set the parents of their inputs.
  4360. if (p_initptr != NULL)
  4361. {
  4362. printf ("In SgInitializedName constructor: resetting parent of valid initializer (p_initptr = %p) (likely sharing violation in copy constructor) \n",p_initptr);
  4363. p_initptr->set_parent(this);
  4364. }
  4365. // p_prev_itemptr = ptr.p_prev_itemptr;
  4366. p_is_initializer = ptr.p_is_initializer;
  4367. p_declptr = ptr.p_declptr;
  4368. // p_itemptr = ptr.p_itemptr;
  4369. // DQ (1/18/2006): Avoid reusing Sg_File_Info objects
  4370. // p_fileInfo = ptr.p_fileInfo;
  4371. // p_file_info = (ptr.p_file_info != NULL) ? new Sg_File_Info(*ptr.p_file_info) : NULL;
  4372. // DQ (12/17/2006): See if we can enforce this!
  4373. // p_startOfConstruct = (ptr.p_startOfConstruct != NULL) ? new Sg_File_Info(*ptr.p_startOfConstruct) : NULL;
  4374. ROSE_ASSERT(ptr.p_startOfConstruct != NULL);
  4375. p_startOfConstruct = new Sg_File_Info(*ptr.p_startOfConstruct);
  4376. ROSE_ASSERT(p_startOfConstruct != NULL);
  4377. // DQ (12/17/2006): Fixup the parent of the new or borrowed Sg_File_Info object.
  4378. p_startOfConstruct->set_parent(this);
  4379. // DQ (11/19/2004): Added to support explicit scopes for variables within variable declarations.
  4380. p_scope = ptr.p_scope;
  4381. // DQ (3/1/2005): Added to avoid valgrind warning about uninitialized use
  4382. p_preinitialization = ptr.p_preinitialization;
  4383. // DQ (4/28/2004): Added storage modifier support (replacing the old interface)
  4384. ROSE_ASSERT (ptr.p_storageModifier != NULL);
  4385. p_storageModifier = new SgStorageModifier ( *(ptr.p_storageModifier) );
  4386. ROSE_ASSERT (p_storageModifier != NULL);
  4387. // DQ (6/20/2006): Set the parent of the SgStorageModifier
  4388. p_storageModifier->set_parent(this);
  4389. // DQ (4/10/2006): Removed in favor of implementation at SgNode using
  4390. // a pointer and the interface represented directly at the SgNode
  4391. // DQ (1/17/2006): Moved attribute mechanism to specific IR nodes
  4392. p_attributeMechanism = NULL;
  4393. // DQ (7/31/2006): Added support for asm declarations on variables (using GNU register codes)
  4394. p_register_name_code = SgInitializedName::e_invalid_register;
  4395. // DQ (8/9/2006): Added support for asm declarations on variables (using strings)
  4396. // Note: don't copy the register string (I think this is best, but it is debatable)
  4397. p_register_name_string = "";
  4398. // DQ (10/10/2007): Added support for initialization of this data member (reported as uninitialized by valgrind).
  4399. p_requiresGlobalNameQualificationOnType = ptr.p_requiresGlobalNameQualificationOnType;
  4400. }
  4401. SgInitializedName&
  4402. SgInitializedName::operator= (const SgInitializedName& ptr)
  4403. {
  4404. ROSE_ASSERT(this != NULL);
  4405. /* check they are not the same name */
  4406. if (this != &ptr)
  4407. {
  4408. p_name = ptr.p_name;
  4409. p_typeptr = ptr.p_typeptr;
  4410. p_initptr = ptr.p_initptr;
  4411. // DQ (12/17/2006): Added semantics that constructors (which are structural) should set the parents of their inputs.
  4412. if (p_initptr != NULL)
  4413. {
  4414. // printf ("In SgInitializedName constructor: resetting parent of valid initializer (p_initptr = %p) (likely sharing violation in operator=) \n",p_initptr);
  4415. #if 0
  4416. // DQ (12/22/2006): Don't allow the parent of the input SgInitializedName to be modified, but make sure that it is set!
  4417. // p_initptr->set_parent(this);
  4418. if (p_initptr->get_parent() == NULL)
  4419. {
  4420. p_initptr->set_parent(this);
  4421. }
  4422. #else
  4423. // DQ (12/22/2006): Interestingly, the inliner is dependent upon this working this way! We should maybe look into this later.
  4424. p_initptr->set_parent(this);
  4425. #endif
  4426. ROSE_ASSERT(p_initptr->get_parent() != NULL);
  4427. // printf ("Exiting as a test! operator= \n");
  4428. // ROSE_ASSERT(false);
  4429. }
  4430. // p_prev_itemptr = ptr.p_prev_itemptr;
  4431. p_is_initializer = ptr.p_is_initializer;
  4432. p_declptr = ptr.p_declptr;
  4433. // p_itemptr = ptr.p_itemptr;
  4434. // DQ (1/18/2006): Avoid reusing Sg_File_Info objects
  4435. // p_fileInfo = ptr.p_fileInfo;
  4436. // DQ (6/23/2006): Added assertion to detect errors
  4437. // ROSE_ASSERT(ptr.p_file_info != NULL);
  4438. // p_file_info = (ptr.p_file_info != NULL) ? new Sg_File_Info(*ptr.p_file_info) : NULL;
  4439. // ROSE_ASSERT(p_file_info != NULL);
  4440. ROSE_ASSERT(ptr.p_startOfConstruct != NULL);
  4441. // p_startOfConstruct = (ptr.p_startOfConstruct != NULL) ? new Sg_File_Info(*ptr.p_startOfConstruct) : NULL;
  4442. p_startOfConstruct = new Sg_File_Info(*ptr.p_startOfConstruct);
  4443. ROSE_ASSERT(p_startOfConstruct != NULL);
  4444. // DQ (12/17/2006): Fixup the parent of the new or borrowed Sg_File_Info object.
  4445. p_startOfConstruct->set_parent(this);
  4446. // DQ (11/19/2004): Added to support explicit scopes for variables within variable declarations.
  4447. p_scope = ptr.p_scope;
  4448. // DQ (3/1/2005): Added to avoid valgrind warning about uninitialized use
  4449. p_preinitialization = ptr.p_preinitialization;
  4450. ROSE_ASSERT (p_storageModifier != NULL);
  4451. *p_storageModifier = *(ptr.p_storageModifier);
  4452. // DQ (4/10/2006): Removed in favor of implementation at SgNode using
  4453. // a pointer and the interface represented directly at the SgNode
  4454. // DQ (1/17/2006): Moved attribute mechanism to specific IR nodes
  4455. p_attributeMechanism = NULL;
  4456. // DQ (7/31/2006): Added support for asm declarations on variables
  4457. p_register_name_code = ptr.p_register_name_code;
  4458. // DQ (7/31/2006): Added support for asm declarations on variables
  4459. p_register_name_string = ptr.p_register_name_string;
  4460. // DQ (10/10/2007): Added support for initialization of this data member (reported as uninitialized by valgrind).
  4461. p_requiresGlobalNameQualificationOnType = ptr.p_requiresGlobalNameQualificationOnType;
  4462. }
  4463. else
  4464. {
  4465. // DQ (6/23/2006): Added debugging message to track this issue.
  4466. printf ("SgInitializedName::operator=(): Attempt to copy self to self \n");
  4467. }
  4468. // ROSE_ASSERT(p_file_info != NULL);
  4469. ROSE_ASSERT(p_startOfConstruct != NULL);
  4470. return *this;
  4471. }
  4472. bool
  4473. SgInitializedName::operator== (const SgInitializedName& ) const
  4474. { return false; }
  4475. bool
  4476. SgInitializedName::operator< (const SgInitializedName&) const
  4477. { return false; }
  4478. #if 0
  4479. // DQ (10/9/2007): Use the ROSETTA generated version to test failure
  4480. // DQ (12/9/2004): This is how an automatically generated function!
  4481. SgName
  4482. SgInitializedName::get_name() const
  4483. {
  4484. assert (this != NULL);
  4485. return p_name;
  4486. }
  4487. #endif
  4488. #if 0
  4489. void
  4490. SgInitializedName::set_name ( SgName name )
  4491. {
  4492. assert (this != NULL);
  4493. p_name = name;
  4494. }
  4495. #endif
  4496. #if 0
  4497. // DQ (10/9/2007): Use the ROSETTA generated version to test failure
  4498. // DQ (10/5/2007): This was a mistake to comment out, we want this functionality. It is likely that
  4499. // similar function ality should be provided for all other names declarations that generate symbols
  4500. // for the symbol table.
  4501. // DQ (12/9/2004): This is now an automatically generated function!
  4502. // AJ (10/21/2004): Added support for changing the symbol name associated with an SgInitializedName
  4503. // by updating the symbol table
  4504. int
  4505. SgInitializedName::set_name(SgName new_name)
  4506. {
  4507. // This function could likely be simpler now that we have better symbol table support.
  4508. set_isModified(true);
  4509. // find the appropriate symbol table.
  4510. SgNode * node = this;
  4511. // DQ (12/9/2004): This should likely call the get_scope function (which is more robust than traversing
  4512. // parents, there is a reason why we are forced to include the scope explicitly on some IR nodes,
  4513. // see test2004_133.C for details).
  4514. while((node!=NULL) && ( isSgScopeStatement(node)==NULL))
  4515. node = node->get_parent();
  4516. ROSE_ASSERT(node!=NULL);
  4517. SgScopeStatement * scope_stmt = isSgScopeStatement(node);
  4518. ROSE_ASSERT(scope_stmt != NULL);
  4519. ROSE_ASSERT(scope_stmt->get_symbol_table() != NULL);
  4520. ROSE_ASSERT(scope_stmt->get_symbol_table()->get_table() != NULL);
  4521. SgDeclarationStatement * parent_declaration = get_declaration();
  4522. ROSE_ASSERT(parent_declaration != NULL);
  4523. // Find the symbols associated with p_name
  4524. std::pair<SgSymbolTable::hash_iterator,SgSymbolTable::hash_iterator> pair_it =
  4525. scope_stmt->get_symbol_table()->get_table()->equal_range(p_name);
  4526. SgSymbolTable::hash_iterator found_it=scope_stmt->get_symbol_table()->get_table()->end();
  4527. for(SgSymbolTable::hash_iterator it = pair_it.first; it != pair_it.second; ++it)
  4528. {
  4529. switch(parent_declaration->getVariant())
  4530. {
  4531. case V_SgVariableDeclaration:
  4532. {
  4533. if (isSgVariableSymbol((*it).second)!=NULL)
  4534. found_it = it;
  4535. break;
  4536. }
  4537. case V_SgClassDeclaration:
  4538. {
  4539. if (isSgClassSymbol((*it).second)!=NULL)
  4540. found_it = it;
  4541. break;
  4542. }
  4543. case V_SgFunctionDeclaration:
  4544. {
  4545. if (isSgFunctionSymbol((*it).second)!=NULL)
  4546. found_it = it;
  4547. break;
  4548. }
  4549. default:
  4550. {
  4551. }
  4552. };
  4553. }
  4554. // there is no Variable,Class or Function symbol associated with p_name
  4555. if (found_it == scope_stmt->get_symbol_table()->get_table()->end())
  4556. {
  4557. printf ("Warning: There is no Variable,Class or Function symbol associated with p_name \n");
  4558. return 0;
  4559. }
  4560. SgSymbol * associated_symbol = (*found_it).second;
  4561. // erase the name from there
  4562. scope_stmt->get_symbol_table()->get_table()->erase(found_it);
  4563. // insert the new_name in the symbol table
  4564. found_it = scope_stmt->get_symbol_table()->get_table()->insert(pair<SgName,SgSymbol*> ( new_name,associated_symbol));
  4565. // if insertion failed
  4566. if (found_it == scope_stmt->get_symbol_table()->get_table()->end())
  4567. {
  4568. printf ("Warning: insertion of new symbol failed \n");
  4569. return 0;
  4570. }
  4571. // Set the p_name to the new_name
  4572. printf ("Reset p_name = %s to new_name = %s \n",p_name.str(),new_name.str());
  4573. p_name = new_name;
  4574. // Invalidate the p_iterator, p_no_name and p_name data members in the Symbol table
  4575. return 1;
  4576. }
  4577. #endif
  4578. SgType*
  4579. SgInitializedName::get_type() const
  4580. {
  4581. ROSE_ASSERT(this != NULL);
  4582. return p_typeptr;
  4583. }
  4584. void
  4585. SgInitializedName::set_type(SgType *t)
  4586. {
  4587. ROSE_ASSERT(this != NULL);
  4588. p_typeptr = t;
  4589. }
  4590. SgInitializer*
  4591. SgInitializedName::get_initializer() const
  4592. {
  4593. // DQ (12/17/2006): These should be able to be generated by ROSETTA!
  4594. // The semantics of p_is_initializer appears to not be required.
  4595. ROSE_ASSERT(this != NULL);
  4596. if (p_is_initializer)
  4597. return p_initptr;
  4598. else
  4599. return NULL;
  4600. }
  4601. void
  4602. SgInitializedName::set_initializer(SgInitializer* i)
  4603. {
  4604. // DQ (12/17/2006): These should be able to be generated by ROSETTA!
  4605. // The semantics of p_is_initializer appears to not be required.
  4606. ROSE_ASSERT(this != NULL);
  4607. p_initptr = i;
  4608. p_is_initializer = 1;
  4609. }
  4610. #if 0
  4611. // DQ (2/18/2006): Added general name mangling for all declarations (and some other IR nodes).
  4612. SgName
  4613. SgInitializedName::get_mangled_name(void) const
  4614. {
  4615. // printf ("In SgInitializedName::get_mangled_name() name = %s \n",get_name().str());
  4616. SgName returnName;
  4617. // The semantics of get_scope is that it can never be NULL (SgGlobal returns itself as its scope!)
  4618. SgScopeStatement* scope = get_scope();
  4619. ROSE_ASSERT(scope != NULL);
  4620. SgName mangleScopeName;
  4621. switch (scope->variantT())
  4622. {
  4623. // These are all of the SgDefinitionStatement IR nodes for which a mangled name can be generated
  4624. case V_SgFunctionDefinition:
  4625. {
  4626. SgFunctionDefinition* functionDefinition = isSgFunctionDefinition(scope);
  4627. ROSE_ASSERT(functionDefinition != NULL);
  4628. mangleScopeName = functionDefinition->get_mangled_name();
  4629. break;
  4630. }
  4631. case V_SgNamespaceDefinitionStatement:
  4632. {
  4633. SgNamespaceDefinitionStatement* namespaceDefinition = isSgNamespaceDefinitionStatement(scope);
  4634. ROSE_ASSERT(namespaceDefinition != NULL);
  4635. mangleScopeName = namespaceDefinition->get_mangled_name();
  4636. break;
  4637. }
  4638. case V_SgClassDefinition:
  4639. {
  4640. SgClassDefinition* classDefinition = isSgClassDefinition(scope);
  4641. ROSE_ASSERT(classDefinition != NULL);
  4642. mangleScopeName = classDefinition->get_mangled_name();
  4643. break;
  4644. }
  4645. default:
  4646. {
  4647. // Nothing to do here!
  4648. // This permits error checking, is it a good idea?
  4649. // ROSE_ASSERT(scope->hasMangledName() == false);
  4650. }
  4651. }
  4652. // DQ (2/18/2006): Not sure if adding "_variable_" really helps
  4653. returnName = mangleScopeName + SgName("_variable_") + get_name();
  4654. // printf ("In SgInitializedName::get_qualified_name() returnName = %s \n",returnName.str());
  4655. return returnName;
  4656. }
  4657. #endif
  4658. #if 0
  4659. // DQ (3/31/2006): Commented out this older version (replaced with newer version).
  4660. SgName
  4661. SgInitializedName::get_mangled_name (void) const
  4662. {
  4663. SgName mangled_name; // return value
  4664. SgName name = get_name ();
  4665. SgScopeStatement* scope = get_scope ();
  4666. ROSE_ASSERT (scope);
  4667. if (name.get_length ()) // not empty
  4668. {
  4669. SgName qual_name = mangleQualifiers (scope);
  4670. mangled_name = joinMangledQualifiers (qual_name, get_name ());
  4671. }
  4672. else // name is empty -- may be an anonymous (unnamed) function arg
  4673. {
  4674. const SgFunctionDefinition* func_def = isSgFunctionDefinition (scope);
  4675. const SgFunctionParameterList* func_params =
  4676. isSgFunctionParameterList (get_declaration ());
  4677. if (func_def && func_params)
  4678. {
  4679. const SgInitializedNamePtrList& func_args = func_params->get_args ();
  4680. // Find position (parameter number) in parameter list
  4681. SgInitializedNamePtrList::const_iterator i;
  4682. size_t param_num = 0;
  4683. for (i = func_args.begin (); i != func_args.end (); ++i)
  4684. {
  4685. param_num++;
  4686. if ((*i) == this)
  4687. break;
  4688. }
  4689. if (i != func_args.end ()) // found position
  4690. {
  4691. ostringstream s;
  4692. s << func_def->get_mangled_name ().str ()
  4693. << "__ARG" << param_num;
  4694. mangled_name = SgName (s.str ());
  4695. }
  4696. }
  4697. }
  4698. if (!mangled_name.get_length ()) // Could not come up with a name?
  4699. {
  4700. printf ("Error in SgInitializedName::get_mangled_name(void): zero length mangled name generated (see if this is realistic) \n");
  4701. ROSE_ASSERT(false);
  4702. // Default: Use pointer value to at least get a unique name
  4703. ostringstream s;
  4704. s << class_name () << "__" << (void *)(this);
  4705. mangled_name = SgName (s.str ().c_str ());
  4706. }
  4707. return mangled_name;
  4708. }
  4709. #endif
  4710. // DQ (3/31/2006): New version from Rich (fixes bug where empty mangled name was generated)
  4711. SgName
  4712. SgInitializedName::get_mangled_name (void) const
  4713. {
  4714. SgName mangled_name; // return value
  4715. // Case 1: Function parameters.
  4716. // Generate names for parameters such that
  4717. // int foo (int x, int y) { return x + y; }
  4718. // int foo (int, int);
  4719. // int foo (int a, int b);
  4720. // all generate the same unique names for equivalent parameters.
  4721. const SgFunctionParameterList* func_params = isSgFunctionParameterList (get_declaration ());
  4722. if (func_params)
  4723. {
  4724. // Find position (parameter number) in parameter list
  4725. const SgInitializedNamePtrList& func_args = func_params->get_args ();
  4726. SgInitializedNamePtrList::const_iterator i;
  4727. size_t param_num = 0;
  4728. for (i = func_args.begin (); i != func_args.end () && *i != this; ++i)
  4729. param_num++;
  4730. if (i != func_args.end ()) // found position
  4731. {
  4732. // Compute a mangled prefix from the function declaration.
  4733. ostringstream s;
  4734. const SgFunctionDeclaration* func_decl = isSgFunctionDeclaration (func_params->get_parent ());
  4735. if (func_decl)
  4736. s << func_decl->get_mangled_name ().str ();
  4737. s << "__ARG" << param_num+1; // Append argument number (1-based)
  4738. mangled_name = SgName (s.str ());
  4739. }
  4740. // else, an error (see below).
  4741. }
  4742. else // Case 2: Not a function parameter
  4743. {
  4744. SgScopeStatement* scope = get_scope ();
  4745. if (scope == NULL)
  4746. {
  4747. printf ("SgInitializedName = %p = %s \n",this,get_name().str());
  4748. get_file_info()->display("Error scope of SgInitializedName == NULL");
  4749. }
  4750. ROSE_ASSERT (scope != NULL);
  4751. SgName qual_name = mangleQualifiers (scope);
  4752. SgName name = get_name();
  4753. if (name.get_length() > 0) // not empty
  4754. {
  4755. mangled_name = joinMangledQualifiers (qual_name, get_name ());
  4756. }
  4757. else
  4758. {
  4759. // name is empty
  4760. if (isSgCatchOptionStmt (scope)) // e.g., 'try {...} catch (int) {...}
  4761. {
  4762. mangled_name = joinMangledQualifiers (qual_name, SgName ("CATCHARG"));
  4763. }
  4764. else
  4765. {
  4766. // printf ("Must be a padding declaration (e.g. int:16) \n");
  4767. mangled_name = joinMangledQualifiers (qual_name, SgName ("PADDING_VARIABLE"));
  4768. }
  4769. }
  4770. }
  4771. if (!mangled_name.get_length ()) // Error: could not come up with a name.
  4772. {
  4773. printf ("Error in SgInitializedName::get_mangled_name(void): zero length mangled name generated (see if this is realistic)\n");
  4774. SgScopeStatement* scope = get_scope ();
  4775. ROSE_ASSERT (scope);
  4776. printf (" Surrounding scope is '%s'\n", scope->sage_class_name ());
  4777. const SgDeclarationStatement* decl = get_declaration ();
  4778. printf (" Decl is '%s'\n", decl ? decl->sage_class_name () : "(none)");
  4779. const SgDeclarationStatement* def = get_definition ();
  4780. printf (" Def is '%s'\n", def ? def->sage_class_name () : "(none)");
  4781. const SgNode* par = decl ? decl->get_parent () : 0;
  4782. printf (" Parent(decl) is '%s'\n", par ? par->sage_class_name () : "(none)");
  4783. // DQ (2/21/2007): I think this is OK for un-named function parameters, leave as a warning for now!.
  4784. // ROSE_ASSERT(false);
  4785. }
  4786. return mangled_name;
  4787. }
  4788. // QY 11/3/04
  4789. SgDeclarationStatement*
  4790. SgInitializedName::get_declaration() const
  4791. {
  4792. // DQ (6/13/2005): This function assumes that the parents have been set!
  4793. // so it should not be used in the EDG/Sage translation!
  4794. // ROSE_ASSERT(get_parent() != NULL);
  4795. #if 1
  4796. // DQ (6/21/2006): Return to using this version of the code
  4797. // DQ (6/21/2005): This is trying to traverse back through the scopes which might not make sense
  4798. for (SgNode* r = get_parent(); r != NULL; r = r->get_parent())
  4799. {
  4800. SgDeclarationStatement* d = isSgDeclarationStatement(r);
  4801. // DQ (6/21/2005): I think this should always be true!
  4802. // ROSE_ASSERT(d != NULL);
  4803. if (d != NULL) {
  4804. return d;
  4805. }
  4806. }
  4807. return NULL;
  4808. #else
  4809. // DQ (6/18/2006): Since we store the declaration we should use the explictly stored
  4810. // value instead of anything generated from parents (structure can be problematic for C++).
  4811. return get_declptr();
  4812. #endif
  4813. }
  4814. SgDeclarationStatement*
  4815. SgInitializedName::get_definition() const
  4816. {
  4817. // printf ("Why does SgInitializedName::get_definition() return a declaration! \n");
  4818. // DQ (6/21/2005): Because the SgVariableDefinition is derived from a SgDeclarationStatement
  4819. // and we return a SgVariableDefinition
  4820. // DQ (6/21/2005): Is this always true? NO!
  4821. // ROSE_ASSERT(isSgVariableDefinition(get_declptr()) != NULL);
  4822. return get_declptr();
  4823. }
  4824. /*
  4825. void
  4826. SgInitializedName::set_declaration(SgDeclarationStatement * decl)
  4827. {
  4828. //p_declptr = decl;
  4829. set_parent(decl);
  4830. }
  4831. */
  4832. void
  4833. SgInitializedName::set_definition(SgDeclarationStatement * def)
  4834. {
  4835. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  4836. // DQ (6/12/2007): New access function tests using DEBUG_SAGE_ACCESS_FUNCTIONS and
  4837. // DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION in sage3.h indicate this is required.
  4838. if (get_declptr() != NULL)
  4839. {
  4840. printf ("Note: overwriting SgInitializedName::get_declptr() = %p with NULL before assignment to def = %p \n",get_declptr(),def);
  4841. set_declptr(NULL);
  4842. }
  4843. #endif
  4844. set_declptr(def);
  4845. }
  4846. #if 0
  4847. SgInitializedName*
  4848. SgInitializedName::get_prev_decl_item() const
  4849. { if(p_is_initializer) return 0; else return p_prev_itemptr; }
  4850. void
  4851. SgInitializedName::set_prev_decl_item(SgInitializedName * item)
  4852. { p_prev_itemptr=item; p_is_initializer=0; }
  4853. SgInitializedName*
  4854. SgInitializedName::get_named_item() const
  4855. { return p_itemptr; }
  4856. void
  4857. SgInitializedName::set_named_item(SgInitializedName* item)
  4858. { p_itemptr=item; }
  4859. #endif
  4860. #if 0
  4861. // DQ (1/18/2006): This is not generated due to the name change of "fileInfo" to "file_info"
  4862. Sg_File_Info*
  4863. SgInitializedName::get_file_info(void) const
  4864. {
  4865. // DQ (8/2/2004): Force an explicit function matching the virtual function defined in SgNode
  4866. // but use the new name internally
  4867. // ROSE_ASSERT ( p_fileInfo != NULL);
  4868. return p_fileInfo;
  4869. }
  4870. #endif
  4871. #if 0
  4872. // DQ (4/3/2004): Added support for storage class attributes
  4873. int
  4874. SgInitializedName::checkBit(unsigned int bit) const
  4875. { if (p_storage_class_attributes & bit) return 1; else return 0; }
  4876. void
  4877. SgInitializedName::setBit(unsigned int bit)
  4878. { p_storage_class_attributes |= bit; }
  4879. void
  4880. SgInitializedName::unsetBit(unsigned int bit)
  4881. { p_storage_class_attributes &= ~bit; }
  4882. int
  4883. SgInitializedName::isExtern() const
  4884. { return checkBit(e_extern); }
  4885. void
  4886. SgInitializedName::setExtern()
  4887. { setBit(e_extern); }
  4888. void
  4889. SgInitializedName::unsetExtern()
  4890. { unsetBit(e_extern); }
  4891. int
  4892. SgInitializedName::isStatic() const
  4893. { return checkBit(e_static); }
  4894. void
  4895. SgInitializedName::setStatic()
  4896. { setBit(e_static); }
  4897. void
  4898. SgInitializedName::unsetStatic()
  4899. { unsetBit(e_static); }
  4900. int
  4901. SgInitializedName::isAuto() const
  4902. { return checkBit(e_auto); }
  4903. void
  4904. SgInitializedName::setAuto()
  4905. { setBit(e_auto); }
  4906. void
  4907. SgInitializedName::unsetAuto()
  4908. { unsetBit(e_auto); }
  4909. int
  4910. SgInitializedName::isRegister() const
  4911. { return checkBit(e_register); }
  4912. void
  4913. SgInitializedName::setRegister()
  4914. { setBit(e_register); }
  4915. void
  4916. SgInitializedName::unsetRegister()
  4917. { unsetBit(e_register); }
  4918. int
  4919. SgInitializedName::isAsm() const
  4920. { return checkBit(e_asm); }
  4921. void
  4922. SgInitializedName::setAsm()
  4923. { setBit(e_asm); }
  4924. void
  4925. SgInitializedName::unsetAsm()
  4926. { unsetBit(e_asm); }
  4927. #endif
  4928. unsigned int
  4929. SgInitializedName::cfgIndexForEnd() const {
  4930. return this->get_initializer() ? 1 : 0;
  4931. }
  4932. bool
  4933. SgInitializedName::cfgIsIndexInteresting(unsigned int idx) const {
  4934. return true;
  4935. }
  4936. unsigned int
  4937. SgInitializedName::cfgFindChildIndex(SgNode* n)
  4938. {
  4939. // This function could be rewritten to be:
  4940. // Check for inappropriate child in initialized name
  4941. // ROSE_ASSERT(n == this->get_initializer());
  4942. // return 0;
  4943. if (n == this->get_initializer())
  4944. {
  4945. return 0;
  4946. }
  4947. else
  4948. ROSE_ASSERT (!"Bad child in initialized name");
  4949. // DQ (8/24/2006): Added return to avoid compiler warning!
  4950. return 0;
  4951. }
  4952. unsigned int
  4953. SgInitializedName::cfgFindNextChildIndex(SgNode* n) {
  4954. return this->cfgFindChildIndex(n) + 1;
  4955. }
  4956. std::vector<VirtualCFG::CFGEdge>
  4957. SgInitializedName::cfgOutEdges(unsigned int idx) {
  4958. std::vector<VirtualCFG::CFGEdge> result;
  4959. switch (idx) {
  4960. case 0:
  4961. if (this->get_initializer()) {
  4962. makeEdge(VirtualCFG::CFGNode(this, idx), this->get_initializer()->cfgForBeginning(),
  4963. result);
  4964. } else {
  4965. makeEdge(VirtualCFG::CFGNode(this, idx), VirtualCFG::getNodeJustAfterInContainer(this), result);
  4966. }
  4967. break;
  4968. case 1:
  4969. ROSE_ASSERT (this->get_initializer());
  4970. makeEdge(VirtualCFG::CFGNode(this, idx), VirtualCFG::getNodeJustAfterInContainer(this), result);
  4971. break;
  4972. default: ROSE_ASSERT (!"Bad index in SgInitializedName");
  4973. }
  4974. return result;
  4975. }
  4976. std::vector<VirtualCFG::CFGEdge>
  4977. SgInitializedName::cfgInEdges(unsigned int idx) {
  4978. std::vector<VirtualCFG::CFGEdge> result;
  4979. switch (idx) {
  4980. case 0:
  4981. makeEdge(VirtualCFG::getNodeJustBeforeInContainer(this), VirtualCFG::CFGNode(this, idx), result);
  4982. break;
  4983. case 1:
  4984. ROSE_ASSERT (this->get_initializer());
  4985. makeEdge(this->get_initializer()->cfgForEnd(),
  4986. VirtualCFG::CFGNode(this, idx), result);
  4987. break;
  4988. default: ROSE_ASSERT (!"Bad index in SgInitializedName");
  4989. }
  4990. return result;
  4991. }
  4992. // End of memberFunctionString
  4993. // Start of memberFunctionString
  4994. #line 331 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Common.code"
  4995. // *** COMMON CODE SECTION BEGINS HERE ***
  4996. int
  4997. SgInitializedName::getVariant() const
  4998. {
  4999. // This function is used in ROSE while "variant()" is used in SAGE
  5000. assert(this != NULL);
  5001. return variant();
  5002. }
  5003. // This function is used in ROSE in treeTraversal code
  5004. // eventually replaces getVariant() and variant()
  5005. // though after variant() has been removed for a while we will
  5006. // want to change the name of variantT() back to variant()
  5007. // (since the "T" was ment to stand for temporary).
  5008. // When this happens the variantT() will be depricated.
  5009. VariantT
  5010. SgInitializedName::variantT() const {
  5011. return V_SgInitializedName;
  5012. }
  5013. #if 0
  5014. int
  5015. SgInitializedName::variant() const
  5016. {
  5017. // This function is used in SAGE
  5018. assert(this != NULL);
  5019. return InitializedNameTag;
  5020. }
  5021. #endif
  5022. const char*
  5023. SgInitializedName::sage_class_name() const
  5024. {
  5025. assert(this != NULL);
  5026. return "SgInitializedName";
  5027. }
  5028. std::string
  5029. SgInitializedName::class_name() const
  5030. {
  5031. assert(this != NULL);
  5032. return "SgInitializedName";
  5033. }
  5034. // DQ (11/26/2005): Support for visitor pattern mechanims
  5035. // (inferior to ROSE traversal mechanism, experimental).
  5036. void
  5037. SgInitializedName::executeVisitorMemberFunction (ROSE_VisitorPattern & visitor)
  5038. {
  5039. ROSE_ASSERT(this != NULL);
  5040. visitor.visit(this);
  5041. }
  5042. // *** COMMON CODE SECTION ENDS HERE ***
  5043. // End of memberFunctionString
  5044. // Start of memberFunctionString
  5045. #line 1387 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Node.code"
  5046. #if 0
  5047. //! Error checking support
  5048. /*! Verifies the following:
  5049. - working getVariant() member function
  5050. - calls base class's error() member function
  5051. Every class has one of these functions.
  5052. */
  5053. bool
  5054. SgInitializedName::error()
  5055. {
  5056. // Put error checking here
  5057. ROSE_ASSERT (this != NULL);
  5058. if (getVariant() != InitializedNameTag)
  5059. {
  5060. printf ("Error in SgInitializedName::error(): SgInitializedName object has a %s variant \n",
  5061. Cxx_GrammarTerminalNames[getVariant()].name);
  5062. // printf ("Error in SgInitializedName::error() \n");
  5063. ROSE_ABORT();
  5064. }
  5065. ROSE_ASSERT (getVariant() == InitializedNameTag);
  5066. return SgSupport::error();
  5067. }
  5068. #endif
  5069. // End of memberFunctionString
  5070. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarVariantFunctionDefinitionMacros.macro"
  5071. int
  5072. SgInitializedName::variant() const
  5073. {
  5074. // This function is generated from grammarVariantFunctionDefinitionMacros.macro
  5075. #ifdef DEBUG
  5076. // printf ("In SgInitializedName::variant() const \n");
  5077. #endif
  5078. assert(this != NULL);
  5079. return InitializedNameTag;
  5080. }
  5081. #line 1 ""
  5082. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarIsClassNameFunctionDefinitionMacros.macro"
  5083. SgInitializedName* isSgInitializedName ( SgNode* inputDerivedClassPointer )
  5084. {
  5085. return dynamic_cast<SgInitializedName*>(inputDerivedClassPointer);
  5086. }
  5087. // DQ (11/8/2003): Added version of functions taking const pointer
  5088. const SgInitializedName* isSgInitializedName ( const SgNode* inputDerivedClassPointer )
  5089. {
  5090. return dynamic_cast<const SgInitializedName*>(inputDerivedClassPointer);
  5091. }
  5092. #line 1 ""
  5093. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  5094. /**
  5095. \brief Generated destructor
  5096. This destructor is automatically generated (by ROSETTA). This destructor
  5097. only frees memory of data members associated with the parts of the current IR node which
  5098. are NOT traversed. Those data members that are part of a traversal can be freed using
  5099. a traversal (calling this destructor on all children in a post-order traversal). Such
  5100. a traversal which deletes a whole AST is provided by DeleteSgTree(SgNode*).
  5101. \internal All IR nodes with data members specified using setDataPrototype() within ROSETTA
  5102. are specified as NO_DELETE is also specified as DEF_TRAVERSAL. Those marked as
  5103. NO_TRAVERSAL can be marked as NO_DELETE or DEF_DELETE.
  5104. \note All SgSymbol IR nodes are deleted when the symbol table is deleted. Currently most
  5105. SgType IR nodes are not deleted (since they are shared). Also, all STL lists of
  5106. pointers are not yet implemented to call delete on eash pointer in the container.
  5107. (This could be done by derivation from the STL containers to define containers that
  5108. automatically deleted their members.)
  5109. */
  5110. SgInitializedName::~SgInitializedName ()
  5111. {
  5112. #if 0
  5113. // debugging information!
  5114. printf ("In SgInitializedName::~SgInitializedName (destructor) \n");
  5115. #endif
  5116. #if 1
  5117. // DQ (6/25/2006): Commented out destructor body to allow the File I/O to work.
  5118. delete p_startOfConstruct;
  5119. delete p_storageModifier;
  5120. // case: not a listType for startOfConstruct
  5121. p_startOfConstruct = NULL; // non list case
  5122. // case: not a listType for name
  5123. p_name = NULL; // non list case
  5124. // case: not a listType for typeptr
  5125. p_typeptr = NULL; // non list case
  5126. // case: not a listType for initptr
  5127. p_initptr = NULL; // non list case
  5128. // case: not a listType for prev_decl_item
  5129. p_prev_decl_item = NULL; // non list case
  5130. // case: not a listType for is_initializer
  5131. p_is_initializer = false; // non list case
  5132. // case: not a listType for declptr
  5133. p_declptr = NULL; // non list case
  5134. // case: not a listType for storageModifier
  5135. p_storageModifier = NULL; // non list case
  5136. // case: not a listType for scope
  5137. p_scope = NULL; // non list case
  5138. // case: not a listType for preinitialization
  5139. p_preinitialization = e_unknown_preinitialization; // non list case
  5140. // case: not a listType for attributeMechanism
  5141. p_attributeMechanism = NULL; // non list case
  5142. // case: not a listType for register_name_code
  5143. p_register_name_code = SgInitializedName::e_invalid_register; // non list case
  5144. // case: not a listType for register_name_string
  5145. p_register_name_string = ""; // non list case
  5146. // case: not a listType for requiresGlobalNameQualificationOnType
  5147. p_requiresGlobalNameQualificationOnType = false; // non list case
  5148. #line 32 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  5149. #endif
  5150. }
  5151. #line 1 ""
  5152. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarConstructorDefinitionMacros.macro"
  5153. // Generated constructor
  5154. SgInitializedName::SgInitializedName ( )
  5155. : SgSupport()
  5156. {
  5157. #ifdef DEBUG
  5158. // printf ("In SgInitializedName::SgInitializedName () sage_class_name() = %s \n",sage_class_name());
  5159. #endif
  5160. p_startOfConstruct = NULL;
  5161. p_name = NULL;
  5162. p_typeptr = NULL;
  5163. p_initptr = NULL;
  5164. p_prev_decl_item = NULL;
  5165. p_is_initializer = false;
  5166. p_declptr = NULL;
  5167. p_storageModifier = NULL;
  5168. p_scope = NULL;
  5169. p_preinitialization = e_unknown_preinitialization;
  5170. p_attributeMechanism = NULL;
  5171. p_register_name_code = SgInitializedName::e_invalid_register;
  5172. p_register_name_string = "";
  5173. p_requiresGlobalNameQualificationOnType = false;
  5174. #line 11 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarConstructorDefinitionMacros.macro"
  5175. // Test the variant virtual function
  5176. assert(InitializedNameTag == variant());
  5177. post_construction_initialization();
  5178. // Test the isSgInitializedName() function since it has been problematic
  5179. assert(isSgInitializedName(this) != NULL);
  5180. }
  5181. #line 1 ""
  5182. #line 1 ""
  5183. #line 6 "../Grammar/grammarClassDefinitionMacros.macro after marker MEMBER_FUNCTION_DEFINITIONS"
  5184. #line 7 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  5185. // ********************************************************
  5186. // member functions common across all array grammar objects
  5187. // ********************************************************
  5188. #line 1 ""
  5189. #line 1 ""
  5190. #line 1 ""
  5191. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  5192. // ********************************************************
  5193. // member functions specific to each node in the grammar
  5194. // ********************************************************
  5195. #line 6 "../Grammar/grammarClassDefinitionMacros.macro before marker MEMBER_FUNCTION_DEFINITIONS"
  5196. #line 1 ""
  5197. #line 1 ""
  5198. // Start of memberFunctionString
  5199. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  5200. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  5201. int
  5202. Sg_File_Info::get_file_id () const
  5203. {
  5204. assert (this != NULL);
  5205. return p_file_id;
  5206. }
  5207. void
  5208. Sg_File_Info::set_file_id ( int file_id )
  5209. {
  5210. assert (this != NULL);
  5211. set_isModified(true);
  5212. p_file_id = file_id;
  5213. }
  5214. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  5215. // End of memberFunctionString
  5216. // Start of memberFunctionString
  5217. // End of memberFunctionString
  5218. // Start of memberFunctionString
  5219. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  5220. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  5221. SgFileIdList
  5222. Sg_File_Info::get_fileIDsToUnparse () const
  5223. {
  5224. assert (this != NULL);
  5225. return p_fileIDsToUnparse;
  5226. }
  5227. void
  5228. Sg_File_Info::set_fileIDsToUnparse ( SgFileIdList fileIDsToUnparse )
  5229. {
  5230. assert (this != NULL);
  5231. set_isModified(true);
  5232. p_fileIDsToUnparse = fileIDsToUnparse;
  5233. }
  5234. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  5235. // End of memberFunctionString
  5236. // Start of memberFunctionString
  5237. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  5238. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  5239. std::map<int, std::string>
  5240. Sg_File_Info::get_fileidtoname_map () const
  5241. {
  5242. assert (this != NULL);
  5243. return p_fileidtoname_map;
  5244. }
  5245. void
  5246. Sg_File_Info::set_fileidtoname_map ( std::map<int, std::string> fileidtoname_map )
  5247. {
  5248. assert (this != NULL);
  5249. set_isModified(true);
  5250. p_fileidtoname_map = fileidtoname_map;
  5251. }
  5252. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  5253. // End of memberFunctionString
  5254. // Start of memberFunctionString
  5255. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  5256. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  5257. std::map<std::string, int>
  5258. Sg_File_Info::get_nametofileid_map () const
  5259. {
  5260. assert (this != NULL);
  5261. return p_nametofileid_map;
  5262. }
  5263. void
  5264. Sg_File_Info::set_nametofileid_map ( std::map<std::string, int> nametofileid_map )
  5265. {
  5266. assert (this != NULL);
  5267. set_isModified(true);
  5268. p_nametofileid_map = nametofileid_map;
  5269. }
  5270. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  5271. // End of memberFunctionString
  5272. // Start of memberFunctionString
  5273. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  5274. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  5275. int
  5276. Sg_File_Info::get_max_file_id () const
  5277. {
  5278. assert (this != NULL);
  5279. return p_max_file_id;
  5280. }
  5281. void
  5282. Sg_File_Info::set_max_file_id ( int max_file_id )
  5283. {
  5284. assert (this != NULL);
  5285. set_isModified(true);
  5286. p_max_file_id = max_file_id;
  5287. }
  5288. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  5289. // End of memberFunctionString
  5290. // Start of memberFunctionString
  5291. #line 7784 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Support.code"
  5292. int Sg_File_Info::p_cur_line ROSE_DEPRECATED_VARIABLE = 0;
  5293. std::string Sg_File_Info::p_cur_file ROSE_DEPRECATED_VARIABLE = "";
  5294. // MK (7/22/05) : Added support for file ids. Here we initialize the static file maps, etc
  5295. int Sg_File_Info::p_max_file_id = 0;
  5296. std::map<std::string, int> Sg_File_Info::p_nametofileid_map;
  5297. std::map<int, std::string> Sg_File_Info::p_fileidtoname_map;
  5298. // DQ (7/4/2005): Added to test internal consistancy
  5299. bool
  5300. Sg_File_Info::ok() const
  5301. {
  5302. ROSE_ASSERT(this != NULL);
  5303. bool lineNumberOK = p_line > 0;
  5304. bool columnNumberOK = p_col > 0;
  5305. // MK (7/22/05) We compare using p_fileid instead of p_filename now
  5306. // bool filenameOK = p_filename != NULL;
  5307. bool filenameOK = p_file_id != NULL_FILE_ID;
  5308. // A compiler generated node has no defined association with a file, line number, or column number.
  5309. bool compilerGenerated = isCompilerGenerated();
  5310. // DQ (11/22/2006): Some nodes have no source position information and we have the live with this at points in the processing.
  5311. // A node which was explicitly marked as a sourcePositionUnavailableInFrontendcompiler has no defined association with a file, line number, or column number.
  5312. bool sourcePositionUnavailableInFrontend = isSourcePositionUnavailableInFrontend();
  5313. // DQ (12/23/2006): If this is part of a transformation then it is OK by definition.
  5314. // A node introduced as part of a transformation has no defined association with a file, line number, or column number.
  5315. bool transformation = isTransformation();
  5316. // return compilerGenerated || (lineNumberOK && filenameOK);
  5317. // return sourcePositionUnavailableInFrontend || compilerGenerated || (lineNumberOK && filenameOK);
  5318. // return transformation || sourcePositionUnavailableInFrontend || compilerGenerated || (lineNumberOK && columnNumberOK && filenameOK);
  5319. return (lineNumberOK && columnNumberOK && filenameOK) || compilerGenerated || sourcePositionUnavailableInFrontend || transformation;
  5320. }
  5321. void
  5322. Sg_File_Info::updateSourcePosition ( Sg_File_Info* update )
  5323. {
  5324. // DQ (12/22/2006): This copies the line number and column number information and verifies that
  5325. // the file name is the same (it does not reset any fo the classification flags). This is more
  5326. // useful than the assignment operator for updating information and is used in the file:
  5327. // fixupSourcePositionInformation.C.
  5328. ROSE_ASSERT(update != NULL);
  5329. // Must have matching file name (only have to compare file_id's)
  5330. ROSE_ASSERT(p_file_id == update->p_file_id);
  5331. // Update only the line number and column number after verifying that the filenames are the same.
  5332. p_line = update->p_line;
  5333. p_col = update->p_col;
  5334. }
  5335. // DQ (8/1/2005): use static function to return new Sg_File_Info object set to default values
  5336. // Static function to return new Sg_File_Info object set to default values
  5337. Sg_File_Info* Sg_File_Info::generateDefaultFileInfo()
  5338. {
  5339. Sg_File_Info* returnValue = new Sg_File_Info("NULL_FILE",0,0);
  5340. ROSE_ASSERT(returnValue != NULL);
  5341. // DQ (6/7/2007): This causes "NULL_FILE" filenames to be introduced into the AST.
  5342. // Gergo pointed out this problems and removing such entries will simplify the tests
  5343. // that are done in the traverseInputFile traversal.
  5344. // printf ("Sg_File_Info::generateDefaultFileInfo(): This function is depricated and is an error to call! \n");
  5345. // ROSE_ASSERT(false);
  5346. // printf ("Calling Sg_File_Info::generateDefaultFileInfo(): returnValue = %p \n",returnValue);
  5347. return returnValue;
  5348. }
  5349. // Static function to return new Sg_File_Info object set to default values appropriate for transformations
  5350. // static Sg_File_Info* generateTransformationDefaultFileInfo()
  5351. Sg_File_Info* Sg_File_Info::generateDefaultFileInfoForTransformationNode()
  5352. {
  5353. // IR nodes using this function's return value will be marked as transformations
  5354. Sg_File_Info* returnValue = generateDefaultFileInfo();
  5355. returnValue->setTransformation();
  5356. // DQ (1/11/2006): Added call to setOutputInCodeGeneration() because the default
  5357. // behavior is to output all transformations. Other functions allow transformations
  5358. // to be specified that would not be output (useful for when including new header files).
  5359. returnValue->setOutputInCodeGeneration();
  5360. returnValue->set_file_id( TRANSFORMATION_FILE_ID );
  5361. return returnValue;
  5362. }
  5363. // DQ (1/11/2006): Added version of function where filename (file_id) can
  5364. // be explicitly set to be the non-default value.
  5365. Sg_File_Info* Sg_File_Info::generateFileInfoForTransformationNode( int file_id )
  5366. {
  5367. // IR nodes using this function's return value will be marked as transformations
  5368. Sg_File_Info* returnValue = generateDefaultFileInfoForTransformationNode();
  5369. returnValue->set_file_id( file_id );
  5370. return returnValue;
  5371. }
  5372. // DQ (1/11/2006): Added version of function where filename (file_id) can
  5373. // be explicitly set to be the non-default value.
  5374. Sg_File_Info* Sg_File_Info::generateFileInfoForTransformationNode( string filename )
  5375. {
  5376. // IR nodes using this function's return value will be marked as transformations
  5377. Sg_File_Info* returnValue = generateDefaultFileInfoForTransformationNode();
  5378. returnValue->set_filenameString( filename );
  5379. return returnValue;
  5380. }
  5381. // Static function to return new Sg_File_Info object set to default values appropriate for compiler generated code
  5382. // static Sg_File_Info* generateCompilerGeneratedDefaultFileInfo()
  5383. Sg_File_Info* Sg_File_Info::generateDefaultFileInfoForCompilerGeneratedNode()
  5384. {
  5385. // IR nodes using this function's return value will be marked as compiler generated (but not output, unless also marked as such)
  5386. Sg_File_Info* returnValue = generateDefaultFileInfo();
  5387. returnValue->setCompilerGenerated();
  5388. returnValue->set_file_id( COMPILER_GENERATED_FILE_ID );
  5389. return returnValue;
  5390. }
  5391. // DQ (11/2/2006): Added operator= member function to simple assignment (used in fixupSourcePositionInformation.C
  5392. // to modify Sg_File_Info objects so that they better reflect the original source code).
  5393. Sg_File_Info &
  5394. Sg_File_Info::operator= ( const Sg_File_Info & X )
  5395. {
  5396. p_file_id = X.p_file_id;
  5397. p_line = X.p_line;
  5398. p_col = X.p_col;
  5399. p_classificationBitField = X.p_classificationBitField;
  5400. p_fileIDsToUnparse = X.p_fileIDsToUnparse;
  5401. // Record that this source position information was updated.
  5402. set_isModified(true);
  5403. return *this;
  5404. }
  5405. // DQ (9/26/2004): Added operator== friend function to permit testing of reused definitions of defining declarations!
  5406. bool
  5407. operator== ( const Sg_File_Info & X, const Sg_File_Info & Y )
  5408. {
  5409. bool returnValue = false;
  5410. // Make this most efficent by putting the least likely match first
  5411. // (col, line, file) and the most expensive test (file) last.
  5412. if (X.get_col() == Y.get_col())
  5413. {
  5414. if (X.get_line() == Y.get_line())
  5415. {
  5416. // MK (7/22/05) : Replaced string comparisons with file_id comparisons
  5417. /*
  5418. if ( string(X.get_filename()) == string(Y.get_filename()))
  5419. {
  5420. returnValue = true;
  5421. }
  5422. */
  5423. if (X.p_file_id == Y.p_file_id)
  5424. {
  5425. returnValue = true;
  5426. }
  5427. }
  5428. }
  5429. return returnValue;
  5430. }
  5431. // DQ (10/6/2004): Added operator!= friend function to permit testing of reused definitions of defining declarations!
  5432. bool
  5433. operator!= ( const Sg_File_Info & X, const Sg_File_Info & Y )
  5434. {
  5435. return operator==(X,Y) ? false : true;
  5436. }
  5437. // DQ (10/25/2004): Added relational operators to permit testing of strting vs. ending file info object (assert starting < ending)
  5438. bool
  5439. operator> ( const Sg_File_Info & X, const Sg_File_Info & Y )
  5440. {
  5441. bool result = false;
  5442. // printf ("In operator > (Sg_File_Info,Sg_File_Info): X.isSameFile(Y) = %s \n",X.isSameFile(Y) ? "true" : "false");
  5443. if (X.isSameFile(Y) == true)
  5444. {
  5445. // printf ("X.p_line = %d Y.p_line = %d \n",X.p_line,Y.p_line);
  5446. // printf ("X.p_col = %d Y.p_col = %d \n",X.p_col,Y.p_col);
  5447. if (X.p_line > Y.p_line)
  5448. {
  5449. // printf ("TRUE: X.p_line = %d > X.p_line = %d \n",X.p_line,X.p_line);
  5450. result = true;
  5451. }
  5452. else
  5453. {
  5454. if (X.p_line == Y.p_line)
  5455. {
  5456. if (X.p_col > Y.p_col)
  5457. {
  5458. // printf ("TRUE: X.p_col = %d > Y.p_col = %d \n",X.p_col,Y.p_col);
  5459. result = true;
  5460. }
  5461. }
  5462. }
  5463. }
  5464. // printf ("Sorry operator> (const Sg_File_Info & X, const Sg_File_Info & Y) not implemented! \n");
  5465. // ROSE_ASSERT(false);
  5466. // return true;
  5467. return result;
  5468. }
  5469. bool
  5470. operator< ( const Sg_File_Info & X, const Sg_File_Info & Y )
  5471. {
  5472. bool result = false;
  5473. // printf ("In operator < (Sg_File_Info,Sg_File_Info): X.isSameFile(Y) = %s \n",X.isSameFile(Y) ? "true" : "false");
  5474. if (X.isSameFile(Y) == true)
  5475. {
  5476. // printf ("X.p_line = %d Y.p_line = %d \n",X.p_line,Y.p_line);
  5477. // printf ("X.p_col = %d Y.p_col = %d \n",X.p_col,Y.p_col);
  5478. if (X.p_line < Y.p_line)
  5479. {
  5480. // printf ("TRUE: X.p_line = %d < Y.p_line = %d \n",X.p_line,Y.p_line);
  5481. result = true;
  5482. }
  5483. else
  5484. {
  5485. if (X.p_line == Y.p_line)
  5486. {
  5487. if (X.p_col < Y.p_col)
  5488. {
  5489. // printf ("TRUE: X.p_col = %d < Y.p_col = %d \n",X.p_col,Y.p_col);
  5490. result = true;
  5491. }
  5492. }
  5493. }
  5494. }
  5495. // printf ("Sorry operator< (const Sg_File_Info & X, const Sg_File_Info & Y) not implemented! \n");
  5496. // ROSE_ASSERT(false);
  5497. // return true;
  5498. return result;
  5499. }
  5500. bool
  5501. operator>= ( const Sg_File_Info & X, const Sg_File_Info & Y )
  5502. {
  5503. bool result = false;
  5504. if (X.isSameFile(Y) == true)
  5505. {
  5506. if (X.p_line > Y.p_line)
  5507. {
  5508. result = true;
  5509. }
  5510. else
  5511. {
  5512. if (X.p_line == Y.p_line)
  5513. {
  5514. if (X.p_col >= Y.p_col)
  5515. result = true;
  5516. }
  5517. }
  5518. }
  5519. // printf ("Sorry operator>= (const Sg_File_Info & X, const Sg_File_Info & Y) not implemented! \n");
  5520. // ROSE_ASSERT(false);
  5521. // return true;
  5522. return result;
  5523. }
  5524. bool
  5525. operator<= ( const Sg_File_Info & X, const Sg_File_Info & Y )
  5526. {
  5527. bool result = false;
  5528. if (X.isSameFile(Y) == true)
  5529. {
  5530. if (X.p_line < Y.p_line)
  5531. {
  5532. result = true;
  5533. }
  5534. else
  5535. {
  5536. if (X.p_line == Y.p_line)
  5537. {
  5538. if (X.p_col <= Y.p_col)
  5539. result = true;
  5540. }
  5541. }
  5542. }
  5543. // printf ("Sorry operator<= (const Sg_File_Info & X, const Sg_File_Info & Y) not implemented! \n");
  5544. // ROSE_ASSERT(false);
  5545. // return true;
  5546. return result;
  5547. }
  5548. void
  5549. Sg_File_Info::display( const std::string label ) const
  5550. {
  5551. ROSE_ASSERT(this != NULL);
  5552. printf ("Inside of Sg_File_Info::display(%s) \n",label.c_str());
  5553. printf (" isTransformation = %s \n",isTransformation() == true ? "true (part of a transformation)" : "false");
  5554. printf (" isCompilerGenerated = %s \n",isCompilerGenerated() == true ? "true (no position information)" : "false");
  5555. printf (" isOutputInCodeGeneration = %s \n",isOutputInCodeGeneration() == true ? "true (output in code generator)" : "false");
  5556. printf (" isShared = %s \n",isShared() == true ? "true (shared within merged AST)" : "false");
  5557. printf (" isFrontendSpecific = %s \n",isFrontendSpecific() == true ? "true (part of ROSE support for gnu compatability)" : "false");
  5558. printf (" isSourcePositionUnavailableInFrontend = %s \n",isSourcePositionUnavailableInFrontend() == true ? "true (source position unavailable in frontend)" : "false");
  5559. printf (" isCommentOrDirective = %s \n",isCommentOrDirective() == true ? "true (this is a comment or CPP directive)" : "false");
  5560. printf (" isToken = %s \n",isToken() == true ? "true (this is from the token stream woven into the AST)" : "false");
  5561. // if (isCompilerGenerated() == false)
  5562. if (!isTransformation() && !isCompilerGenerated())
  5563. {
  5564. printf (" filename = %s \n",get_filename());
  5565. printf (" line = %d column = %d \n",get_line(),get_col());
  5566. }
  5567. // DQ (6/17/2005): Way to get extra debugging information, if the
  5568. // substring "debug" is found then extra information is output
  5569. // if (label == "debug")
  5570. if (label.find("debug") != std::string::npos)
  5571. {
  5572. printf (" file_id = %d \n",get_file_id());
  5573. printf (" filename = %s \n",get_raw_filename().c_str());
  5574. printf (" line = %d column = %d \n",p_line,p_col);
  5575. }
  5576. // DQ (5/16/2005): output these values, but I think they might be removed
  5577. // later since I don't see the point of storing this information!
  5578. // printf (" isDeclaration = %s \n",isDeclaration() == true ? "true" : "false");
  5579. // printf (" isInitialization = %s \n",isInitialization() == true ? "true" : "false");
  5580. }
  5581. string
  5582. Sg_File_Info::displayString(const std::string & label ) const
  5583. {
  5584. ROSE_ASSERT(this != NULL);
  5585. std::string s;
  5586. s += std::string("Inside of Sg_File_Info::displayString(") + label + std::string (") \n");
  5587. s += std::string("isTransformation = ") + std::string(isTransformation() ? "true" : "false") + std::string(" ");
  5588. s += std::string("isCompilerGenerated = ") + std::string(isCompilerGenerated() ? "true" : "false") + std::string(" ");
  5589. if (!isTransformation() && !isCompilerGenerated())
  5590. {
  5591. s += std::string("line number = ") + StringUtility::numberToString(get_line()) + std::string(" ");
  5592. s += std::string("column number = ") + StringUtility::numberToString(get_col()) + std::string(" ");
  5593. s += std::string("filename = ") + std::string(get_filename()) + std::string(" ");
  5594. }
  5595. return s;
  5596. }
  5597. void
  5598. Sg_File_Info::display_static_data( const std::string label )
  5599. {
  5600. // DQ (6/11/2007): output static data for debugging
  5601. printf ("Inside of Sg_File_Info::display_static_data(%s) \n",label.c_str());
  5602. printf ("p_cur_line = %d \n",p_cur_line);
  5603. printf ("p_cur_file = %s \n",p_cur_file.c_str());
  5604. printf ("p_max_file_id = %d \n",p_max_file_id);
  5605. printf ("p_nametofileid_map: \n");
  5606. for (std::map<std::string,int>::iterator i = p_nametofileid_map.begin(); i != p_nametofileid_map.end(); i++)
  5607. {
  5608. printf ("name = %s id = %d \n",i->first.c_str(),i->second);
  5609. }
  5610. printf ("p_fileidtoname_map: \n");
  5611. for (std::map<int,std::string>::iterator i = p_fileidtoname_map.begin(); i != p_fileidtoname_map.end(); i++)
  5612. {
  5613. printf ("id = %d name = %s \n",i->first,i->second.c_str());
  5614. }
  5615. }
  5616. // Since we make the arguments in the other constructor
  5617. // have default values this constructor is redundant/ambiguous
  5618. // Sg_File_Info::Sg_File_Info() {}
  5619. Sg_File_Info::Sg_File_Info ()
  5620. {
  5621. ROSE_ASSERT(this != NULL);
  5622. // Default constructor used for making copies of subtrees
  5623. p_line = 0;
  5624. p_col = 0;
  5625. p_classificationBitField = 0;
  5626. // MK (7/22/05) : Initialize p_file_id to inidicate a copy
  5627. p_file_id = COPY_FILE_ID;
  5628. #if 0
  5629. printf ("Sg_File_Info default constructor = %p \n",this);
  5630. // display("In constructor");
  5631. #endif
  5632. // Provide a common function called for initialization support.
  5633. post_construction_initialization();
  5634. }
  5635. // DQ (4/19/2006): Added constructor to take std::string as part of move
  5636. // away from C style strings to C++ style strings.
  5637. Sg_File_Info::Sg_File_Info ( const std::string & filename, int line, int col )
  5638. : p_line(line), p_col(col)
  5639. {
  5640. ROSE_ASSERT(this != NULL);
  5641. // DQ (5/11/2006): Allow "NULL_FILE" as a name (used within ROSE) to map to the NULL_FILE_ID
  5642. // if (filename.empty() == true)
  5643. if (filename.empty() == true || filename == "NULL_FILE")
  5644. {
  5645. p_file_id = NULL_FILE_ID;
  5646. }
  5647. else
  5648. {
  5649. // DQ (7/25/2005): Refactored to use set_filename()
  5650. set_filenameString(filename);
  5651. }
  5652. p_classificationBitField = 0;
  5653. ROSE_ASSERT (p_col >= 0);
  5654. #if 0
  5655. printf ("Sg_File_Info constructor(const std::string,int,int) = %p \n",this);
  5656. // display("In constructor");
  5657. #endif
  5658. // Provide a common function called for initialization support.
  5659. post_construction_initialization();
  5660. }
  5661. // DQ (2/15/2003): added copy constructor
  5662. Sg_File_Info::Sg_File_Info(const Sg_File_Info & X)
  5663. : p_file_id(X.p_file_id),
  5664. p_line(X.p_line), p_col(X.p_col),
  5665. // DQ (7/29/2005): Preserve IR node classification within copy constructor
  5666. // p_classificationBitField(0)
  5667. p_classificationBitField(X.p_classificationBitField),
  5668. p_fileIDsToUnparse(X.p_fileIDsToUnparse)
  5669. {
  5670. ROSE_ASSERT(this != NULL);
  5671. ROSE_ASSERT (p_col >= 0);
  5672. #if 0
  5673. printf ("Sg_File_Info copy constructor(const Sg_File_Info) = %p \n",this);
  5674. // display("In copy constructor");
  5675. #endif
  5676. // Provide a common function called for initialization support.
  5677. post_construction_initialization();
  5678. }
  5679. #if 0
  5680. // This is now removed but saved becuase it might be that it should be depricated for a while
  5681. Sg_File_Info::Sg_File_Info ( const char* filename, int line, int col )
  5682. : p_line(line), p_col(col) // , p_isPartOfTransformation(false)
  5683. {
  5684. ROSE_ASSERT(this != NULL);
  5685. if (!filename) {
  5686. p_file_id = NULL_FILE_ID;
  5687. }
  5688. else
  5689. {
  5690. // DQ (7/25/2005): Refactored to use set_filename()
  5691. set_filename(filename);
  5692. }
  5693. p_classificationBitField = 0;
  5694. if (p_col < 0)
  5695. {
  5696. printf ("Error p_col = %d \n",p_col);
  5697. }
  5698. ROSE_ASSERT (p_col >= 0);
  5699. // Provide a common function called for initialization support.
  5700. post_construction_initialization();
  5701. }
  5702. #endif
  5703. void
  5704. Sg_File_Info::post_construction_initialization()
  5705. {
  5706. ROSE_ASSERT (this != NULL);
  5707. // ROSE_ASSERT(this != (Sg_File_Info*) 0x5231b0);
  5708. }
  5709. void
  5710. Sg_File_Info::set_line(int line)
  5711. {
  5712. ROSE_ASSERT (this != NULL);
  5713. p_line = line;
  5714. }
  5715. void
  5716. // DQ (9/5/2006): renamed functions to swap the implementations
  5717. // Sg_File_Info::set_filename(const char* filename)
  5718. Sg_File_Info::set_filenameString ( const std::string & filename )
  5719. {
  5720. ROSE_ASSERT (this != NULL);
  5721. if (p_nametofileid_map.count(filename) == 0)
  5722. {
  5723. p_file_id = p_max_file_id++;
  5724. p_nametofileid_map[filename] = p_file_id;
  5725. p_fileidtoname_map[p_file_id] = filename;
  5726. }
  5727. else
  5728. {
  5729. p_file_id = p_nametofileid_map[filename];
  5730. }
  5731. // DQ (8/31/2006): We can't enforce that this is an absolute path (test2001_04.C and test2004_60.C demonstrate why).
  5732. // DQ (8/31/2006): Verify that this is a absolute path
  5733. // string targetSubstring = "/";
  5734. // string filenameString = filename;
  5735. // if (filenameString.substr(0,targetSubstring.size()) != targetSubstring)
  5736. // printf ("@@@@@@@@@@@@@@@@@@@@ In Sg_File_Info::Sg_File_Info(string,int,int): filename = %s @@@@@@@@@@@@@@@@@@@@\n",filenameString.c_str());
  5737. // ROSE_ASSERT(filenameString.substr(0,targetSubstring.size()) == targetSubstring);
  5738. // Detect use of AST Rewrite intermediate files (need to make sure they get absolute paths)
  5739. // string targetSubstring2 = "rose_";
  5740. // ROSE_ASSERT(filenameString.substr(0,targetSubstring2.size()) != targetSubstring2);
  5741. }
  5742. void
  5743. // DQ (9/5/2006): renamed functions to swap the implementations
  5744. // Sg_File_Info::set_filenameString ( const std::string & filename )
  5745. Sg_File_Info::set_filename(const char* filename)
  5746. {
  5747. // DQ (9/5/2006): Modified implementation
  5748. // set_filename(filename.c_str());
  5749. ROSE_ASSERT(filename != NULL);
  5750. set_filenameString(filename);
  5751. }
  5752. const std::string&
  5753. Sg_File_Info::get_filenameString() const
  5754. {
  5755. ROSE_ASSERT (this != NULL);
  5756. // return p_filename;
  5757. const std::string* returnString = NULL;
  5758. if (isTransformation() == true)
  5759. {
  5760. #if PRINT_DEVELOPER_WARNINGS
  5761. // DQ (2/25/2006): Unclear how often we want to have this output, it is sometimes useful and sometime annoying.
  5762. printf ("Sg_File_Info::get_filename called for transformation IR node \n");
  5763. #endif
  5764. static const std::string transformation_string = "transformation";
  5765. returnString = &transformation_string;
  5766. }
  5767. else if(isCompilerGenerated() == true)
  5768. {
  5769. // DQ (8/17/2005): only "compilergenerated" when compiler generate (not when marked for output)
  5770. // if ( isCompilerGenerated() == true || isCompilerGeneratedNodeToBeUnparsed() == true )
  5771. // printf ("Sg_File_Info::get_filename called for compiler generated IR node \n");
  5772. static const std::string compilerGenerated_string = "compilerGenerated";
  5773. returnString = &compilerGenerated_string;
  5774. }else {
  5775. #if 0
  5776. const char * tmp = getFilenameFromID(p_file_id).c_str();
  5777. int length = strlen(tmp) + 1;
  5778. returnString = new char[length];
  5779. strncpy(returnString, tmp, length);
  5780. #endif
  5781. returnString = &getFilenameFromID(p_file_id);
  5782. }
  5783. ROSE_ASSERT (returnString != NULL);
  5784. return *returnString;
  5785. }
  5786. const char*
  5787. Sg_File_Info::get_filename() const
  5788. {
  5789. // DQ (10/15/2005): This function is the C++ string version of the get_filename()
  5790. // function which has been depricated. At some point the get_filename() function
  5791. // will be eliminated and later reinfroduced as get_filename() (finally returning
  5792. // a C++ string instead of a char* (C style string)).
  5793. return get_filenameString().c_str();
  5794. }
  5795. string
  5796. Sg_File_Info::get_raw_filename() const
  5797. {
  5798. ROSE_ASSERT (this != NULL);
  5799. // return whatever name is in the map
  5800. return getFilenameFromID(p_file_id);
  5801. }
  5802. int
  5803. Sg_File_Info::get_line() const
  5804. {
  5805. ROSE_ASSERT (this != NULL);
  5806. // return p_line;
  5807. // const int undefinedValue = INT_MAX-1;
  5808. const int undefinedValue = 0;
  5809. int returnValue = 0;
  5810. if (isTransformation() == true)
  5811. {
  5812. // printf ("Sg_File_Info::get_line called for transformation IR node (p_line = %d) \n",p_line);
  5813. returnValue = undefinedValue;
  5814. }
  5815. else
  5816. {
  5817. // DQ (8/17/2005): only undefinedValue when compiler generate (not when marked for output)
  5818. // if ( isCompilerGenerated() == true || isCompilerGeneratedNodeToBeUnparsed() == true )
  5819. if ( isCompilerGenerated() == true )
  5820. {
  5821. // printf ("Sg_File_Info::get_line called for compiler generated IR node (p_line = %d) \n",p_line);
  5822. // DQ (6/14/2005): Temp code to permit identification of line number of template declaration!
  5823. // returnValue = undefinedValue;
  5824. // returnValue = p_line;
  5825. returnValue = undefinedValue;
  5826. }
  5827. else
  5828. {
  5829. returnValue = p_line;
  5830. }
  5831. }
  5832. ROSE_ASSERT (returnValue >= 0);
  5833. return returnValue;
  5834. }
  5835. int
  5836. Sg_File_Info::get_raw_line() const
  5837. {
  5838. ROSE_ASSERT (this != NULL);
  5839. return p_line;
  5840. }
  5841. int
  5842. Sg_File_Info::get_col() const
  5843. {
  5844. ROSE_ASSERT (this != NULL);
  5845. ROSE_ASSERT (p_col >= 0);
  5846. // return p_col;
  5847. // const int undefinedValue = INT_MAX-1;
  5848. const int undefinedValue = 0;
  5849. int returnValue = 0;
  5850. if (isTransformation() == true)
  5851. {
  5852. // printf ("Sg_File_Info::get_col called for transformation IR node \n");
  5853. returnValue = undefinedValue;
  5854. }
  5855. else
  5856. {
  5857. // DQ (8/17/2005): only undefinedValue when compiler generate (not when marked for output)
  5858. // if ( isCompilerGenerated() == true || isCompilerGeneratedNodeToBeUnparsed() == true )
  5859. if ( isCompilerGenerated() == true )
  5860. {
  5861. // printf ("Sg_File_Info::get_col called for compiler generated IR node \n");
  5862. returnValue = undefinedValue;
  5863. }
  5864. else
  5865. {
  5866. returnValue = p_col;
  5867. }
  5868. }
  5869. ROSE_ASSERT (returnValue >= 0);
  5870. return returnValue;
  5871. }
  5872. int
  5873. Sg_File_Info::get_raw_col() const
  5874. {
  5875. ROSE_ASSERT (this != NULL);
  5876. ROSE_ASSERT (p_col >= 0);
  5877. return p_col;
  5878. }
  5879. // DQ (5/24/2005): This function is impemented using the newer classification mechanism
  5880. void
  5881. Sg_File_Info::set_isPartOfTransformation( bool isPartOfTransformation )
  5882. {
  5883. ROSE_ASSERT (this != NULL);
  5884. // p_isPartOfTransformation = isPartOfTransformation;
  5885. if (isPartOfTransformation == true)
  5886. setTransformation();
  5887. else
  5888. unsetTransformation();
  5889. }
  5890. // DQ (5/24/2005): This function is impemented using the newer classification mechanism
  5891. bool
  5892. Sg_File_Info::get_isPartOfTransformation()
  5893. {
  5894. ROSE_ASSERT (this != NULL);
  5895. // return p_isPartOfTransformation;
  5896. return isTransformation();
  5897. }
  5898. void
  5899. Sg_File_Info::register_node(SgLocatedNode* node)
  5900. {} /* register interest */
  5901. void
  5902. Sg_File_Info::deregister_node(SgLocatedNode* node)
  5903. {}
  5904. // functions added by Dan Quinlan (suggested by Gary Lee)
  5905. void
  5906. Sg_File_Info::set_col( int n )
  5907. {
  5908. ROSE_ASSERT (this != NULL);
  5909. p_col = n;
  5910. ROSE_ASSERT (p_col >= 0);
  5911. }
  5912. int
  5913. Sg_File_Info::getCurrentLine () const
  5914. {
  5915. ROSE_ASSERT (this != NULL);
  5916. printf ("This is a depricated function: char* Sg_File_Info::getCurrentLine() const \n");
  5917. return p_cur_line;
  5918. }
  5919. std::string
  5920. Sg_File_Info::getCurrentFilename () const
  5921. {
  5922. ROSE_ASSERT (this != NULL);
  5923. printf ("This is a depricated function: char* Sg_File_Info::getCurrentFilename() const \n");
  5924. return p_cur_file;
  5925. }
  5926. bool
  5927. Sg_File_Info::hasPositionInSource() const
  5928. {
  5929. ROSE_ASSERT(this != NULL);
  5930. // DQ (1/11/2006): Modified to not use the output function which mixed
  5931. // concepts of compiler generated with output (deprecated function).
  5932. // bool result = ( ! ( isTransformation() || isCompilerGenerated() || isCompilerGeneratedNodeToBeUnparsed() ) );
  5933. bool result = ( ! ( isTransformation() || isCompilerGenerated() || isOutputInCodeGeneration() ) );
  5934. return result;
  5935. }
  5936. bool
  5937. Sg_File_Info::isSameFile(SgFile* file) const
  5938. {
  5939. // DQ (6/21/2005): check if this file info object is from the same file
  5940. // This function abstracts the mechanism of comparing if a file info object is associated with a specific SgFile.
  5941. // this function will be made more efficient later when we can abstract out the string comparision from the test.
  5942. // Later we will implement a map from filename to unique "file number identifiers", this will permit significant
  5943. // spaces saving in the IR by avoiding redundant storage of filename strings and also improve the efficiency of
  5944. // testing if two file info objects represent the same file (an integer equality test instead of string comparision).
  5945. // File names are particularly long (since they include full path), so this will allow us to save a lot of space.
  5946. ROSE_ASSERT(this != NULL);
  5947. ROSE_ASSERT(file != NULL);
  5948. // MK (7/22/05) : removing use of p_filename in favor of p_file_id
  5949. // Generate names of the files
  5950. /*
  5951. string inputFilename = file->getFileName();
  5952. string currentFilename = get_filename();
  5953. bool result = (currentFilename == inputFilename);
  5954. */
  5955. SgScopeStatement * globalScope = (SgScopeStatement *)(file->get_root());
  5956. ROSE_ASSERT(globalScope != NULL);
  5957. Sg_File_Info* fileInfo = globalScope->get_file_info();
  5958. ROSE_ASSERT(fileInfo != NULL);
  5959. bool result = (p_file_id == fileInfo->get_file_id());
  5960. return result;
  5961. }
  5962. // DQ (1/18/2006): Added new function with more useful interface.
  5963. bool
  5964. Sg_File_Info::isSameFile(Sg_File_Info* fileInfo) const
  5965. {
  5966. ROSE_ASSERT(fileInfo != NULL);
  5967. bool result = (p_file_id == fileInfo->get_file_id());
  5968. return result;
  5969. }
  5970. // DQ (1/18/2006): Added new function with more useful interface.
  5971. bool
  5972. Sg_File_Info::isSameFile(const Sg_File_Info & fileInfo) const
  5973. {
  5974. bool result = (p_file_id == fileInfo.get_file_id());
  5975. return result;
  5976. }
  5977. //! Access functions for classification of File_Info objects
  5978. bool
  5979. Sg_File_Info::isTransformation() const
  5980. {
  5981. ROSE_ASSERT(this != NULL);
  5982. return (p_classificationBitField & e_transformation);
  5983. }
  5984. void
  5985. Sg_File_Info::setTransformation()
  5986. {
  5987. ROSE_ASSERT(this != NULL);
  5988. p_classificationBitField |= e_transformation;
  5989. }
  5990. void
  5991. Sg_File_Info::unsetTransformation()
  5992. {
  5993. ROSE_ASSERT(this != NULL);
  5994. p_classificationBitField &= ~e_transformation;
  5995. }
  5996. bool
  5997. Sg_File_Info::isCompilerGenerated() const
  5998. {
  5999. ROSE_ASSERT(this != NULL);
  6000. return (p_classificationBitField & e_compiler_generated);
  6001. }
  6002. void
  6003. Sg_File_Info::setCompilerGenerated()
  6004. {
  6005. ROSE_ASSERT(this != NULL);
  6006. p_classificationBitField |= e_compiler_generated;
  6007. }
  6008. void
  6009. Sg_File_Info::unsetCompilerGenerated()
  6010. {
  6011. ROSE_ASSERT(this != NULL);
  6012. p_classificationBitField &= ~e_compiler_generated;
  6013. }
  6014. // bool isCompilerGeneratedNodeToBeUnparsed() const;
  6015. bool
  6016. Sg_File_Info::isCompilerGeneratedNodeToBeUnparsed() const
  6017. {
  6018. // Make sure that both bits are set!
  6019. ROSE_ASSERT(this != NULL);
  6020. return (p_classificationBitField & e_output_in_code_generation);
  6021. #if 0
  6022. // DQ (6/17/2005): Allow these to be set separately so that setting a whole function to
  6023. // be unparsed will not make any expecific casts as compiler generated and not required!
  6024. // If casts are the only issue then perhaps they should be marked explicitly as implicit
  6025. // or explicit (rather than compiler generated).
  6026. bool result = (p_classificationBitField & e_output_in_code_generation);
  6027. // error checking: if e_compiler_generated_node_to_be_unparsed then also e_compiler_generated
  6028. if (result == true)
  6029. ROSE_ASSERT(isCompilerGenerated() == true);
  6030. return result;
  6031. #endif
  6032. }
  6033. void
  6034. Sg_File_Info::setCompilerGeneratedNodeToBeUnparsed()
  6035. {
  6036. // Make sure that both bits are set!
  6037. // setCompilerGenerated();
  6038. ROSE_ASSERT(this != NULL);
  6039. p_classificationBitField |= e_output_in_code_generation;
  6040. }
  6041. void
  6042. Sg_File_Info::unsetCompilerGeneratedNodeToBeUnparsed()
  6043. {
  6044. ROSE_ASSERT(this != NULL);
  6045. p_classificationBitField &= ~e_output_in_code_generation;
  6046. }
  6047. bool
  6048. Sg_File_Info::isOutputInCodeGeneration() const
  6049. {
  6050. // Make sure that both bits are set!
  6051. ROSE_ASSERT(this != NULL);
  6052. return (p_classificationBitField & e_output_in_code_generation);
  6053. }
  6054. void
  6055. Sg_File_Info::setOutputInCodeGeneration()
  6056. {
  6057. // Make sure that both bits are set!
  6058. // setCompilerGenerated();
  6059. ROSE_ASSERT(this != NULL);
  6060. p_classificationBitField |= e_output_in_code_generation;
  6061. }
  6062. void
  6063. Sg_File_Info::unsetOutputInCodeGeneration()
  6064. {
  6065. ROSE_ASSERT(this != NULL);
  6066. p_classificationBitField &= ~e_output_in_code_generation;
  6067. }
  6068. bool
  6069. Sg_File_Info::isShared() const
  6070. {
  6071. ROSE_ASSERT(this != NULL);
  6072. return (p_classificationBitField & e_shared);
  6073. }
  6074. void
  6075. Sg_File_Info::setShared()
  6076. {
  6077. // MK (8/3/05) : We always want to unparse the current file (this is a performance issue)
  6078. ROSE_ASSERT(this != NULL);
  6079. if (isShared() == false)
  6080. p_fileIDsToUnparse.insert(p_file_id);
  6081. p_classificationBitField |= e_shared;
  6082. }
  6083. void
  6084. Sg_File_Info::unsetShared()
  6085. {
  6086. ROSE_ASSERT(this != NULL);
  6087. p_classificationBitField &= ~e_shared;
  6088. // MK (8/2/05) : Initialize the fileid set
  6089. p_fileIDsToUnparse.clear();
  6090. }
  6091. bool
  6092. Sg_File_Info::isFrontendSpecific() const
  6093. {
  6094. ROSE_ASSERT(this != NULL);
  6095. return (p_classificationBitField & e_frontend_specific);
  6096. }
  6097. void
  6098. Sg_File_Info::setFrontendSpecific()
  6099. {
  6100. ROSE_ASSERT(this != NULL);
  6101. p_classificationBitField |= e_frontend_specific;
  6102. }
  6103. void
  6104. Sg_File_Info::unsetFrontendSpecific()
  6105. {
  6106. ROSE_ASSERT(this != NULL);
  6107. p_classificationBitField &= ~e_frontend_specific;
  6108. }
  6109. bool
  6110. Sg_File_Info::isSourcePositionUnavailableInFrontend() const
  6111. {
  6112. ROSE_ASSERT(this != NULL);
  6113. return (p_classificationBitField & e_source_position_unavailable_in_frontend);
  6114. }
  6115. void
  6116. Sg_File_Info::setSourcePositionUnavailableInFrontend()
  6117. {
  6118. ROSE_ASSERT(this != NULL);
  6119. p_classificationBitField |= e_source_position_unavailable_in_frontend;
  6120. }
  6121. void
  6122. Sg_File_Info::unsetSourcePositionUnavailableInFrontend()
  6123. {
  6124. ROSE_ASSERT(this != NULL);
  6125. p_classificationBitField &= ~e_source_position_unavailable_in_frontend;
  6126. }
  6127. bool
  6128. Sg_File_Info::isCommentOrDirective() const
  6129. {
  6130. ROSE_ASSERT(this != NULL);
  6131. return (p_classificationBitField & e_comment_or_directive);
  6132. }
  6133. void
  6134. Sg_File_Info::setCommentOrDirective()
  6135. {
  6136. ROSE_ASSERT(this != NULL);
  6137. p_classificationBitField |= e_comment_or_directive;
  6138. }
  6139. void
  6140. Sg_File_Info::unsetCommentOrDirective()
  6141. {
  6142. ROSE_ASSERT(this != NULL);
  6143. p_classificationBitField &= ~e_comment_or_directive;
  6144. }
  6145. bool
  6146. Sg_File_Info::isToken() const
  6147. {
  6148. ROSE_ASSERT(this != NULL);
  6149. return (p_classificationBitField & e_token);
  6150. }
  6151. void
  6152. Sg_File_Info::setToken()
  6153. {
  6154. ROSE_ASSERT(this != NULL);
  6155. p_classificationBitField |= e_token;
  6156. }
  6157. void
  6158. Sg_File_Info::unsetToken()
  6159. {
  6160. ROSE_ASSERT(this != NULL);
  6161. p_classificationBitField &= ~e_token;
  6162. }
  6163. // MK (8/2/05) : Implementation for function to handle unparsing of particular files
  6164. void
  6165. Sg_File_Info::addFileToUnparse(int file_id)
  6166. {
  6167. ROSE_ASSERT(this != NULL);
  6168. p_fileIDsToUnparse.insert(file_id);
  6169. }
  6170. bool
  6171. Sg_File_Info::shouldUnparse(int file_id)
  6172. {
  6173. ROSE_ASSERT(this != NULL);
  6174. return p_fileIDsToUnparse.count(file_id) != 0;
  6175. }
  6176. // DQ (6/17/2005): Removed function (not used and not important to support)
  6177. // bool
  6178. // Sg_File_Info::isDeclaration() const
  6179. // { return (p_classificationBitField & e_declaration); }
  6180. // DQ (6/17/2005): Removed function (not used and not important to support)
  6181. // void
  6182. // Sg_File_Info::setDeclaration()
  6183. // {
  6184. // unsetInitialization();
  6185. // p_classificationBitField |= e_declaration;
  6186. // }
  6187. // DQ (6/17/2005): Removed function (not used and not important to support)
  6188. // void
  6189. // Sg_File_Info::unsetDeclaration()
  6190. // { p_classificationBitField &= ~e_declaration; }
  6191. // DQ (6/17/2005): Removed function (not used and not important to support)
  6192. // bool
  6193. // Sg_File_Info::isInitialization() const
  6194. // { return (p_classificationBitField & e_initialization); }
  6195. // DQ (6/17/2005): Removed function (not used and not important to support)
  6196. // void
  6197. // Sg_File_Info::setInitialization()
  6198. // {
  6199. // unsetDeclaration();
  6200. // p_classificationBitField |= e_initialization;
  6201. // }
  6202. // DQ (6/17/2005): Removed function (not used and not important to support)
  6203. // void
  6204. // Sg_File_Info::unsetInitialization()
  6205. // { p_classificationBitField &= ~e_initialization; }
  6206. unsigned int
  6207. Sg_File_Info::get_classificationBitField(void) const
  6208. {
  6209. ROSE_ASSERT(this != NULL);
  6210. return p_classificationBitField;
  6211. }
  6212. void
  6213. Sg_File_Info::set_classificationBitField( unsigned int bitflags )
  6214. {
  6215. ROSE_ASSERT(this != NULL);
  6216. p_classificationBitField = bitflags;
  6217. }
  6218. // MK (8/2/05): Added implementations for static functions to support interface to fileid maps
  6219. const string&
  6220. Sg_File_Info::getFilenameFromID(int id)
  6221. {
  6222. // This is a static function
  6223. const std::string* name = NULL;
  6224. switch(id)
  6225. {
  6226. // special cases
  6227. case NULL_FILE_ID:
  6228. {
  6229. static const std::string null_file_string = "NULL_FILE";
  6230. name = &null_file_string;
  6231. break;
  6232. }
  6233. case COPY_FILE_ID:
  6234. {
  6235. static const std::string copy_file_string = "COPY";
  6236. name = &copy_file_string;
  6237. break;
  6238. }
  6239. case TRANSFORMATION_FILE_ID:
  6240. {
  6241. static const std::string transformation_string = "transformation";
  6242. name = &transformation_string;
  6243. break;
  6244. }
  6245. case COMPILER_GENERATED_FILE_ID:
  6246. {
  6247. static const std::string compilerGenerated_string = "compilerGenerated";
  6248. name = &compilerGenerated_string;
  6249. break;
  6250. }
  6251. case COMPILER_GENERATED_MARKED_FOR_OUTPUT_FILE_ID:
  6252. {
  6253. // name = "compilerGenerated";
  6254. printf ("The concept of COMPILER_GENERATED and OUTPUT are now decoupled, so make this an error \n");
  6255. ROSE_ASSERT(false);
  6256. break;
  6257. }
  6258. case BAD_FILE_ID:
  6259. {
  6260. static const std::string badfile_string = "badfile";
  6261. name = &badfile_string;
  6262. break;
  6263. }
  6264. // normal case
  6265. default:
  6266. {
  6267. // assert that the id is present in the map (else error)
  6268. // ROSE_ASSERT(p_fileidtoname_map.count(id) != 0);
  6269. bool failure = (p_fileidtoname_map.count(id) == 0);
  6270. if (failure == true)
  6271. {
  6272. printf ("Error: bad id number for file id (id = %d) \n",id);
  6273. display_static_data("error in getFilenameFromID");
  6274. // Note: this causes an empty entry to be generated in p_fileidtoname_map for the id == p_max_file_id (value of max map size)
  6275. // std::cout << p_fileidtoname_map[id] << std::endl;
  6276. // printf ("Error: bad id number for file id (id = %d) \n",id);
  6277. }
  6278. ROSE_ASSERT(failure == false);
  6279. // get the filename from the map using the valid id
  6280. name = &p_fileidtoname_map[id];
  6281. }
  6282. }
  6283. return *name;
  6284. }
  6285. int
  6286. Sg_File_Info::getIDFromFilename( std::string filename )
  6287. {
  6288. // This is a static function
  6289. if (p_nametofileid_map.count(filename) == 0)
  6290. {
  6291. return BAD_FILE_ID;
  6292. }
  6293. return p_nametofileid_map[filename];
  6294. }
  6295. // End of memberFunctionString
  6296. // Start of memberFunctionString
  6297. #line 331 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Common.code"
  6298. // *** COMMON CODE SECTION BEGINS HERE ***
  6299. int
  6300. Sg_File_Info::getVariant() const
  6301. {
  6302. // This function is used in ROSE while "variant()" is used in SAGE
  6303. assert(this != NULL);
  6304. return variant();
  6305. }
  6306. // This function is used in ROSE in treeTraversal code
  6307. // eventually replaces getVariant() and variant()
  6308. // though after variant() has been removed for a while we will
  6309. // want to change the name of variantT() back to variant()
  6310. // (since the "T" was ment to stand for temporary).
  6311. // When this happens the variantT() will be depricated.
  6312. VariantT
  6313. Sg_File_Info::variantT() const {
  6314. return V_Sg_File_Info;
  6315. }
  6316. #if 0
  6317. int
  6318. Sg_File_Info::variant() const
  6319. {
  6320. // This function is used in SAGE
  6321. assert(this != NULL);
  6322. return _File_InfoTag;
  6323. }
  6324. #endif
  6325. const char*
  6326. Sg_File_Info::sage_class_name() const
  6327. {
  6328. assert(this != NULL);
  6329. return "Sg_File_Info";
  6330. }
  6331. std::string
  6332. Sg_File_Info::class_name() const
  6333. {
  6334. assert(this != NULL);
  6335. return "Sg_File_Info";
  6336. }
  6337. // DQ (11/26/2005): Support for visitor pattern mechanims
  6338. // (inferior to ROSE traversal mechanism, experimental).
  6339. void
  6340. Sg_File_Info::executeVisitorMemberFunction (ROSE_VisitorPattern & visitor)
  6341. {
  6342. ROSE_ASSERT(this != NULL);
  6343. visitor.visit(this);
  6344. }
  6345. // *** COMMON CODE SECTION ENDS HERE ***
  6346. // End of memberFunctionString
  6347. // Start of memberFunctionString
  6348. #line 1387 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Node.code"
  6349. #if 0
  6350. //! Error checking support
  6351. /*! Verifies the following:
  6352. - working getVariant() member function
  6353. - calls base class's error() member function
  6354. Every class has one of these functions.
  6355. */
  6356. bool
  6357. Sg_File_Info::error()
  6358. {
  6359. // Put error checking here
  6360. ROSE_ASSERT (this != NULL);
  6361. if (getVariant() != _File_InfoTag)
  6362. {
  6363. printf ("Error in Sg_File_Info::error(): Sg_File_Info object has a %s variant \n",
  6364. Cxx_GrammarTerminalNames[getVariant()].name);
  6365. // printf ("Error in Sg_File_Info::error() \n");
  6366. ROSE_ABORT();
  6367. }
  6368. ROSE_ASSERT (getVariant() == _File_InfoTag);
  6369. return SgSupport::error();
  6370. }
  6371. #endif
  6372. // End of memberFunctionString
  6373. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarVariantFunctionDefinitionMacros.macro"
  6374. int
  6375. Sg_File_Info::variant() const
  6376. {
  6377. // This function is generated from grammarVariantFunctionDefinitionMacros.macro
  6378. #ifdef DEBUG
  6379. // printf ("In Sg_File_Info::variant() const \n");
  6380. #endif
  6381. assert(this != NULL);
  6382. return _File_InfoTag;
  6383. }
  6384. #line 1 ""
  6385. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarIsClassNameFunctionDefinitionMacros.macro"
  6386. Sg_File_Info* isSg_File_Info ( SgNode* inputDerivedClassPointer )
  6387. {
  6388. return dynamic_cast<Sg_File_Info*>(inputDerivedClassPointer);
  6389. }
  6390. // DQ (11/8/2003): Added version of functions taking const pointer
  6391. const Sg_File_Info* isSg_File_Info ( const SgNode* inputDerivedClassPointer )
  6392. {
  6393. return dynamic_cast<const Sg_File_Info*>(inputDerivedClassPointer);
  6394. }
  6395. #line 1 ""
  6396. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  6397. /**
  6398. \brief Generated destructor
  6399. This destructor is automatically generated (by ROSETTA). This destructor
  6400. only frees memory of data members associated with the parts of the current IR node which
  6401. are NOT traversed. Those data members that are part of a traversal can be freed using
  6402. a traversal (calling this destructor on all children in a post-order traversal). Such
  6403. a traversal which deletes a whole AST is provided by DeleteSgTree(SgNode*).
  6404. \internal All IR nodes with data members specified using setDataPrototype() within ROSETTA
  6405. are specified as NO_DELETE is also specified as DEF_TRAVERSAL. Those marked as
  6406. NO_TRAVERSAL can be marked as NO_DELETE or DEF_DELETE.
  6407. \note All SgSymbol IR nodes are deleted when the symbol table is deleted. Currently most
  6408. SgType IR nodes are not deleted (since they are shared). Also, all STL lists of
  6409. pointers are not yet implemented to call delete on eash pointer in the container.
  6410. (This could be done by derivation from the STL containers to define containers that
  6411. automatically deleted their members.)
  6412. */
  6413. Sg_File_Info::~Sg_File_Info ()
  6414. {
  6415. #if 0
  6416. // debugging information!
  6417. printf ("In Sg_File_Info::~Sg_File_Info (destructor) \n");
  6418. #endif
  6419. #if 1
  6420. // DQ (6/25/2006): Commented out destructor body to allow the File I/O to work.
  6421. // case: not a listType for file_id
  6422. p_file_id = NULL_FILE_ID; // non list case
  6423. // case: not a listType for line
  6424. p_line = 0; // non list case
  6425. // case: not a listType for col
  6426. p_col = 0; // non list case
  6427. // case: not a listType for classificationBitField
  6428. p_classificationBitField = 0; // non list case
  6429. #line 32 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  6430. #endif
  6431. }
  6432. #line 1 ""
  6433. #line 1 ""
  6434. #line 6 "../Grammar/grammarClassDefinitionMacros.macro after marker MEMBER_FUNCTION_DEFINITIONS"
  6435. #line 7 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  6436. // ********************************************************
  6437. // member functions common across all array grammar objects
  6438. // ********************************************************
  6439. #line 1 ""
  6440. #line 1 ""
  6441. #line 1 ""
  6442. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  6443. // ********************************************************
  6444. // member functions specific to each node in the grammar
  6445. // ********************************************************
  6446. #line 6 "../Grammar/grammarClassDefinitionMacros.macro before marker MEMBER_FUNCTION_DEFINITIONS"
  6447. #line 1 ""
  6448. #line 1 ""
  6449. // Start of memberFunctionString
  6450. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6451. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6452. Sg_File_Info*
  6453. SgFile::get_startOfConstruct () const
  6454. {
  6455. assert (this != NULL);
  6456. return p_startOfConstruct;
  6457. }
  6458. void
  6459. SgFile::set_startOfConstruct ( Sg_File_Info* startOfConstruct )
  6460. {
  6461. assert (this != NULL);
  6462. set_isModified(true);
  6463. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  6464. if (p_startOfConstruct != NULL && startOfConstruct != NULL && p_startOfConstruct != startOfConstruct)
  6465. {
  6466. printf ("Warning: startOfConstruct = %p overwriting valid pointer p_startOfConstruct = %p \n",startOfConstruct,p_startOfConstruct);
  6467. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  6468. printf ("Error fails assertion (p_startOfConstruct != NULL && startOfConstruct != NULL && p_startOfConstruct != startOfConstruct) is false\n");
  6469. ROSE_ASSERT(false);
  6470. #endif
  6471. }
  6472. #endif
  6473. p_startOfConstruct = startOfConstruct;
  6474. }
  6475. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6476. // End of memberFunctionString
  6477. // Start of memberFunctionString
  6478. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6479. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6480. SgGlobal*
  6481. SgFile::get_root () const
  6482. {
  6483. assert (this != NULL);
  6484. return p_root;
  6485. }
  6486. void
  6487. SgFile::set_root ( SgGlobal* root )
  6488. {
  6489. assert (this != NULL);
  6490. set_isModified(true);
  6491. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  6492. if (p_root != NULL && root != NULL && p_root != root)
  6493. {
  6494. printf ("Warning: root = %p overwriting valid pointer p_root = %p \n",root,p_root);
  6495. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  6496. printf ("Error fails assertion (p_root != NULL && root != NULL && p_root != root) is false\n");
  6497. ROSE_ASSERT(false);
  6498. #endif
  6499. }
  6500. #endif
  6501. p_root = root;
  6502. }
  6503. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6504. // End of memberFunctionString
  6505. // Start of memberFunctionString
  6506. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6507. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6508. SgStringList
  6509. SgFile::get_originalCommandLineArgumentList () const
  6510. {
  6511. assert (this != NULL);
  6512. return p_originalCommandLineArgumentList;
  6513. }
  6514. void
  6515. SgFile::set_originalCommandLineArgumentList ( SgStringList originalCommandLineArgumentList )
  6516. {
  6517. assert (this != NULL);
  6518. set_isModified(true);
  6519. p_originalCommandLineArgumentList = originalCommandLineArgumentList;
  6520. }
  6521. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6522. // End of memberFunctionString
  6523. // Start of memberFunctionString
  6524. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6525. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6526. int
  6527. SgFile::get_verbose () const
  6528. {
  6529. assert (this != NULL);
  6530. return p_verbose;
  6531. }
  6532. void
  6533. SgFile::set_verbose ( int verbose )
  6534. {
  6535. assert (this != NULL);
  6536. set_isModified(true);
  6537. p_verbose = verbose;
  6538. }
  6539. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6540. // End of memberFunctionString
  6541. // Start of memberFunctionString
  6542. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6543. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6544. bool
  6545. SgFile::get_C_only () const
  6546. {
  6547. assert (this != NULL);
  6548. return p_C_only;
  6549. }
  6550. void
  6551. SgFile::set_C_only ( bool C_only )
  6552. {
  6553. assert (this != NULL);
  6554. set_isModified(true);
  6555. p_C_only = C_only;
  6556. }
  6557. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6558. // End of memberFunctionString
  6559. // Start of memberFunctionString
  6560. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6561. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6562. bool
  6563. SgFile::get_C99_only () const
  6564. {
  6565. assert (this != NULL);
  6566. return p_C99_only;
  6567. }
  6568. void
  6569. SgFile::set_C99_only ( bool C99_only )
  6570. {
  6571. assert (this != NULL);
  6572. set_isModified(true);
  6573. p_C99_only = C99_only;
  6574. }
  6575. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6576. // End of memberFunctionString
  6577. // Start of memberFunctionString
  6578. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6579. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6580. bool
  6581. SgFile::get_Fortran_only () const
  6582. {
  6583. assert (this != NULL);
  6584. return p_Fortran_only;
  6585. }
  6586. void
  6587. SgFile::set_Fortran_only ( bool Fortran_only )
  6588. {
  6589. assert (this != NULL);
  6590. set_isModified(true);
  6591. p_Fortran_only = Fortran_only;
  6592. }
  6593. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6594. // End of memberFunctionString
  6595. // Start of memberFunctionString
  6596. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6597. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6598. bool
  6599. SgFile::get_F77_only () const
  6600. {
  6601. assert (this != NULL);
  6602. return p_F77_only;
  6603. }
  6604. void
  6605. SgFile::set_F77_only ( bool F77_only )
  6606. {
  6607. assert (this != NULL);
  6608. set_isModified(true);
  6609. p_F77_only = F77_only;
  6610. }
  6611. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6612. // End of memberFunctionString
  6613. // Start of memberFunctionString
  6614. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6615. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6616. bool
  6617. SgFile::get_F90_only () const
  6618. {
  6619. assert (this != NULL);
  6620. return p_F90_only;
  6621. }
  6622. void
  6623. SgFile::set_F90_only ( bool F90_only )
  6624. {
  6625. assert (this != NULL);
  6626. set_isModified(true);
  6627. p_F90_only = F90_only;
  6628. }
  6629. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6630. // End of memberFunctionString
  6631. // Start of memberFunctionString
  6632. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6633. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6634. bool
  6635. SgFile::get_F95_only () const
  6636. {
  6637. assert (this != NULL);
  6638. return p_F95_only;
  6639. }
  6640. void
  6641. SgFile::set_F95_only ( bool F95_only )
  6642. {
  6643. assert (this != NULL);
  6644. set_isModified(true);
  6645. p_F95_only = F95_only;
  6646. }
  6647. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6648. // End of memberFunctionString
  6649. // Start of memberFunctionString
  6650. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6651. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6652. bool
  6653. SgFile::get_F2003_only () const
  6654. {
  6655. assert (this != NULL);
  6656. return p_F2003_only;
  6657. }
  6658. void
  6659. SgFile::set_F2003_only ( bool F2003_only )
  6660. {
  6661. assert (this != NULL);
  6662. set_isModified(true);
  6663. p_F2003_only = F2003_only;
  6664. }
  6665. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6666. // End of memberFunctionString
  6667. // Start of memberFunctionString
  6668. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6669. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6670. bool
  6671. SgFile::get_fixedFormat () const
  6672. {
  6673. assert (this != NULL);
  6674. return p_fixedFormat;
  6675. }
  6676. void
  6677. SgFile::set_fixedFormat ( bool fixedFormat )
  6678. {
  6679. assert (this != NULL);
  6680. set_isModified(true);
  6681. p_fixedFormat = fixedFormat;
  6682. }
  6683. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6684. // End of memberFunctionString
  6685. // Start of memberFunctionString
  6686. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6687. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6688. bool
  6689. SgFile::get_freeFormat () const
  6690. {
  6691. assert (this != NULL);
  6692. return p_freeFormat;
  6693. }
  6694. void
  6695. SgFile::set_freeFormat ( bool freeFormat )
  6696. {
  6697. assert (this != NULL);
  6698. set_isModified(true);
  6699. p_freeFormat = freeFormat;
  6700. }
  6701. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6702. // End of memberFunctionString
  6703. // Start of memberFunctionString
  6704. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6705. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6706. SgFile::outputFormatOption_enum
  6707. SgFile::get_outputFormat () const
  6708. {
  6709. assert (this != NULL);
  6710. return p_outputFormat;
  6711. }
  6712. void
  6713. SgFile::set_outputFormat ( SgFile::outputFormatOption_enum outputFormat )
  6714. {
  6715. assert (this != NULL);
  6716. set_isModified(true);
  6717. p_outputFormat = outputFormat;
  6718. }
  6719. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6720. // End of memberFunctionString
  6721. // Start of memberFunctionString
  6722. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6723. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6724. bool
  6725. SgFile::get_fortran_implicit_none () const
  6726. {
  6727. assert (this != NULL);
  6728. return p_fortran_implicit_none;
  6729. }
  6730. void
  6731. SgFile::set_fortran_implicit_none ( bool fortran_implicit_none )
  6732. {
  6733. assert (this != NULL);
  6734. set_isModified(true);
  6735. p_fortran_implicit_none = fortran_implicit_none;
  6736. }
  6737. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6738. // End of memberFunctionString
  6739. // Start of memberFunctionString
  6740. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6741. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6742. bool
  6743. SgFile::get_fortran_openmp () const
  6744. {
  6745. assert (this != NULL);
  6746. return p_fortran_openmp;
  6747. }
  6748. void
  6749. SgFile::set_fortran_openmp ( bool fortran_openmp )
  6750. {
  6751. assert (this != NULL);
  6752. set_isModified(true);
  6753. p_fortran_openmp = fortran_openmp;
  6754. }
  6755. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6756. // End of memberFunctionString
  6757. // Start of memberFunctionString
  6758. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6759. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6760. bool
  6761. SgFile::get_skip_transformation () const
  6762. {
  6763. assert (this != NULL);
  6764. return p_skip_transformation;
  6765. }
  6766. void
  6767. SgFile::set_skip_transformation ( bool skip_transformation )
  6768. {
  6769. assert (this != NULL);
  6770. set_isModified(true);
  6771. p_skip_transformation = skip_transformation;
  6772. }
  6773. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6774. // End of memberFunctionString
  6775. // Start of memberFunctionString
  6776. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6777. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6778. bool
  6779. SgFile::get_skip_unparse () const
  6780. {
  6781. assert (this != NULL);
  6782. return p_skip_unparse;
  6783. }
  6784. void
  6785. SgFile::set_skip_unparse ( bool skip_unparse )
  6786. {
  6787. assert (this != NULL);
  6788. set_isModified(true);
  6789. p_skip_unparse = skip_unparse;
  6790. }
  6791. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6792. // End of memberFunctionString
  6793. // Start of memberFunctionString
  6794. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6795. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6796. bool
  6797. SgFile::get_unparse_includes () const
  6798. {
  6799. assert (this != NULL);
  6800. return p_unparse_includes;
  6801. }
  6802. void
  6803. SgFile::set_unparse_includes ( bool unparse_includes )
  6804. {
  6805. assert (this != NULL);
  6806. set_isModified(true);
  6807. p_unparse_includes = unparse_includes;
  6808. }
  6809. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6810. // End of memberFunctionString
  6811. // Start of memberFunctionString
  6812. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6813. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6814. bool
  6815. SgFile::get_skipfinalCompileStep () const
  6816. {
  6817. assert (this != NULL);
  6818. return p_skipfinalCompileStep;
  6819. }
  6820. void
  6821. SgFile::set_skipfinalCompileStep ( bool skipfinalCompileStep )
  6822. {
  6823. assert (this != NULL);
  6824. set_isModified(true);
  6825. p_skipfinalCompileStep = skipfinalCompileStep;
  6826. }
  6827. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6828. // End of memberFunctionString
  6829. // Start of memberFunctionString
  6830. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6831. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6832. SgFile::outputLanguageOption_enum
  6833. SgFile::get_outputLanguage () const
  6834. {
  6835. assert (this != NULL);
  6836. return p_outputLanguage;
  6837. }
  6838. void
  6839. SgFile::set_outputLanguage ( SgFile::outputLanguageOption_enum outputLanguage )
  6840. {
  6841. assert (this != NULL);
  6842. set_isModified(true);
  6843. p_outputLanguage = outputLanguage;
  6844. }
  6845. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6846. // End of memberFunctionString
  6847. // Start of memberFunctionString
  6848. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6849. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6850. std::string
  6851. SgFile::get_sourceFileNameWithPath () const
  6852. {
  6853. assert (this != NULL);
  6854. return p_sourceFileNameWithPath;
  6855. }
  6856. void
  6857. SgFile::set_sourceFileNameWithPath ( std::string sourceFileNameWithPath )
  6858. {
  6859. assert (this != NULL);
  6860. set_isModified(true);
  6861. p_sourceFileNameWithPath = sourceFileNameWithPath;
  6862. }
  6863. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6864. // End of memberFunctionString
  6865. // Start of memberFunctionString
  6866. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6867. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6868. std::string
  6869. SgFile::get_sourceFileNameWithoutPath () const
  6870. {
  6871. assert (this != NULL);
  6872. return p_sourceFileNameWithoutPath;
  6873. }
  6874. void
  6875. SgFile::set_sourceFileNameWithoutPath ( std::string sourceFileNameWithoutPath )
  6876. {
  6877. assert (this != NULL);
  6878. set_isModified(true);
  6879. p_sourceFileNameWithoutPath = sourceFileNameWithoutPath;
  6880. }
  6881. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6882. // End of memberFunctionString
  6883. // Start of memberFunctionString
  6884. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6885. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6886. std::string
  6887. SgFile::get_unparse_output_filename () const
  6888. {
  6889. assert (this != NULL);
  6890. return p_unparse_output_filename;
  6891. }
  6892. void
  6893. SgFile::set_unparse_output_filename ( std::string unparse_output_filename )
  6894. {
  6895. assert (this != NULL);
  6896. set_isModified(true);
  6897. p_unparse_output_filename = unparse_output_filename;
  6898. }
  6899. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6900. // End of memberFunctionString
  6901. // Start of memberFunctionString
  6902. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6903. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6904. bool
  6905. SgFile::get_useBackendOnly () const
  6906. {
  6907. assert (this != NULL);
  6908. return p_useBackendOnly;
  6909. }
  6910. void
  6911. SgFile::set_useBackendOnly ( bool useBackendOnly )
  6912. {
  6913. assert (this != NULL);
  6914. set_isModified(true);
  6915. p_useBackendOnly = useBackendOnly;
  6916. }
  6917. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6918. // End of memberFunctionString
  6919. // Start of memberFunctionString
  6920. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6921. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6922. bool
  6923. SgFile::get_compileOnly () const
  6924. {
  6925. assert (this != NULL);
  6926. return p_compileOnly;
  6927. }
  6928. void
  6929. SgFile::set_compileOnly ( bool compileOnly )
  6930. {
  6931. assert (this != NULL);
  6932. set_isModified(true);
  6933. p_compileOnly = compileOnly;
  6934. }
  6935. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6936. // End of memberFunctionString
  6937. // Start of memberFunctionString
  6938. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6939. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6940. std::string
  6941. SgFile::get_savedFrontendCommandLine () const
  6942. {
  6943. assert (this != NULL);
  6944. return p_savedFrontendCommandLine;
  6945. }
  6946. void
  6947. SgFile::set_savedFrontendCommandLine ( std::string savedFrontendCommandLine )
  6948. {
  6949. assert (this != NULL);
  6950. set_isModified(true);
  6951. p_savedFrontendCommandLine = savedFrontendCommandLine;
  6952. }
  6953. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6954. // End of memberFunctionString
  6955. // Start of memberFunctionString
  6956. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6957. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6958. bool
  6959. SgFile::get_no_implicit_templates () const
  6960. {
  6961. assert (this != NULL);
  6962. return p_no_implicit_templates;
  6963. }
  6964. void
  6965. SgFile::set_no_implicit_templates ( bool no_implicit_templates )
  6966. {
  6967. assert (this != NULL);
  6968. set_isModified(true);
  6969. p_no_implicit_templates = no_implicit_templates;
  6970. }
  6971. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6972. // End of memberFunctionString
  6973. // Start of memberFunctionString
  6974. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6975. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6976. bool
  6977. SgFile::get_no_implicit_inline_templates () const
  6978. {
  6979. assert (this != NULL);
  6980. return p_no_implicit_inline_templates;
  6981. }
  6982. void
  6983. SgFile::set_no_implicit_inline_templates ( bool no_implicit_inline_templates )
  6984. {
  6985. assert (this != NULL);
  6986. set_isModified(true);
  6987. p_no_implicit_inline_templates = no_implicit_inline_templates;
  6988. }
  6989. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  6990. // End of memberFunctionString
  6991. // Start of memberFunctionString
  6992. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  6993. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  6994. bool
  6995. SgFile::get_skip_commentsAndDirectives () const
  6996. {
  6997. assert (this != NULL);
  6998. return p_skip_commentsAndDirectives;
  6999. }
  7000. void
  7001. SgFile::set_skip_commentsAndDirectives ( bool skip_commentsAndDirectives )
  7002. {
  7003. assert (this != NULL);
  7004. set_isModified(true);
  7005. p_skip_commentsAndDirectives = skip_commentsAndDirectives;
  7006. }
  7007. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7008. // End of memberFunctionString
  7009. // Start of memberFunctionString
  7010. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7011. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7012. bool
  7013. SgFile::get_collectAllCommentsAndDirectives () const
  7014. {
  7015. assert (this != NULL);
  7016. return p_collectAllCommentsAndDirectives;
  7017. }
  7018. void
  7019. SgFile::set_collectAllCommentsAndDirectives ( bool collectAllCommentsAndDirectives )
  7020. {
  7021. assert (this != NULL);
  7022. set_isModified(true);
  7023. p_collectAllCommentsAndDirectives = collectAllCommentsAndDirectives;
  7024. }
  7025. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7026. // End of memberFunctionString
  7027. // Start of memberFunctionString
  7028. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7029. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7030. ROSEAttributesListContainerPtr
  7031. SgFile::get_preprocessorDirectivesAndCommentsList () const
  7032. {
  7033. assert (this != NULL);
  7034. return p_preprocessorDirectivesAndCommentsList;
  7035. }
  7036. void
  7037. SgFile::set_preprocessorDirectivesAndCommentsList ( ROSEAttributesListContainerPtr preprocessorDirectivesAndCommentsList )
  7038. {
  7039. assert (this != NULL);
  7040. set_isModified(true);
  7041. p_preprocessorDirectivesAndCommentsList = preprocessorDirectivesAndCommentsList;
  7042. }
  7043. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7044. // End of memberFunctionString
  7045. // Start of memberFunctionString
  7046. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7047. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7048. AstAttributeMechanism*
  7049. SgFile::get_attributeMechanism () const
  7050. {
  7051. assert (this != NULL);
  7052. return p_attributeMechanism;
  7053. }
  7054. void
  7055. SgFile::set_attributeMechanism ( AstAttributeMechanism* attributeMechanism )
  7056. {
  7057. assert (this != NULL);
  7058. set_isModified(true);
  7059. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  7060. if (p_attributeMechanism != NULL && attributeMechanism != NULL && p_attributeMechanism != attributeMechanism)
  7061. {
  7062. printf ("Warning: attributeMechanism = %p overwriting valid pointer p_attributeMechanism = %p \n",attributeMechanism,p_attributeMechanism);
  7063. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  7064. printf ("Error fails assertion (p_attributeMechanism != NULL && attributeMechanism != NULL && p_attributeMechanism != attributeMechanism) is false\n");
  7065. ROSE_ASSERT(false);
  7066. #endif
  7067. }
  7068. #endif
  7069. p_attributeMechanism = attributeMechanism;
  7070. }
  7071. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7072. // End of memberFunctionString
  7073. // Start of memberFunctionString
  7074. #line 836 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Support.code"
  7075. #if 0
  7076. // DQ (4/10/2006): Removed in favor of implementation at SgNode using
  7077. // a pointer and the interface represented directly at the SgNode
  7078. AstAttributeMechanism &
  7079. SgFile::attribute()
  7080. {
  7081. // DQ (1/2/2006): This function preserves as much of
  7082. // the syntax of attribute being a public data member.
  7083. if (p_attribute == NULL)
  7084. {
  7085. printf ("Error: p_attribute == NULL (node = %s) \n",class_name().c_str());
  7086. ROSE_ASSERT(false);
  7087. }
  7088. return *p_attribute;
  7089. }
  7090. #endif
  7091. void
  7092. SgFile::addNewAttribute( std::string s, AstAttribute* a )
  7093. {
  7094. if (get_attributeMechanism() == NULL)
  7095. {
  7096. set_attributeMechanism( new AstAttributeMechanism() );
  7097. ROSE_ASSERT(get_attributeMechanism() != NULL);
  7098. }
  7099. get_attributeMechanism()->add(s,a);
  7100. }
  7101. void
  7102. SgFile::setAttribute( std::string s, AstAttribute* a )
  7103. {
  7104. if (get_attributeMechanism() == NULL)
  7105. {
  7106. set_attributeMechanism( new AstAttributeMechanism() );
  7107. ROSE_ASSERT(get_attributeMechanism() != NULL);
  7108. }
  7109. get_attributeMechanism()->set(s,a);
  7110. }
  7111. AstAttribute*
  7112. SgFile::getAttribute(std::string s) const
  7113. {
  7114. ROSE_ASSERT(get_attributeMechanism() != NULL);
  7115. AstAttribute* returnValue = get_attributeMechanism()->operator[](s);
  7116. ROSE_ASSERT(returnValue != NULL);
  7117. return returnValue;
  7118. }
  7119. void
  7120. SgFile::updateAttribute( std::string s, AstAttribute* a )
  7121. {
  7122. // formerly called: replace
  7123. ROSE_ASSERT(get_attributeMechanism() != NULL);
  7124. get_attributeMechanism()->replace(s,a);
  7125. }
  7126. void
  7127. SgFile::removeAttribute(std::string s)
  7128. {
  7129. ROSE_ASSERT(get_attributeMechanism() != NULL);
  7130. get_attributeMechanism()->remove(s);
  7131. // DQ (1/2/2006): If we have no more attributes then remove the attribute container
  7132. int remainingCount = numberOfAttributes();
  7133. // printf ("In AstTextAttributesHandling::visit(): remaining number of attributes = %d \n",remainingCount);
  7134. if (remainingCount == 0)
  7135. {
  7136. delete get_attributeMechanism();
  7137. set_attributeMechanism(NULL);
  7138. }
  7139. }
  7140. bool
  7141. SgFile::attributeExists(std::string s) const
  7142. {
  7143. bool returnValue = false;
  7144. if (get_attributeMechanism() != NULL)
  7145. returnValue = get_attributeMechanism()->exists(s);
  7146. return returnValue;
  7147. }
  7148. int
  7149. SgFile::numberOfAttributes() const
  7150. {
  7151. int returnValue = 0;
  7152. if (get_attributeMechanism() != NULL)
  7153. returnValue = get_attributeMechanism()->size();
  7154. return returnValue;
  7155. }
  7156. // End of memberFunctionString
  7157. // Start of memberFunctionString
  7158. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7159. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7160. bool
  7161. SgFile::get_KCC_frontend () const
  7162. {
  7163. assert (this != NULL);
  7164. return p_KCC_frontend;
  7165. }
  7166. void
  7167. SgFile::set_KCC_frontend ( bool KCC_frontend )
  7168. {
  7169. assert (this != NULL);
  7170. set_isModified(true);
  7171. p_KCC_frontend = KCC_frontend;
  7172. }
  7173. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7174. // End of memberFunctionString
  7175. // Start of memberFunctionString
  7176. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7177. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7178. bool
  7179. SgFile::get_new_frontend () const
  7180. {
  7181. assert (this != NULL);
  7182. return p_new_frontend;
  7183. }
  7184. void
  7185. SgFile::set_new_frontend ( bool new_frontend )
  7186. {
  7187. assert (this != NULL);
  7188. set_isModified(true);
  7189. p_new_frontend = new_frontend;
  7190. }
  7191. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7192. // End of memberFunctionString
  7193. // Start of memberFunctionString
  7194. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7195. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7196. bool
  7197. SgFile::get_travTraceToDOT () const
  7198. {
  7199. assert (this != NULL);
  7200. return p_travTraceToDOT;
  7201. }
  7202. void
  7203. SgFile::set_travTraceToDOT ( bool travTraceToDOT )
  7204. {
  7205. assert (this != NULL);
  7206. set_isModified(true);
  7207. p_travTraceToDOT = travTraceToDOT;
  7208. }
  7209. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7210. // End of memberFunctionString
  7211. // Start of memberFunctionString
  7212. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7213. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7214. bool
  7215. SgFile::get_disable_edg_backend () const
  7216. {
  7217. assert (this != NULL);
  7218. return p_disable_edg_backend;
  7219. }
  7220. void
  7221. SgFile::set_disable_edg_backend ( bool disable_edg_backend )
  7222. {
  7223. assert (this != NULL);
  7224. set_isModified(true);
  7225. p_disable_edg_backend = disable_edg_backend;
  7226. }
  7227. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7228. // End of memberFunctionString
  7229. // Start of memberFunctionString
  7230. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7231. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7232. bool
  7233. SgFile::get_disable_sage_backend () const
  7234. {
  7235. assert (this != NULL);
  7236. return p_disable_sage_backend;
  7237. }
  7238. void
  7239. SgFile::set_disable_sage_backend ( bool disable_sage_backend )
  7240. {
  7241. assert (this != NULL);
  7242. set_isModified(true);
  7243. p_disable_sage_backend = disable_sage_backend;
  7244. }
  7245. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7246. // End of memberFunctionString
  7247. // Start of memberFunctionString
  7248. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7249. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7250. int
  7251. SgFile::get_testingLevel () const
  7252. {
  7253. assert (this != NULL);
  7254. return p_testingLevel;
  7255. }
  7256. void
  7257. SgFile::set_testingLevel ( int testingLevel )
  7258. {
  7259. assert (this != NULL);
  7260. set_isModified(true);
  7261. p_testingLevel = testingLevel;
  7262. }
  7263. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7264. // End of memberFunctionString
  7265. // Start of memberFunctionString
  7266. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7267. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7268. bool
  7269. SgFile::get_preinit_il () const
  7270. {
  7271. assert (this != NULL);
  7272. return p_preinit_il;
  7273. }
  7274. void
  7275. SgFile::set_preinit_il ( bool preinit_il )
  7276. {
  7277. assert (this != NULL);
  7278. set_isModified(true);
  7279. p_preinit_il = preinit_il;
  7280. }
  7281. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7282. // End of memberFunctionString
  7283. // Start of memberFunctionString
  7284. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7285. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7286. bool
  7287. SgFile::get_enable_cp_backend () const
  7288. {
  7289. assert (this != NULL);
  7290. return p_enable_cp_backend;
  7291. }
  7292. void
  7293. SgFile::set_enable_cp_backend ( bool enable_cp_backend )
  7294. {
  7295. assert (this != NULL);
  7296. set_isModified(true);
  7297. p_enable_cp_backend = enable_cp_backend;
  7298. }
  7299. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7300. // End of memberFunctionString
  7301. // Start of memberFunctionString
  7302. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7303. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7304. bool
  7305. SgFile::get_outputGrammarTreeFiles () const
  7306. {
  7307. assert (this != NULL);
  7308. return p_outputGrammarTreeFiles;
  7309. }
  7310. void
  7311. SgFile::set_outputGrammarTreeFiles ( bool outputGrammarTreeFiles )
  7312. {
  7313. assert (this != NULL);
  7314. set_isModified(true);
  7315. p_outputGrammarTreeFiles = outputGrammarTreeFiles;
  7316. }
  7317. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7318. // End of memberFunctionString
  7319. // Start of memberFunctionString
  7320. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7321. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7322. bool
  7323. SgFile::get_outputGrammarTreeFilesForHeaderFiles () const
  7324. {
  7325. assert (this != NULL);
  7326. return p_outputGrammarTreeFilesForHeaderFiles;
  7327. }
  7328. void
  7329. SgFile::set_outputGrammarTreeFilesForHeaderFiles ( bool outputGrammarTreeFilesForHeaderFiles )
  7330. {
  7331. assert (this != NULL);
  7332. set_isModified(true);
  7333. p_outputGrammarTreeFilesForHeaderFiles = outputGrammarTreeFilesForHeaderFiles;
  7334. }
  7335. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7336. // End of memberFunctionString
  7337. // Start of memberFunctionString
  7338. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7339. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7340. bool
  7341. SgFile::get_outputGrammarTreeFilesForEDG () const
  7342. {
  7343. assert (this != NULL);
  7344. return p_outputGrammarTreeFilesForEDG;
  7345. }
  7346. void
  7347. SgFile::set_outputGrammarTreeFilesForEDG ( bool outputGrammarTreeFilesForEDG )
  7348. {
  7349. assert (this != NULL);
  7350. set_isModified(true);
  7351. p_outputGrammarTreeFilesForEDG = outputGrammarTreeFilesForEDG;
  7352. }
  7353. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7354. // End of memberFunctionString
  7355. // Start of memberFunctionString
  7356. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7357. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7358. bool
  7359. SgFile::get_markGeneratedFiles () const
  7360. {
  7361. assert (this != NULL);
  7362. return p_markGeneratedFiles;
  7363. }
  7364. void
  7365. SgFile::set_markGeneratedFiles ( bool markGeneratedFiles )
  7366. {
  7367. assert (this != NULL);
  7368. set_isModified(true);
  7369. p_markGeneratedFiles = markGeneratedFiles;
  7370. }
  7371. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7372. // End of memberFunctionString
  7373. // Start of memberFunctionString
  7374. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7375. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7376. bool
  7377. SgFile::get_negative_test () const
  7378. {
  7379. assert (this != NULL);
  7380. return p_negative_test;
  7381. }
  7382. void
  7383. SgFile::set_negative_test ( bool negative_test )
  7384. {
  7385. assert (this != NULL);
  7386. set_isModified(true);
  7387. p_negative_test = negative_test;
  7388. }
  7389. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7390. // End of memberFunctionString
  7391. // Start of memberFunctionString
  7392. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7393. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7394. bool
  7395. SgFile::get_strict_language_handling () const
  7396. {
  7397. assert (this != NULL);
  7398. return p_strict_language_handling;
  7399. }
  7400. void
  7401. SgFile::set_strict_language_handling ( bool strict_language_handling )
  7402. {
  7403. assert (this != NULL);
  7404. set_isModified(true);
  7405. p_strict_language_handling = strict_language_handling;
  7406. }
  7407. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7408. // End of memberFunctionString
  7409. // Start of memberFunctionString
  7410. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7411. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7412. int
  7413. SgFile::get_embedColorCodesInGeneratedCode () const
  7414. {
  7415. assert (this != NULL);
  7416. return p_embedColorCodesInGeneratedCode;
  7417. }
  7418. void
  7419. SgFile::set_embedColorCodesInGeneratedCode ( int embedColorCodesInGeneratedCode )
  7420. {
  7421. assert (this != NULL);
  7422. set_isModified(true);
  7423. p_embedColorCodesInGeneratedCode = embedColorCodesInGeneratedCode;
  7424. }
  7425. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7426. // End of memberFunctionString
  7427. // Start of memberFunctionString
  7428. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7429. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7430. int
  7431. SgFile::get_generateSourcePositionCodes () const
  7432. {
  7433. assert (this != NULL);
  7434. return p_generateSourcePositionCodes;
  7435. }
  7436. void
  7437. SgFile::set_generateSourcePositionCodes ( int generateSourcePositionCodes )
  7438. {
  7439. assert (this != NULL);
  7440. set_isModified(true);
  7441. p_generateSourcePositionCodes = generateSourcePositionCodes;
  7442. }
  7443. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7444. // End of memberFunctionString
  7445. // Start of memberFunctionString
  7446. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7447. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7448. bool
  7449. SgFile::get_sourceFileUsesCppFileExtension () const
  7450. {
  7451. assert (this != NULL);
  7452. return p_sourceFileUsesCppFileExtension;
  7453. }
  7454. void
  7455. SgFile::set_sourceFileUsesCppFileExtension ( bool sourceFileUsesCppFileExtension )
  7456. {
  7457. assert (this != NULL);
  7458. set_isModified(true);
  7459. p_sourceFileUsesCppFileExtension = sourceFileUsesCppFileExtension;
  7460. }
  7461. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7462. // End of memberFunctionString
  7463. // Start of memberFunctionString
  7464. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7465. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7466. bool
  7467. SgFile::get_sourceFileUsesFortranFileExtension () const
  7468. {
  7469. assert (this != NULL);
  7470. return p_sourceFileUsesFortranFileExtension;
  7471. }
  7472. void
  7473. SgFile::set_sourceFileUsesFortranFileExtension ( bool sourceFileUsesFortranFileExtension )
  7474. {
  7475. assert (this != NULL);
  7476. set_isModified(true);
  7477. p_sourceFileUsesFortranFileExtension = sourceFileUsesFortranFileExtension;
  7478. }
  7479. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7480. // End of memberFunctionString
  7481. // Start of memberFunctionString
  7482. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7483. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7484. bool
  7485. SgFile::get_sourceFileUsesFortran77FileExtension () const
  7486. {
  7487. assert (this != NULL);
  7488. return p_sourceFileUsesFortran77FileExtension;
  7489. }
  7490. void
  7491. SgFile::set_sourceFileUsesFortran77FileExtension ( bool sourceFileUsesFortran77FileExtension )
  7492. {
  7493. assert (this != NULL);
  7494. set_isModified(true);
  7495. p_sourceFileUsesFortran77FileExtension = sourceFileUsesFortran77FileExtension;
  7496. }
  7497. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7498. // End of memberFunctionString
  7499. // Start of memberFunctionString
  7500. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7501. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7502. bool
  7503. SgFile::get_sourceFileUsesFortran90FileExtension () const
  7504. {
  7505. assert (this != NULL);
  7506. return p_sourceFileUsesFortran90FileExtension;
  7507. }
  7508. void
  7509. SgFile::set_sourceFileUsesFortran90FileExtension ( bool sourceFileUsesFortran90FileExtension )
  7510. {
  7511. assert (this != NULL);
  7512. set_isModified(true);
  7513. p_sourceFileUsesFortran90FileExtension = sourceFileUsesFortran90FileExtension;
  7514. }
  7515. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7516. // End of memberFunctionString
  7517. // Start of memberFunctionString
  7518. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7519. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7520. bool
  7521. SgFile::get_sourceFileUsesFortran95FileExtension () const
  7522. {
  7523. assert (this != NULL);
  7524. return p_sourceFileUsesFortran95FileExtension;
  7525. }
  7526. void
  7527. SgFile::set_sourceFileUsesFortran95FileExtension ( bool sourceFileUsesFortran95FileExtension )
  7528. {
  7529. assert (this != NULL);
  7530. set_isModified(true);
  7531. p_sourceFileUsesFortran95FileExtension = sourceFileUsesFortran95FileExtension;
  7532. }
  7533. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7534. // End of memberFunctionString
  7535. // Start of memberFunctionString
  7536. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7537. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7538. bool
  7539. SgFile::get_sourceFileUsesFortran2003FileExtension () const
  7540. {
  7541. assert (this != NULL);
  7542. return p_sourceFileUsesFortran2003FileExtension;
  7543. }
  7544. void
  7545. SgFile::set_sourceFileUsesFortran2003FileExtension ( bool sourceFileUsesFortran2003FileExtension )
  7546. {
  7547. assert (this != NULL);
  7548. set_isModified(true);
  7549. p_sourceFileUsesFortran2003FileExtension = sourceFileUsesFortran2003FileExtension;
  7550. }
  7551. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7552. // End of memberFunctionString
  7553. // Start of memberFunctionString
  7554. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  7555. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  7556. SgFile*
  7557. SgFile::get_binaryFile () const
  7558. {
  7559. assert (this != NULL);
  7560. return p_binaryFile;
  7561. }
  7562. void
  7563. SgFile::set_binaryFile ( SgFile* binaryFile )
  7564. {
  7565. assert (this != NULL);
  7566. set_isModified(true);
  7567. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  7568. if (p_binaryFile != NULL && binaryFile != NULL && p_binaryFile != binaryFile)
  7569. {
  7570. printf ("Warning: binaryFile = %p overwriting valid pointer p_binaryFile = %p \n",binaryFile,p_binaryFile);
  7571. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  7572. printf ("Error fails assertion (p_binaryFile != NULL && binaryFile != NULL && p_binaryFile != binaryFile) is false\n");
  7573. ROSE_ASSERT(false);
  7574. #endif
  7575. }
  7576. #endif
  7577. p_binaryFile = binaryFile;
  7578. }
  7579. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  7580. // End of memberFunctionString
  7581. // Start of memberFunctionString
  7582. #line 8972 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Support.code"
  7583. // void unparsestdout();
  7584. // void unparse(std::ostream&);
  7585. //! Declaration of space for static variables
  7586. //static int SgFile::p_defaultNumberOfCommandLineArguments = 0;
  7587. //static char** SgFile::p_defaultCommandLineArgumentList = NULL;
  7588. //! Function prototype of EDG function to set call back function
  7589. void set_sage_transform_function(void (*f)(SgFile *));
  7590. void set_sage_edg_AST_display_function(void (*f)(SgFile *));
  7591. int edg_main(int, char *[], SgFile & sageFile );
  7592. #if 0
  7593. int openFortranParser_main(int, char *[], SgFile & sageFile );
  7594. // DQ (8/12/2007): Declare this locally for now and later put it into the Fortran support directly
  7595. int
  7596. openFortranParser_main(int numberOfArgs, char* commandline[], SgFile & sourceFile )
  7597. {
  7598. printf ("Inside of openFortranParser_main(): numberOfArgs = %d \n",numberOfArgs);
  7599. SgGlobal* globalScope = sourceFile.get_globalScope();
  7600. ROSE_ASSERT(globalScope != NULL);
  7601. // printf ("Global scope = %p number of declarations = %zu \n",globalScope,globalScope->get_declarations().size());
  7602. // sourceFile.display("In openFortranParser");
  7603. printf ("\nCall to Java-based LANL's OpenFortranParser project not implemented \n\n");
  7604. return 0;
  7605. }
  7606. #else
  7607. // This is the "C" function implemented in:
  7608. // ROSE/src/frontend/OpenFortranParser_SAGE_Connection/openFortranParser_main.c
  7609. // This function calls the Java JVM to load the Java implemented parser (written
  7610. // using ANTLR, a parser generator).
  7611. extern "C" int openFortranParser_main(int argc, char **argv );
  7612. // This is how we pass the pointer to the SgFile created in ROSE before the Open
  7613. // Fortran Parser is called to the Open Fortran Parser. In the case of C/C++ using
  7614. // EDG the SgFile is passed through the edg_main() function, but not so with the
  7615. // Open Fortran Parser's openFortranParser_main() function API. So we use this
  7616. // global variable to pass the SgFile (so that the parser c_action functions can
  7617. // build the Fotran AST using the existing SgFile.
  7618. extern SgFile* OpenFortranParser_globalFilePointer;
  7619. #endif
  7620. #if 0
  7621. // DQ (1/18/2006): This is not generated due to the name change of "fileInfo" to "file_info"
  7622. Sg_File_Info*
  7623. SgFile::get_file_info(void) const
  7624. {
  7625. // DQ (1/18/2006): Added function to be match virtual function on SgNode
  7626. // (so that the SgFile's Sg_File_Info object could be accessed).
  7627. return p_fileInfo;
  7628. }
  7629. #endif
  7630. Sg_File_Info*
  7631. SgFile::get_file_info() const
  7632. {
  7633. // This redefines get_file_info() as it is implemented for a SgLocatedNode
  7634. // to use the "get_startOfConstruct()" for consistancy with SgLocatedNode IR nodes.
  7635. return get_startOfConstruct();
  7636. }
  7637. void
  7638. SgFile::set_file_info( Sg_File_Info* fileinfo )
  7639. {
  7640. // This redefines set_file_info() as it is implemented for a SgLocatedNode
  7641. // to use the "set_startOfConstruct()" for consistancy with SgLocatedNode IR nodes.
  7642. set_startOfConstruct(fileinfo);
  7643. }
  7644. std::string
  7645. SgFile::getFileName ()
  7646. {
  7647. // Get the filename from the Sage III file object
  7648. // ROSE_ASSERT(get_fileInfo() != NULL);
  7649. SgScopeStatement *globalScope = (SgScopeStatement *)(&(root()));
  7650. ROSE_ASSERT (globalScope != NULL);
  7651. Sg_File_Info* fileInfo = globalScope->get_file_info();
  7652. ROSE_ASSERT (fileInfo != NULL);
  7653. std::string fileName = fileInfo->get_filenameString();
  7654. return fileName;
  7655. }
  7656. // function prototype
  7657. ROSEAttributesListPtr getPreprocessorDirectives( char *fileName);
  7658. // DQ (2/3/2004): Debugging segfault in use of il_header within ROSE
  7659. // #include "sageCommonSourceHeader.h"
  7660. // extern an_il_header il_header;
  7661. void
  7662. SgFile::setupSourceFilename ( const vector<string>& argv )
  7663. {
  7664. // DQ (4/21/2006): New version of source file name handling (set the source file name early)
  7665. Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(argv);
  7666. if (!fileList.empty())
  7667. {
  7668. ROSE_ASSERT(fileList.size() == 1);
  7669. // DQ (8/31/2006): Convert the source file to have a path if it does not already
  7670. // p_sourceFileNameWithPath = *(fileList.begin());
  7671. string sourceFilename = *(fileList.begin());
  7672. // sourceFilename = StringUtility::getAbsolutePathFromRelativePath(sourceFilename);
  7673. sourceFilename = StringUtility::getAbsolutePathFromRelativePath(sourceFilename, true);
  7674. p_sourceFileNameWithPath = sourceFilename;
  7675. // printf ("In SgFile::setupSourceFilename(int,char**): p_sourceFileNameWithPath = %s \n",p_sourceFileNameWithPath.c_str());
  7676. // This should be an absolute path
  7677. string targetSubstring = "/";
  7678. // if (sourceFilename.substr(0,targetSubstring.size()) != targetSubstring)
  7679. // printf ("@@@@@@@@@@@@@@@@@@@@ In SgFile::setupSourceFilename(int,char**): sourceFilename = %s @@@@@@@@@@@@@@@@@@@@\n",sourceFilename.c_str());
  7680. // ROSE_ASSERT(sourceFilename.substr(0,targetSubstring.size()) == targetSubstring);
  7681. // Rama: 12/06/06: Fixup for problem with file names.
  7682. // Made changes to this file and string utilities function getAbsolutePathFromRelativePath by cloning it with name getAbsolutePathFromRelativePathWithErrors
  7683. // Also refer to script that tests -- reasonably exhaustively -- to various combinarions of input files.
  7684. if (sourceFilename.substr(0,targetSubstring.size()) != targetSubstring)
  7685. printf ("sourceFilename encountered an error in filename\n");
  7686. // DQ (11/29/2006): Even if this is C mode, we have to define the __cplusplus macro
  7687. // is we detect we are processing a source file using the a C++ filename extension.
  7688. string filenameExtension = StringUtility::fileNameSuffix(sourceFilename);
  7689. // if (StringUtility::isCppFileNameSuffix(filenameExtension) == true)
  7690. if (CommandlineProcessing::isCppFileNameSuffix(filenameExtension) == true)
  7691. {
  7692. // This is a C++ file (so define __cplusplus, just like GNU gcc would)
  7693. // set_requires_cplusplus_macro(true);
  7694. set_sourceFileUsesCppFileExtension(true);
  7695. }
  7696. else
  7697. {
  7698. // This a not a C++ file (assume it is a C file and don't define the __cplusplus macro, just like GNU gcc would)
  7699. set_sourceFileUsesCppFileExtension(false);
  7700. }
  7701. p_sourceFileNameWithoutPath = ROSE::stripPathFromFileName(p_sourceFileNameWithPath.c_str());
  7702. }
  7703. else
  7704. {
  7705. // ROSE_ASSERT (p_numberOfSourceFileNames == 0);
  7706. ROSE_ASSERT (p_sourceFileNameWithPath.empty() == true);
  7707. // If no source code file name was found then likely this is a link command
  7708. // using the C++ compiler. In this case skip the EDG processing.
  7709. set_disable_edg_backend(true);
  7710. // printf ("No source file found on command line, assuming to be linker command line \n");
  7711. }
  7712. // Keep the filename stored in the Sg_File_Info consistant. Later we will want to remove this redundency
  7713. // The reason we have the Sg_File_Info object is so that we can easily support filename matching based on
  7714. // the integer values instead of string comparisions.
  7715. get_file_info()->set_filenameString(p_sourceFileNameWithPath);
  7716. }
  7717. void SgFile::doSetupForConstructor(const vector<string>& argv, int& errorCode, int fileNameIndex, SgProject* project) {
  7718. // DQ (4/21/2006): I think we can now assert this! This is an unused function parameter!
  7719. ROSE_ASSERT(fileNameIndex == 0);
  7720. // DQ (5/9/2007): Moved this call down to after where the file name is available so that we could include the filename in the label.
  7721. // DQ (7/6/2005): Introduce tracking of performance of ROSE.
  7722. // TimingPerformance timer ("AST SgFile Constructor:");
  7723. // Set the project early in the construction phase so that we can access data in
  7724. // the parent if needed (useful for template handling but also makes sure the parent is
  7725. // set (and avoids fixup (currently done, but too late in the construction process for
  7726. // the template support).
  7727. if (project != NULL)
  7728. set_parent(project);
  7729. // DQ (5/9/2007): The initialization() should do this, so this should not be required.
  7730. p_root = NULL;
  7731. p_binaryFile = NULL;
  7732. // initalize all local variables to default values
  7733. initialization();
  7734. // DQ (4/21/2006): Setup the source filename as early as possible
  7735. setupSourceFilename(argv);
  7736. // DQ (5/9/2007): Moved this call from above to where the file name is available so that we could include
  7737. // the filename in the label. This helps to identify the performance data with individual files where
  7738. // multiple source files are specificed on the command line.
  7739. // printf ("p_sourceFileNameWithPath = %s \n",p_sourceFileNameWithPath);
  7740. string timerLabel = "AST SgFile Constructor for " + p_sourceFileNameWithPath + ":";
  7741. TimingPerformance timer (timerLabel);
  7742. // Build a DEEP COPY of the input parameters!
  7743. vector<string> local_commandLineArgumentList = argv;
  7744. // Save the commandline as a list of strings (we made a deep copy becasue the "callFrontEnd()" function might change it!
  7745. set_originalCommandLineArgumentList( local_commandLineArgumentList );
  7746. // DQ (5/22/2005): Store the file name index in the SgFile object so that it can figure out
  7747. // which file name applies to it. This helps support functions such as "get_filename()"
  7748. // used elsewhere in Sage III. Not clear if we really need this!
  7749. // p_fileNameIndex = fileNameIndex;
  7750. #if 0
  7751. printf ("In SgFile::SgFile() after initialization: get_skipfinalCompileStep() = %s \n",
  7752. get_skipfinalCompileStep() ? "true" : "false");
  7753. #endif
  7754. // printf ("In SgFile constructor: fileNameIndex = %d \n",fileNameIndex);
  7755. // Store the command line for later use with compiling the unparsed code
  7756. // set_NumberOfCommandLineArguments ( argc );
  7757. // set_CommandLineArgumentList ( argv );
  7758. ROSE_ASSERT (p_root != NULL);
  7759. // error checking
  7760. ROSE_ASSERT (argv.size() > 1);
  7761. // printf ("DONE with copy of command line in SgFile constructor! \n");
  7762. #if 0
  7763. printf ("In SgFile::SgFile() before callFrontEnd(): get_skipfinalCompileStep() = %s \n",
  7764. get_skipfinalCompileStep() ? "true" : "false");
  7765. #endif
  7766. #if 1
  7767. // DQ (10/16/2005): Modified to make clear that argc and argv are not modified
  7768. // Call the EDG fron-end to generate the abstract syntax tree
  7769. // int EDG_FrontEndErrorCode = callFrontEnd ( argc, argv, *this, fileNameIndex );
  7770. // int EDG_FrontEndErrorCode = callFrontEnd ( local_commandLineArgumentList, *this, fileNameIndex );
  7771. // int EDG_FrontEndErrorCode = callFrontEnd ( local_commandLineArgumentList );
  7772. int EDG_FrontEndErrorCode = callFrontEnd();
  7773. // Warning from EDG processing are OK but not errors
  7774. ROSE_ASSERT (EDG_FrontEndErrorCode <= 3);
  7775. errorCode = EDG_FrontEndErrorCode;
  7776. // cout << "EDG/SAGE/ROSE Processing DONE! " << endl;
  7777. #endif
  7778. #if 0
  7779. printf ("In SgFile::SgFile() after callFrontEnd(): get_skipfinalCompileStep() = %s \n",
  7780. get_skipfinalCompileStep() ? "true" : "false");
  7781. #endif
  7782. // DQ (5/24/2005): Fixup the file info information at the SgFile and the global scope (SgGlobal)
  7783. // Opps, SgFile object does not have a Sg_File_Info pointer data member.
  7784. // Sg_File_Info* localfileInfo = new Sg_File_Info(p_sourceFileNamesWithPath[fileNameIndex],0,0);
  7785. // ROSE_ASSERT (localfileInfo != NULL);
  7786. // set_file_info(localfileInfo);
  7787. // DQ (10/15/2005): This has not been converted to a C++ string!
  7788. // DQ (5/24/2005): Now fixup the file info's file name in the global scope!
  7789. // printf ("In SgFile::SgFile p_sourceFileNamesWithPath[%d] = %s \n",fileNameIndex,p_sourceFileNamesWithPath[fileNameIndex]);
  7790. // p_root->get_file_info()->set_filename(p_sourceFileNamesWithPath[fileNameIndex]);
  7791. p_root->get_file_info()->set_filenameString(p_sourceFileNameWithPath);
  7792. // DQ (1/18/2006): Set the filename in the SgFile::p_file_info
  7793. ROSE_ASSERT(get_file_info() != NULL);
  7794. get_file_info()->set_filenameString(p_sourceFileNameWithPath);
  7795. #if 0
  7796. printf ("In SgFile::SgFile(): get_skipfinalCompileStep() = %s \n",
  7797. get_skipfinalCompileStep() ? "true" : "false");
  7798. #endif
  7799. // DQ (5/3/2007): Added assertion.
  7800. ROSE_ASSERT (get_startOfConstruct() != NULL);
  7801. }
  7802. SgFile::SgFile ( int & argc, char** & argv , int & errorCode, int fileNameIndex, SgProject* project )
  7803. // : p_numberOfCommandLineArguments(argc) , p_commandLineArgumentList(NULL)
  7804. {
  7805. // This constructor actually makes the call to EDG to build the AST (via callFrontEnd()).
  7806. ROSE_ASSERT (argv && argc >= 0);
  7807. doSetupForConstructor(vector<string>(argv, argv + argc), errorCode, fileNameIndex, project);
  7808. }
  7809. SgFile::SgFile ( vector<string> & argv , int & errorCode, int fileNameIndex, SgProject* project )
  7810. // : p_numberOfCommandLineArguments(argc) , p_commandLineArgumentList(NULL)
  7811. {
  7812. // This constructor actually makes the call to EDG to build the AST (via callFrontEnd()).
  7813. doSetupForConstructor(argv, errorCode, fileNameIndex, project);
  7814. }
  7815. SgFile::SgFile ()
  7816. {
  7817. // Default constructor
  7818. // This builds a valid SgFile which has no global scope
  7819. // we might make it have a global scope just to support
  7820. // the p_root pointer always being a valid pointer (and
  7821. // the list of declarations being empty).
  7822. // DQ (1/18/2006): uncommented to test loop processing
  7823. // DQ (9/26/2005): We can try to get this constructor working now
  7824. // printf ("This is the default constructor, use SgFile (argc,argv) instead \n");
  7825. // ROSE_ABORT();
  7826. p_root = NULL;
  7827. p_binaryFile = NULL;
  7828. // DQ (10/16/2005): Removed as part of cleanup to SgFile
  7829. // p_numberOfCommandLineArguments = 0;
  7830. // p_commandLineArgumentList = NULL;
  7831. initialization ();
  7832. // DQ (5/15/2006): Note that initialization() builds a SgGlobal but for this
  7833. // default constructor (used in the copy function) we don't want to build one of these.
  7834. // So delete the SgGlobal just built.
  7835. ROSE_ASSERT(p_root != NULL);
  7836. delete p_root;
  7837. p_root = NULL;
  7838. // DQ (10/16/2005): Removed as part of cleanup to SgFile
  7839. // DQ (7/13/2004): Reset the values based on constructor arguments
  7840. // p_numberOfCommandLineArguments = p_defaultNumberOfCommandLineArguments;
  7841. // p_commandLineArgumentList = p_defaultCommandLineArgumentList;
  7842. }
  7843. // DQ (1/17/2006): Added this (copy constructor) to be explicit
  7844. // and avoid difficult bugs where it is compiler generated.
  7845. SgFile::SgFile ( const SgFile & X )
  7846. {
  7847. printf ("Error: calling private copy constructor! \n");
  7848. ROSE_ASSERT(false);
  7849. }
  7850. void
  7851. SgFile::initialization ()
  7852. {
  7853. /* START: List of variables that need to be initialized!
  7854. X SgGlobal* p_root;
  7855. X int p_numberOfCommandLineArguments;
  7856. X char** p_commandLineArgumentList;
  7857. X int p_defaultNumberOfCommandLineArguments;
  7858. X char** p_defaultCommandLineArgumentList;
  7859. X bool p_verbose;
  7860. X bool p_C_only;
  7861. X bool p_outputGrammarTreeFiles;
  7862. X bool p_outputGrammarTreeFilesForEDG;
  7863. X bool p_skip_transformation;
  7864. X bool p_skip_unparse;
  7865. X bool p_outputGrammarTreeFilesForHeaderFiles;
  7866. X bool p_unparse_includes;
  7867. X bool p_KCC_frontend;
  7868. X bool p_new_frontend;
  7869. X bool p_skipfinalCompileStep;
  7870. X bool p_disable_edg_backend;
  7871. X bool p_disable_sage_backend;
  7872. X int p_testingLevel;
  7873. X bool p_preinit_il;
  7874. X bool p_enable_cp_backend;
  7875. X int p_numberOfSourceFileNames;
  7876. X char** p_sourceFileNamesWithPath;
  7877. X char** p_sourceFileNamesWithoutPath;
  7878. X bool p_skip_buildHigherLevelGrammars;
  7879. X char* p_unparse_output_filename;
  7880. X bool p_travTraceToDOT;
  7881. X bool p_useBackendOnly;
  7882. X bool p_compileOnly;
  7883. string p_savedFrontendCommandLine;
  7884. X ROSEAttributesListContainerPtr p_preprocessorDirectivesAndCommentsList;
  7885. END: List of variables that need to be initialized!
  7886. */
  7887. ROSE_ASSERT(this != NULL);
  7888. // This should use a Sg_File_Info with the correct name (maybe this
  7889. // should be initialized by "callFrontEnd()")
  7890. // Sg_File_Info* fileInfo = new Sg_File_Info("SgFile file unknown",0,0);
  7891. // DQ (1/17/2006): Initialize the local file info pointer (this was not previously set!)
  7892. // the name will be reset to the file name later in the construction of the SgFile.
  7893. // set_file_info(new Sg_File_Info (*fileInfo));
  7894. // DQ (12/23/3006): Let the fileInfo be initialized with line 1, column 1 (instead of
  7895. // line 0, column 0). This avoids it failing the test for a valid Sg_File_Info object
  7896. // later (e.g. in fixupSourcePositionInformation.C).
  7897. // DQ (8/31/2006): Generate a NULL_FILE (instead of SgFile::SgFile) so that we can
  7898. // enforce that the filename is always an absolute path (starting with "/").
  7899. // Sg_File_Info* fileInfo = new Sg_File_Info("SgFile::SgFile",0,0);
  7900. // Sg_File_Info* fileInfo = new Sg_File_Info("",0,0);
  7901. Sg_File_Info* fileInfo = new Sg_File_Info("",1,1);
  7902. ROSE_ASSERT(fileInfo != NULL);
  7903. // set_file_info(fileInfo);
  7904. set_startOfConstruct(fileInfo);
  7905. fileInfo->set_parent(this);
  7906. ROSE_ASSERT(get_startOfConstruct() != NULL);
  7907. ROSE_ASSERT(get_file_info() != NULL);
  7908. ROSE_ASSERT (p_root == NULL);
  7909. ROSE_ASSERT (p_binaryFile == NULL);
  7910. // DQ (8/31/2006): Generate a NULL_FILE (instead of SgFile::SgFile) so that we can
  7911. // enforce that the filename is always an absolute path (starting with "/").
  7912. // Sg_File_Info* globalScopeFileInfo = new Sg_File_Info("SgGlobal::SgGlobal",0,0);
  7913. Sg_File_Info* globalScopeFileInfo = new Sg_File_Info("",0,0);
  7914. ROSE_ASSERT (globalScopeFileInfo != NULL);
  7915. p_root = new SgGlobal( globalScopeFileInfo );
  7916. ROSE_ASSERT (p_root != NULL);
  7917. #if 0
  7918. // DQ (1/17/2006): Trying to debug NULL SgFile::get_fileInfo() result
  7919. printf ("Printing out Sg_File_Info object %p in SgFile(%p)::initialization() \n",fileInfo,this);
  7920. fileInfo->display("In SgFile::initialization()");
  7921. get_fileInfo()->display("In SgFile::initialization() calling get_fileInfo()");
  7922. #endif
  7923. // DQ (2/15/2006): Set the parent of the SgGlobal IR node
  7924. p_root->set_parent(this);
  7925. // DQ (4/10/2006): Removed in favor of implementation at SgNode using
  7926. // a pointer and the interface represented directly at the SgNode
  7927. // DQ (1/13/2006): Initialize new AstAttributeMechanism pointer (moved from SgNode)
  7928. p_attributeMechanism = NULL;
  7929. // DQ (10/16/2005): Removed as part of cleanup to SgFile
  7930. // DQ (12/6/2003): initialize these here.
  7931. // p_defaultNumberOfCommandLineArguments = 0;
  7932. // p_defaultCommandLineArgumentList = NULL;
  7933. // DQ (7/13/2004): Not previously initialized (except through constructor preinitialization list)
  7934. // I have removed them from the constructor preinitialization list so that ALL local member data
  7935. // could be set in this inialization function!
  7936. // p_numberOfCommandLineArguments = 0;
  7937. // p_commandLineArgumentList = NULL;
  7938. // DQ (4/7/2001) Added support for multiple files (save the preprocessor
  7939. // directives and comments into the SgFile)
  7940. // the ROSEAttributesListContainer represents all preprocessor
  7941. // declarations and comments from each source file (and its
  7942. // corresponding include files) (thus a list of lists of lists
  7943. // of cpp directives and comments!!!)
  7944. // At construction this is a NULL pointer, it is updated later after construction of the AST.
  7945. p_preprocessorDirectivesAndCommentsList = NULL; // new ROSEAttributesListContainer();
  7946. // ROSE_ASSERT (p_preprocessorDirectivesAndCommentsList != NULL);
  7947. ROSE_ASSERT (p_preprocessorDirectivesAndCommentsList == NULL);
  7948. // DQ (10/15/2005): Don't have a default for this (use an empty string)!
  7949. // p_unparse_output_filename = "rose_unparse.C";
  7950. p_verbose = 0;
  7951. // version = false;
  7952. // help = false;
  7953. // DQ (7/13/2004): Not previously initialized!
  7954. p_C_only = false;
  7955. p_C99_only = false;
  7956. // DQ (8/11/2007): Added support for Fortran
  7957. p_Fortran_only = false;
  7958. p_F77_only = false;
  7959. p_F90_only = false;
  7960. p_F95_only = false;
  7961. p_F2003_only = false;
  7962. p_fixedFormat = false;
  7963. p_outputFormat = SgFile::e_unknown_output_format;
  7964. p_fortran_implicit_none = false;
  7965. p_fortran_openmp = false;
  7966. p_compileOnly = false;
  7967. // After higher level ASTs are build optionally apply transformations
  7968. p_skip_transformation = false;
  7969. p_skip_unparse = false;
  7970. p_outputGrammarTreeFiles = false; // default should be false (set to true while debugging)
  7971. p_outputGrammarTreeFilesForHeaderFiles = false; // default is to skip headers
  7972. // DQ (8/27/2007): Support for alternative langauge code generation (unparsing), useful for testing specific language unparsers.
  7973. p_outputLanguage = SgFile::e_default_output_language;
  7974. // p_new_unparser = true; // by default use the new unparser
  7975. p_unparse_includes = false; // by default do NOT unparse include files into the source code
  7976. p_KCC_frontend = false;
  7977. // Alternatively we can call the new edg frontend to test the edg process
  7978. p_new_frontend = false;
  7979. #if 1
  7980. // The default should be to act like a C++ compiler
  7981. p_skipfinalCompileStep = false;
  7982. #else
  7983. p_skipfinalCompileStep = true;
  7984. #endif
  7985. // controls call to the edg_main (disables all processing
  7986. // and acts like a shell which calls the compiler)
  7987. p_disable_edg_backend = false;
  7988. // Disable parsing of the EDG program tree into the SAGE program tree
  7989. p_disable_sage_backend = false;
  7990. // Shorthand form for different levels of testing (default is -1)
  7991. p_testingLevel = -1;
  7992. // enable processing specific to templates
  7993. p_preinit_il = false;
  7994. p_enable_cp_backend = false;
  7995. // Used to store filenames of input source files
  7996. // p_numberOfSourceFileNames = 0;
  7997. // DQ (10/15/2005): This is now a C++ string (so we can't set these to NULL)
  7998. // p_sourceFileNamesWithPath = NULL;
  7999. // p_sourceFileNamesWithoutPath = NULL;
  8000. // currentDirectory = NULL;
  8001. // Used to trigger building of higher level ASTs
  8002. // p_skip_buildHigherLevelGrammars = false;
  8003. // Support for faster processing of pdf output (where we likely don't need the pdf output of the the EDG AST)
  8004. p_outputGrammarTreeFilesForEDG = false;
  8005. // initialize p_useBackendOnly data member
  8006. p_useBackendOnly = false;
  8007. // DQ (12/6/2003): initialize this here
  8008. p_travTraceToDOT = false;
  8009. // DQ (6/21/2005): initialize g++ specific template instantiation control flags
  8010. p_no_implicit_templates = false;
  8011. p_no_implicit_inline_templates = false;
  8012. // DQ (4/19/2006): Added to control comment and directive handling (takes more time to process header files).
  8013. p_collectAllCommentsAndDirectives = false;
  8014. // Added to permit all comments and CPP directives to be skipped (e.g. when unparsing all hearders)
  8015. p_skip_commentsAndDirectives = false;
  8016. // DQ (9/5/2006): Added mechanism to optionally watermark files generated by ROSE
  8017. p_markGeneratedFiles = false;
  8018. // DQ (9/19/2006): Allow testing of ROSE using input that is expected to fail (return passed if test failed)
  8019. p_negative_test = false;
  8020. // DQ (9/24/2006): Permit optional enforcement of ANSI standards
  8021. p_strict_language_handling = false;
  8022. // DQ (10/31/2006): Output information that can be used to colorize properties of generated code (useful for debugging).
  8023. p_embedColorCodesInGeneratedCode = 0;
  8024. // DQ (10/31/2006): Output separate file containing source position information for highlighting (useful for debugging).
  8025. p_generateSourcePositionCodes = 0;
  8026. // DQ (12/2/2006): This we be used (as in GNU) to set the languge mode (C++ files will turn on C++ language mode
  8027. // and only ".c" (C files) will turn on C language mode).
  8028. p_sourceFileUsesCppFileExtension = false;
  8029. // DQ (10/19/2007): Added initialization new data member added to support handing of binary AST and source code AST.
  8030. p_binaryFile = NULL;
  8031. }
  8032. #if 0
  8033. SgFile::~SgFile()
  8034. {
  8035. // This is the highest level of control for the cleanup of memory
  8036. // allocated as part of the creation of the program tree
  8037. #if 1
  8038. delete p_root;
  8039. p_root = NULL;
  8040. #endif
  8041. // Not ready to delete this yet
  8042. // delete p_preprocessorDirectivesAndCommentsList;
  8043. }
  8044. #endif
  8045. SgGlobal &
  8046. SgFile::root() ROSE_DEPRECATED_FUNCTION
  8047. {
  8048. assert(p_root != NULL);
  8049. return *p_root;
  8050. }
  8051. // DQ (7/19/2005): Added to support better naming of global scope (root is not very clear)
  8052. // get_root() set_root() and root() will be depricated.
  8053. SgGlobal*
  8054. SgFile::get_globalScope() const
  8055. {
  8056. // This variable name will be changed in the future (to globalScope)
  8057. ROSE_ASSERT(p_root != NULL);
  8058. return p_root;
  8059. }
  8060. #if 1
  8061. // function prototype (not required?)
  8062. // int compileOutput ( int & argc, char** & argv );
  8063. int
  8064. SgFile::compileOutput ( int fileNameIndex, const std::string& compilerName )
  8065. {
  8066. // Compile the output file from the unparing
  8067. vector<string> argv = get_originalCommandLineArgumentList();
  8068. ROSE_ASSERT(!argv.empty());
  8069. // DQ (4/21/2006): I think we can now assert this! This is an unused function parameter!
  8070. ROSE_ASSERT(fileNameIndex == 0);
  8071. // DQ (1/17/2006): test this
  8072. // ROSE_ASSERT(get_fileInfo() != NULL);
  8073. // error checking
  8074. ROSE_ASSERT (argv.size() > 1);
  8075. // BP : 10/31/2001, strip out any rose options before passing the command line.
  8076. stripRoseCommandLineOptions( argv );
  8077. // DQ (2/12/2004): strip out edg specific options that
  8078. // would cause an error in the backend compiler.
  8079. stripEdgCommandLineOptions( argv );
  8080. // Call the compile
  8081. int errorCode = compileOutput ( argv, fileNameIndex, compilerName );
  8082. // return the error code from the compilation
  8083. return errorCode;
  8084. }
  8085. #endif
  8086. // function prototype
  8087. // void pdfPrintAbstractSyntaxTreeSage ( SgFile & sageFile, bool writeOutHeaderFiles );
  8088. #if 0
  8089. void
  8090. SgFile::outputPDF ()
  8091. {
  8092. // Output the program tree
  8093. printf ("In SgFile::outputPDF(): Dumping the program tree (AST) to a file \n");
  8094. // Use Markus's new pdf generator
  8095. AstPDFGeneration pdftest;
  8096. pdftest.generateWithinFile(this);
  8097. }
  8098. #endif
  8099. #if 0
  8100. int
  8101. SgFile::get_NumberOfCommandLineArguments()
  8102. {
  8103. ROSE_ASSERT (p_numberOfCommandLineArguments > 0);
  8104. return p_numberOfCommandLineArguments;
  8105. }
  8106. char**
  8107. SgFile::get_CommandLineArgumentList()
  8108. {
  8109. ROSE_ASSERT (p_commandLineArgumentList != NULL);
  8110. return p_commandLineArgumentList;
  8111. }
  8112. #endif
  8113. #if 0
  8114. // These variables are both references and so must be initialized by the constructors
  8115. void
  8116. SgFile::set_NumberOfCommandLineArguments ( int & n )
  8117. {
  8118. ROSE_ASSERT (n > 0);
  8119. p_numberOfCommandLineArguments = n;
  8120. }
  8121. void
  8122. SgFile::set_CommandLineArgumentList ( char** & argv )
  8123. {
  8124. ROSE_ASSERT (argv != NULL);
  8125. p_commandLineArgumentList = argv;
  8126. }
  8127. #endif
  8128. #if 0
  8129. // These can be automatically generated (I think)
  8130. ROSEAttributesListContainer &
  8131. SgFile::get_preprocessorDirectivesAndCommentsList ()
  8132. {
  8133. // assert(i==0);
  8134. // return *p_file;
  8135. ROSE_ASSERT (p_fileList != NULL);
  8136. ROSEAttributesListContainer* targetList = (*p_preprocessorDirectivesAndCommentsList);
  8137. ROSE_ASSERT (targetList != NULL);
  8138. return *targetList;
  8139. }
  8140. void
  8141. SgFile::set_preprocessorDirectivesAndCommentsList ( ROSEAttributesListContainer & directivesList )
  8142. {
  8143. ROSE_ASSERT (p_preprocessorDirectivesAndCommentsList != NULL);
  8144. p_preprocessorDirectivesAndCommentsList->push_back(&directivesList);
  8145. }
  8146. #endif
  8147. #if 0
  8148. void
  8149. roseDisplayMechanism( SgFile *file )
  8150. {
  8151. // This is the function called by EDG if set using the set_sage_transform_function()
  8152. // function. We use it to permit the EDG AST to be dumped out to a file. This
  8153. // step must be done before EDG's AST is deleted and so can't be done when other
  8154. // Sage/ROSE transformations are done (which is now after the EDG AST is released
  8155. // under the new (simplified) interface).
  8156. // This function is called at the point where the EDG program tree has already
  8157. // been parsed into the C++ (modified Sage) grammar but the EDG AST still exists.
  8158. #if ROSE_INTERNAL_DEBUG
  8159. if ( file->get_verbose() > 1 )
  8160. {
  8161. // Find out what file we are doing transformations upon
  8162. printf ("In roseDisplayMechanism: globalSourceFileName = %s \n",file->getFileName());
  8163. }
  8164. #endif
  8165. if (file->get_outputGrammarTreeFiles() == true)
  8166. {
  8167. // Output the program tree
  8168. printf ("## Dumping the program tree (AST) to a file ## \n");
  8169. // Permit the AST for the header files to be output
  8170. // as well (this makes the output files very large)
  8171. bool writeOutHeaderFiles = file->get_outputGrammarTreeFilesForHeaderFiles();
  8172. // Added to speed up processing of large files when we just want the SAGE 3 AST
  8173. bool writeOutEDG_AST = file->get_outputGrammarTreeFilesForEDG();
  8174. // Output the source code file (as represented by the EDG AST) as a PDF file (with bookmarks)
  8175. // Allow this to be off by default since the files generated are so large and most often we just want the SAGE 3 AST
  8176. if (writeOutEDG_AST == true)
  8177. pdfPrintAbstractSyntaxTreeEDG ( file, writeOutHeaderFiles );
  8178. else
  8179. printf ("Skipping output of EDG AST in PDF format (EDG output must be turned on explicitly using commandline option) \n");
  8180. // Output the source code file (as represented by the SAGE AST) as a PDF file (with bookmarks)
  8181. // pdfPrintAbstractSyntaxTreeSage ( file, writeOutHeaderFiles );
  8182. // printf ("Exiting after testing pdf file output of source code! \n");
  8183. // ROSE_ABORT();
  8184. }
  8185. else
  8186. {
  8187. // printf ("## Skip dumping the EDG program tree to a file ## \n");
  8188. }
  8189. }
  8190. #endif
  8191. int
  8192. // SgFile::callFrontEnd ( int & argc, char** & argv, SgFile & sageFile, int fileNameIndex )
  8193. // SgFile::callFrontEnd ( int & argc, char** & argv )
  8194. SgFile::callFrontEnd ()
  8195. {
  8196. // DQ (1/17/2006): test this
  8197. // ROSE_ASSERT(get_fileInfo() != NULL);
  8198. int fileNameIndex = 0;
  8199. // DQ (4/21/2006): I think we can now assert this!
  8200. ROSE_ASSERT(fileNameIndex == 0);
  8201. // DQ (7/6/2005): Introduce tracking of performance of ROSE.
  8202. TimingPerformance timer ("AST Front End Processing (SgFile):");
  8203. // This function processes the command line and calls the EDG frontend.
  8204. int frontendErrorLevel = 0;
  8205. // Build an argc,argv based C style commandline (we might not really need this)
  8206. vector<string> argv = get_originalCommandLineArgumentList();
  8207. #if ROSE_INTERNAL_DEBUG
  8208. if (ROSE_DEBUG > 9)
  8209. {
  8210. // Print out the input arguments, so we can set them up internally instead of
  8211. // on the command line (which is driving me nuts)
  8212. for (unsigned int i=0; i < argv.size(); i++)
  8213. printf ("argv[%d] = %s \n",i,argv[i]);
  8214. }
  8215. #endif
  8216. // printf ("Inside of SgFile::callFrontEnd(): fileNameIndex = %d \n",fileNameIndex);
  8217. // Save this so that it can be used in the template instantiation phase later.
  8218. // This file is later written into the *.ti file so that the compilation can
  8219. // be repeated as required to instantiate all function templates.
  8220. std::string translatorCommandLineString = CommandlineProcessing::generateStringFromArgList(argv,false,true);
  8221. // printf ("translatorCommandLineString = %s \n",translatorCommandLineString.c_str());
  8222. set_savedFrontendCommandLine(translatorCommandLineString);
  8223. // display("At TOP of SgFile::callFrontEnd()");
  8224. // local copies of argc and argv variables
  8225. // The purpose of building local copies is to avoid
  8226. // the modification of the command line by SLA
  8227. vector<string> localCopy_argv = argv;
  8228. // printf ("DONE with copy of command line! \n");
  8229. // Process command line options specific to ROSE
  8230. // This leaves all filenames and non-rose specific option in the argv list
  8231. processRoseCommandLineOptions (localCopy_argv);
  8232. // DQ (6/21/2005): Process template specific options so that we can generated
  8233. // code for the backend compiler (this processing is backend specific).
  8234. processBackendSpecificCommandLineOptions (localCopy_argv);
  8235. // display("AFTER processRoseCommandLineOptions in SgFile::callFrontEnd()");
  8236. // Use ROSE buildCommandLine() function
  8237. // int numberOfCommandLineArguments = 24;
  8238. // char** inputCommandLine = new char* [numberOfCommandLineArguments];
  8239. // ROSE_ASSERT (inputCommandLine != NULL);
  8240. vector<string> inputCommandLine;
  8241. // Build the commandline for EDG
  8242. build_EDG_CommandLine (inputCommandLine,localCopy_argv,fileNameIndex );
  8243. // DQ (10/15/2005): This is now a single C++ string (and not a list)
  8244. // Make sure the list of file names is allocated, even if there are no file names in the list.
  8245. // DQ (1/23/2004): I wish that C++ string objects had been used uniformally through out this code!!!
  8246. // ROSE_ASSERT (get_sourceFileNamesWithoutPath() != NULL);
  8247. // ROSE_ASSERT (get_sourceFileNameWithoutPath().empty() == false);
  8248. // display("AFTER build_EDG_CommandLine in SgFile::callFrontEnd()");
  8249. // Exit if we are to ONLY call the vendor's backend compiler
  8250. if (p_useBackendOnly == true)
  8251. return 0;
  8252. ROSE_ASSERT (p_useBackendOnly == false);
  8253. // DQ (4/21/2006): If we have called the frontend for this SgFile then mark this file to be unparsed.
  8254. // This will cause code to be generated and the compileOutput() function will then set the name of
  8255. // the file that the backend (vendor) compiler will compile to be the the intermediate file. Else it
  8256. // will be set to be the origianl source file. In the new design, the frontendShell() can be called
  8257. // to generate just the SgProject and SgFile nodes and we can loop over the SgFile objects and call
  8258. // the frontend separately for each SgFile. so we have to set the output file name to be compiled
  8259. // late in the processing (at backend compile time since we don't know when or if the frontend will
  8260. // be called for each SgFile).
  8261. set_skip_unparse(false);
  8262. #if 0
  8263. // DQ (2/13/2004): This is no longer used!!!
  8264. // This sets up a "call back" function.
  8265. // This function sets a function pointer internal to SAGE (EDG sage_gen_be.C) which
  8266. // is called by the sage processing after the EDG AST is translated into the SAGE AST.
  8267. // The alternative would be to have the generation of the EDG PDF file be generated as
  8268. // an option to EDG, but this would requirre the addition of the PDF headers to EDG which
  8269. // I would like to avoid (I want to avoid modifying EDG if possible).
  8270. // set_sage_transform_function(roseDisplayMechanism);
  8271. // set_sage_edg_AST_display_function(roseDisplayMechanism);
  8272. // DQ (4/23/2006): Declaration of friend function required here by g++ 4.1.0!
  8273. void alternativeSageEdgInterfaceConstruction( SgFile *file );
  8274. set_sage_transform_function(alternativeSageEdgInterfaceConstruction);
  8275. #endif
  8276. // DQ (1/22/2004): As I recall this has a name that really
  8277. // should be "disable_edg" instead of "disable_edg_backend".
  8278. if ( get_disable_edg_backend() == false )
  8279. {
  8280. // ROSE::new_frontend = true;
  8281. // We can either use the newest EDG frontend separately (useful for debugging)
  8282. // or the EDG frontend that is included in SAGE III (currently EDG 3.3).
  8283. // New EDG frontend:
  8284. // This permits testing with the most up-to-date version of the EDG frontend and
  8285. // can be useful in identifing errors or bugs in the SAGE processing (or ROSE itself).
  8286. // EDG frontend used by SAGE III:
  8287. // The use of this frontend permits the continued processing via ROSE and the
  8288. // unparsing of the AST to rebuilt the C++ source code (with transformations if any
  8289. // were done).
  8290. // DQ (10/15/2005): This is now a C++ string (and not char* C style string)
  8291. // Make sure that we have generated a proper file name (or move filename
  8292. // processing to processRoseCommandLineOptions()).
  8293. // printf ("Print out the file name to make sure it is processed \n");
  8294. // printf (" filename = %s \n",get_unparse_output_filename());
  8295. // ROSE_ASSERT (get_unparse_output_filename() != NULL);
  8296. // ROSE_ASSERT (get_unparse_output_filename().empty() == false);
  8297. std::string edgFrontEndCommandLineString;
  8298. if ( get_new_frontend() == true )
  8299. {
  8300. // Use the current version of the EDG frontend from EDG (or any other version)
  8301. printf ("ROSE::new_frontend == true (call edgFrontEnd using unix system() function!) \n");
  8302. if ( get_KCC_frontend() == true )
  8303. {
  8304. edgFrontEndCommandLineString = "KCC "; // -cpfe_only is no longer supported (I think)
  8305. }
  8306. else
  8307. {
  8308. edgFrontEndCommandLineString = "edgFrontEnd ";
  8309. }
  8310. edgFrontEndCommandLineString += CommandlineProcessing::generateStringFromArgList(inputCommandLine,true,false);
  8311. if ( get_verbose() > 1 )
  8312. printf ("edgFrontEndCommandLineString = %s \n",edgFrontEndCommandLineString.c_str());
  8313. system(edgFrontEndCommandLineString.c_str());
  8314. // exit(0);
  8315. }
  8316. else
  8317. {
  8318. // Call the "INTERNAL" EDG Front End used by ROSE (with modified command
  8319. // line input so that ROSE's command line is simplified)!
  8320. if ( get_verbose() > 1 )
  8321. printf ("Calling edg_main \n");
  8322. #if 0
  8323. edgFrontEndCommandLineString = std::string(argv[0]) + std::string(" ") + CommandlineProcessing::generateStringFromArgList(inputCommandLine,false,false);
  8324. if ( get_verbose() > 1 )
  8325. printf ("edgFrontEndCommandLineString = %s \n",edgFrontEndCommandLineString.c_str());
  8326. #endif
  8327. // We need to detect errors in this stage so that we can prevent further processing
  8328. // int edg_errorLevel = edg_main (numberOfCommandLineArguments, inputCommandLine,sageFile);
  8329. // int edg_errorLevel = edg_main (numberOfCommandLineArguments, inputCommandLine,*this);
  8330. // int frontendErrorLevel = 0;
  8331. #if 0
  8332. printf ("get_C_only() = %s \n",(get_C_only() == true) ? "true" : "false");
  8333. printf ("get_C99_only() = %s \n",(get_C99_only() == true) ? "true" : "false");
  8334. printf ("get_Fortran_only() = %s \n",(get_Fortran_only() == true) ? "true" : "false");
  8335. printf ("get_F77_only() = %s \n",(get_F77_only() == true) ? "true" : "false");
  8336. printf ("get_F90_only() = %s \n",(get_F90_only() == true) ? "true" : "false");
  8337. printf ("get_F95_only() = %s \n",(get_F95_only() == true) ? "true" : "false");
  8338. printf ("get_F2003_only() = %s \n",(get_F2003_only() == true) ? "true" : "false");
  8339. #endif
  8340. if (get_Fortran_only() == true)
  8341. {
  8342. // frontendErrorLevel = openFortranParser_main (numberOfCommandLineArguments, inputCommandLine,*this);
  8343. // printf ("Calling the openFortranParser_main() function (which loads the JVM) \n");
  8344. // DQ (9/30/2007): Introduce syntax checking on input code (initially we can just call the backend compiler
  8345. // and let it report on the syntax errors). Later we can make this a command line switch to disable (default
  8346. // should be true).
  8347. bool syntaxCheckInputCode = true;
  8348. if (syntaxCheckInputCode == true)
  8349. {
  8350. // DQ (9/30/2007): Introduce tracking of performance of ROSE.
  8351. TimingPerformance timer ("Fortran syntax checking of input:");
  8352. // DQ (9/30/2007): For Fortran, we want to run gfortran up front so that we can verify that
  8353. // the input file is syntax error free. First lets see what data is avilable to use to check
  8354. // that we have a fortran file.
  8355. // display("Before calling OpenFortranParser, what are the values in the SgFile");
  8356. // DQ (9/30/2007): Call the backend Fortran compiler (typically gfortran) to check the syntax
  8357. // of the input program. When using GNU gfortran, use the "-S" option which means:
  8358. // "Compile only; do not assemble or link".
  8359. string syntaxCheckingCommandline = "gfortran -S " + get_sourceFileNameWithPath();
  8360. printf ("Checking syntax of input program using gfortran: syntaxCheckingCommandline = %s \n",syntaxCheckingCommandline.c_str());
  8361. // Call the OS with the commandline defined by: syntaxCheckingCommandline
  8362. int returnValueForSyntaxCheckUsingBackendCompiler = system (syntaxCheckingCommandline.c_str());
  8363. // Check that there are no errors, I think that warnings are ignored!
  8364. if (returnValueForSyntaxCheckUsingBackendCompiler != 0)
  8365. {
  8366. printf ("Syntax errors detected in input problem ... \n");
  8367. exit(1);
  8368. }
  8369. ROSE_ASSERT(returnValueForSyntaxCheckUsingBackendCompiler == 0);
  8370. }
  8371. // edgFrontEndCommandLineString = std::string(argv[0]) + std::string(" --class parser.java.FortranParserActionJNI ") + CommandlineProcessing::generateStringFromArgcArgv(numberOfCommandLineArguments,(const char**)inputCommandLine,false,false);
  8372. // edgFrontEndCommandLineString = "xxx --class parser.java.FortranParserActionJNI /home/dquinlan/ROSE/NEW_ROSE/developersScratchSpace/Dan/Fortran_tests/test2007_01.f90";
  8373. // edgFrontEndCommandLineString = "--dump /home/dquinlan/ROSE/NEW_ROSE/developersScratchSpace/Dan/Fortran_tests/test2007_01.f90";
  8374. // edgFrontEndCommandLineString = std::string(argv[0]) + " --class parser.java.FortranParserActionJNI /home/dquinlan/ROSE/NEW_ROSE/developersScratchSpace/Dan/Fortran_tests/test2007_01.f90";
  8375. edgFrontEndCommandLineString = std::string(argv[0]) + " --class parser.java.FortranParserActionJNI " + get_sourceFileNameWithPath();
  8376. if ( get_verbose() > -1 )
  8377. printf ("numberOfCommandLineArguments = %zu edgFrontEndCommandLineString = %s \n",inputCommandLine.size(),edgFrontEndCommandLineString.c_str());
  8378. int openFortranParser_argc = 0;
  8379. char** openFortranParser_argv = NULL;
  8380. CommandlineProcessing::generateArgcArgvFromList(CommandlineProcessing::generateArgListFromString(edgFrontEndCommandLineString),openFortranParser_argc,openFortranParser_argv);
  8381. // printf ("openFortranParser_argc = %d openFortranParser_argv = %s \n",openFortranParser_argc,CommandlineProcessing::generateStringFromArgList(openFortranParser_argv,false,false).c_str());
  8382. // DQ (8/19/2007): Setup the global pointer used to pass the SgFile to which the Open Fortran Parser
  8383. // should attach the AST. This is a bit ugly, but the parser interface only takes a commandline so it
  8384. // would be more ackward to pass a pointer to a C++ object through the commandline or the Java interface.
  8385. OpenFortranParser_globalFilePointer = const_cast<SgFile*>(this);
  8386. ROSE_ASSERT(OpenFortranParser_globalFilePointer != NULL);
  8387. printf ("Calling openFortranParser_main(): OpenFortranParser_globalFilePointer = %p \n",OpenFortranParser_globalFilePointer);
  8388. // frontendErrorLevel = openFortranParser_main (numberOfCommandLineArguments, inputCommandLine);
  8389. frontendErrorLevel = openFortranParser_main (openFortranParser_argc, openFortranParser_argv);
  8390. printf ("DONE: Calling the openFortranParser_main() function (which loads the JVM) \n");
  8391. // Reset this global pointer after we are done (just to be safe and avoid it being used later and causing strange bugs).
  8392. OpenFortranParser_globalFilePointer = NULL;
  8393. }
  8394. else
  8395. {
  8396. edgFrontEndCommandLineString = std::string(argv[0]) + std::string(" ") + CommandlineProcessing::generateStringFromArgList(inputCommandLine,false,false);
  8397. if ( get_verbose() > 1 )
  8398. printf ("edgFrontEndCommandLineString = %s \n",edgFrontEndCommandLineString.c_str());
  8399. int edg_argc = 0;
  8400. char **edg_argv = NULL;
  8401. CommandlineProcessing::generateArgcArgvFromList(inputCommandLine, edg_argc, edg_argv);
  8402. frontendErrorLevel = edg_main (edg_argc, edg_argv, *this);
  8403. }
  8404. if ( get_verbose() > 1 )
  8405. printf ("DONE: frontend called (frontendErrorLevel = %d) \n",frontendErrorLevel);
  8406. // If we had any errors reporte by the EDG frontend then quite now
  8407. if (frontendErrorLevel > 3)
  8408. {
  8409. // cout << "Errors in EDG Processing: (edg_errorLevel > 3)" << endl;
  8410. if ( get_verbose() > 1 )
  8411. printf ("frontendErrorLevel = %d \n",frontendErrorLevel);
  8412. // DQ (9/22/2006): We need to invert the test result (return code) for
  8413. // negative tests (where failure is expected and success is an error).
  8414. if (get_negative_test() == true)
  8415. {
  8416. if ( get_verbose() > 1 )
  8417. {
  8418. printf ("(evaluation of frontend results) This is a negative tests, so an error in compilation is a PASS but a successful \n");
  8419. printf ("compilation is not a FAIL since the faulure might happen in the compilation of the generated code by the vendor compiler. \n");
  8420. }
  8421. exit(0);
  8422. }
  8423. else
  8424. {
  8425. // Exit because there are errors in the input program
  8426. cout << "Errors in EDG Processing: (frontendErrorLevel > 3)" << endl;
  8427. ROSE_ABORT();
  8428. }
  8429. }
  8430. // if there are warnings report that there are in the verbose mode and continue
  8431. if (frontendErrorLevel > 0)
  8432. {
  8433. if ( get_verbose() >= 1 )
  8434. cout << "Warnings in Rose parser/IR translation processing! (continuing ...) " << endl;
  8435. }
  8436. }
  8437. }
  8438. // DQ (4/20/2006): This code was moved from the SgFile constructor so that is would
  8439. // permit the separate construction of the SgProject and call to the front-end cleaner.
  8440. // DQ (5/22/2005): This is a older function with a newer more up-to-date comment on why we have it.
  8441. // This function is a repository for minor AST fixups done as a post-processing step in the
  8442. // construction of the Sage III AST from the EDG frontend. In some cases it fixes specific
  8443. // problems in either EDG or the translation of EDG to Sage III (more the later than the former).
  8444. // In other cases if does post-processing (e.g. setting parent pointers in the AST) can could
  8445. // only done from a more complete global view of the staticly defined AST. In many cases these
  8446. // AST fixups are not so temporary so the name of the function might change at some point.
  8447. // Notice that all AST fixup is done before attachment of the comments to the AST.
  8448. // temporaryAstFixes(this);
  8449. AstPostProcessing(this);
  8450. // This is set in the unparser now so that we can handle the source file plus all header files
  8451. ROSE_ASSERT (p_preprocessorDirectivesAndCommentsList == NULL);
  8452. // Build the empty list container so that we can just add lists for new files as they are encountered
  8453. p_preprocessorDirectivesAndCommentsList = new ROSEAttributesListContainer();
  8454. ROSE_ASSERT (p_preprocessorDirectivesAndCommentsList != NULL);
  8455. // DQ (4/19/2006): since they can take a while and includes substantial
  8456. // file I/O we make this optional (selected from the command line).
  8457. // bool collectAllCommentsAndDirectives = get_collectAllCommentsAndDirectives();
  8458. // DQ (4/19/2006): attachAllPreprocessingInfo() is now merged into the attachPreprocessingInfo()
  8459. // function.
  8460. // DQ (4/6/2006): This is also the correct function to call to use Wave.
  8461. // Markus Kowarschik: attach preprocessor directives to AST nodes
  8462. // This uses the AST traversal and so needs to be done after the
  8463. // call to temporaryAstFixes(), above.
  8464. if (get_skip_commentsAndDirectives() == false)
  8465. {
  8466. if (get_verbose() > 1)
  8467. {
  8468. printf ("In SgFile::callFrontEnd(): calling attachAllPreprocessingInfo() \n");
  8469. }
  8470. attachPreprocessingInfo(this);
  8471. if (get_verbose() > 1)
  8472. {
  8473. printf ("In SgFile::callFrontEnd(): Done with attachAllPreprocessingInfo() \n");
  8474. }
  8475. }
  8476. // DQ (4/11/2006): This is Lingxiao's work (new patch, since the first and second attempts didn't work)
  8477. // to support attaching comments from all header files to the AST. It seems that both
  8478. // attachPreprocessingInfo() and attachAllPreprocessingInfo() can be run as a mechanism to test
  8479. // Lingxiao's work on at least the source file. Note that performance associated with collecting
  8480. // all comments and CPP directives from header files might be a problem.
  8481. // DQ (4/1/2006): This will have to be fixed a little later (next release)
  8482. // DQ (3/29/2006): This is Lingxiao's work to support attaching comments from all header files to the
  8483. // AST (the previous mechanism only extracted comments from the source file and atted them to the AST,
  8484. // the part of the AST representing the input source file).
  8485. // attachAllPreprocessingInfo(this,collectAllCommentsAndDirectives);
  8486. // display("At bottom of SgFile::callFrontEnd()");
  8487. // return the error code associated with the call to the C++ Front-end
  8488. return frontendErrorLevel;
  8489. }
  8490. void
  8491. SgFile::stripRoseCommandLineOptions ( vector<string>& argv )
  8492. {
  8493. // Strip out the rose specific commandline options
  8494. // the assume all other arguments are to be passed onto the C or C++ compiler
  8495. int optionCount = 0;
  8496. // int i = 0;
  8497. #if ROSE_INTERNAL_DEBUG
  8498. // printf ("ROSE_DEBUG = %d \n",ROSE_DEBUG);
  8499. // printf ("get_verbose() = %s value = %d \n",(get_verbose() > 1) ? "true" : "false",get_verbose());
  8500. if ( (ROSE_DEBUG >= 1) || (get_verbose() > 2 )
  8501. {
  8502. printf ("In stripRoseCommandLineOptions: List ALL arguments: argc = %zu \n",argv.size());
  8503. for (size_t i=0; i < argv.size(); i++)
  8504. printf (" argv[%d] = %s \n",i,argv[i]);
  8505. }
  8506. #endif
  8507. // Split out the ROSE options first
  8508. // Use 1 at end of argument list to SLA to force removal of option from argv and decrement of agrc
  8509. optionCount = sla(argv, "-" , "($)", "(h|help)",1);
  8510. optionCount = sla(argv, "-rose:", "($)", "(h|help)",1);
  8511. optionCount = sla(argv, "-rose:", "($)", "(V|version)", 1);
  8512. // optionCount = sla(argv, "-rose:", "($)", "(v|verbose)",1);
  8513. int integerOption = 0;
  8514. optionCount = sla(argv, "-rose:", "($)^", "(v|verbose)", &integerOption, 1);
  8515. optionCount = sla(argv, "-rose:", "($)", "(C|C_only)",1);
  8516. optionCount = sla(argv, "-rose:", "($)", "(C99|C99_only)",1);
  8517. // DQ (8/11/2007): Support for Fortran and its different flavors
  8518. optionCount = sla(argv, "-rose:", "($)", "(f|F|Fortran)",1);
  8519. optionCount = sla(argv, "-rose:", "($)", "(f77|F77|Fortran77)",1);
  8520. optionCount = sla(argv, "-rose:", "($)", "(f90|F90|Fortran90)",1);
  8521. optionCount = sla(argv, "-rose:", "($)", "(f95|F95|Fortran95)",1);
  8522. optionCount = sla(argv, "-rose:", "($)", "(f2003|F2003|Fortran2003)",1);
  8523. // DQ (8/27/2007):Support for Fortran language output format
  8524. optionCount = sla(argv, "-rose:", "($)", "(fixedOutput|fixedFormatOutput)",1);
  8525. optionCount = sla(argv, "-rose:", "($)", "(freeOutput|freeFormatOutput)",1);
  8526. optionCount = sla(argv, "-rose:", "($)", "(C_output_language|Cxx_output_language|Fortran_output_language|Promela_output_language)",1);
  8527. // DQ (5/19/2005): The output file name is constructed from the input source name (as I recall)
  8528. // optionCount = sla(argv, "-rose:", "($)^", "(o|output)", &p_unparse_output_filename ,1);
  8529. optionCount = sla(argv, "-rose:", "($)", "(skip_rose)",1);
  8530. optionCount = sla(argv, "-rose:", "($)", "(skip_transformation)",1);
  8531. optionCount = sla(argv, "-rose:", "($)", "(skip_unparse)",1);
  8532. optionCount = sla(argv, "-rose:", "($)", "(unparse_includes)",1);
  8533. optionCount = sla(argv, "-rose:", "($)", "(collectAllCommentsAndDirectives)",1);
  8534. optionCount = sla(argv, "-rose:", "($)", "(skip_commentsAndDirectives)",1);
  8535. optionCount = sla(argv, "-rose:", "($)", "(skipfinalCompileStep)",1);
  8536. optionCount = sla(argv, "-rose:", "($)", "(prelink)",1);
  8537. optionCount = sla(argv, "-" , "($)", "(ansi)",1);
  8538. optionCount = sla(argv, "-rose:", "($)", "(markGeneratedFiles)",1);
  8539. optionCount = sla(argv, "-rose:", "($)", "(negative_test)",1);
  8540. integerOption = 0;
  8541. optionCount = sla(argv, "-rose:", "($)^", "(embedColorCodesInGeneratedCode)", &integerOption, 1);
  8542. optionCount = sla(argv, "-rose:", "($)^", "(generateSourcePositionCodes)", &integerOption, 1);
  8543. optionCount = sla(argv, "-rose:", "($)", "(outputGrammarTreeFiles)",1);
  8544. optionCount = sla(argv, "-rose:", "($)", "(outputGrammarTreeFilesForHeaderFiles)",1);
  8545. optionCount = sla(argv, "-rose:", "($)", "(outputGrammarTreeFilesForEDG)",1);
  8546. optionCount = sla(argv, "-rose:", "($)", "(new_unparser)",1);
  8547. optionCount = sla(argv, "-rose:", "($)", "(negative_test)",1);
  8548. optionCount = sla(argv, "-rose:", "($)", "(strict)",1);
  8549. integerOption = 0;
  8550. optionCount = sla(argv, "-rose:", "($)^", "test", &integerOption, 1);
  8551. optionCount = sla(argv, "-rose:", "($)", "(skipfinalCompileStep)",1);
  8552. optionCount = sla(argv, "-rose:", "($)", "(prelink)",1);
  8553. char* templateInstationationOption = NULL;
  8554. optionCount = sla(argv, "-rose:", "($)^", "(instantiation)",templateInstationationOption,1);
  8555. // DQ (6/17/2005): Added support for AST merging (sharing common parts of the AST most often represented in common header files of a project)
  8556. optionCount = sla(argv, "-rose:", "($)", "(astMerge)",1);
  8557. char* filename = NULL;
  8558. optionCount = sla(argv, "-rose:", "($)^", "(astMergeCommandFile)",filename,1);
  8559. optionCount = sla(argv, "-rose:", "($)^", "(compilationPerformanceFile)",filename,1);
  8560. //AS(093007) Remove paramaters relating to excluding and include comments and directives
  8561. optionCount = sla(argv, "-rose:", "($)^", "(excludeCommentsAndDirectives)", &integerOption, 1);
  8562. optionCount = sla(argv, "-rose:", "($)^", "(excludeCommentsAndDirectivesFrom)", &integerOption, 1);
  8563. optionCount = sla(argv, "-rose:", "($)^", "(includeCommentsAndDirectives)", &integerOption, 1);
  8564. optionCount = sla(argv, "-rose:", "($)^", "(includeCommentsAndDirectivesFrom)", &integerOption, 1);
  8565. }
  8566. void
  8567. SgFile::stripEdgCommandLineOptions ( vector<string> & argv )
  8568. {
  8569. // Strip out the EDG specific commandline options the assume all
  8570. // other arguments are to be passed onto the C or C++ compiler
  8571. #if 0
  8572. if ( (ROSE_DEBUG >= 0) || (get_verbose() > 1) )
  8573. {
  8574. Rose_STL_Container<string> l = CommandlineProcessing::generateArgListFromArgcArgv (argc,argv);
  8575. printf ("In SgFile::stripEdgCommandLineOptions: argv = \n%s \n",StringUtility::listToString(l).c_str());
  8576. }
  8577. #endif
  8578. // Split out the EDG options (ignore the returned Rose_STL_Container<string> object)
  8579. CommandlineProcessing::removeArgs (argv,"-edg:");
  8580. CommandlineProcessing::removeArgs (argv,"--edg:");
  8581. CommandlineProcessing::removeArgsWithParameters (argv,"-edg_parameter:");
  8582. CommandlineProcessing::removeArgsWithParameters (argv,"--edg_parameter:");
  8583. #if 0
  8584. Rose_STL_Container<string> l = CommandlineProcessing::generateArgListFromArgcArgv (argc,argv);
  8585. printf ("In SgFile::stripEdgCommandLineOptions: argv = \n%s \n",StringUtility::listToString(l).c_str());
  8586. printf ("Exiting in stripEdgCommandLineOptions() \n");
  8587. ROSE_ASSERT (1 == 2);
  8588. #endif
  8589. }
  8590. void
  8591. SgFile::processRoseCommandLineOptions ( vector<string> & argv )
  8592. {
  8593. // Strip out the rose specific command line options
  8594. // then search for all filenames (options without the "-" prefix)
  8595. // the assume all other arguments are to be passed onto the C or C++ compiler
  8596. // int optionCount = 0;
  8597. // int i = 0;
  8598. // DQ (1/17/2006): test this
  8599. // ROSE_ASSERT(get_fileInfo() != NULL);
  8600. // Split out the ROSE options first
  8601. // printf ("Before processing ROSE options argc = %d \n",argc);
  8602. //
  8603. // help option (allows alternative -h or -help instead of just -rose:help)
  8604. // This is the only rose options that does not require the "-rose:" prefix
  8605. //
  8606. if ( CommandlineProcessing::isOption(argv,"-rose:","(h|help)",true) == true ||
  8607. CommandlineProcessing::isOption(argv,"--", "(h|help)",true) == true ||
  8608. CommandlineProcessing::isOption(argv,"-","(h|help)",true) == true )
  8609. {
  8610. printf ("\nROSE (pre-release alpha version: %s) \n",VERSION);
  8611. // ROSE::usage(0);
  8612. usage(0);
  8613. // exit(0);
  8614. }
  8615. //
  8616. // version option
  8617. //
  8618. if ( CommandlineProcessing::isOption(argv,"-rose:","(V|version)",true) == true )
  8619. {
  8620. // function in SAGE III to access version number of EDG
  8621. extern std::string edgVersionString();
  8622. printf ("\nROSE (pre-release alpha version: %s) \n",VERSION);
  8623. printf (" Using C++ and C frontend from EDG (version %s) internally \n",edgVersionString().c_str());
  8624. }
  8625. //
  8626. // markGeneratedFiles option
  8627. //
  8628. set_markGeneratedFiles(false);
  8629. if ( CommandlineProcessing::isOption(argv,"-rose:","(markGeneratedFiles)",true) == true )
  8630. {
  8631. // Optionally mark the generated files with "#define ROSE_GENERATED_CODE"
  8632. set_markGeneratedFiles(true);
  8633. }
  8634. //
  8635. // embedColorCodesInGeneratedCode option
  8636. //
  8637. int integerOptionForEmbedColorCodesInGeneratedCode = 0;
  8638. if ( CommandlineProcessing::isOptionWithParameter(argv,"-rose:","(embedColorCodesInGeneratedCode)",integerOptionForEmbedColorCodesInGeneratedCode,true) == true )
  8639. {
  8640. printf ("Calling set_embedColorCodesInGeneratedCode(%d) \n",integerOptionForEmbedColorCodesInGeneratedCode);
  8641. set_embedColorCodesInGeneratedCode(integerOptionForEmbedColorCodesInGeneratedCode);
  8642. }
  8643. //
  8644. // generateSourcePositionCodes option
  8645. //
  8646. int integerOptionForGenerateSourcePositionCodes = 0;
  8647. if ( CommandlineProcessing::isOptionWithParameter(argv,"-rose:","(generateSourcePositionCodes)",integerOptionForGenerateSourcePositionCodes,true) == true )
  8648. {
  8649. printf ("Calling set_generateSourcePositionCodes(%d) \n",integerOptionForGenerateSourcePositionCodes);
  8650. set_generateSourcePositionCodes(integerOptionForGenerateSourcePositionCodes);
  8651. }
  8652. //
  8653. // verbose option
  8654. //
  8655. // DQ (4/20/2006): This can already be set (to none zero value) if the SgProject was previously build already (see tutorial/selectedFileTranslation.C)
  8656. // ROSE_ASSERT (get_verbose() == 0);
  8657. // if ( CommandlineProcessing::isOption(argv,"-rose:","(v|verbose)",true) )
  8658. int integerOptionForVerbose = 0;
  8659. if ( CommandlineProcessing::isOptionWithParameter(argv,"-rose:","(v|verbose)",integerOptionForVerbose,true) == true )
  8660. {
  8661. // set_verbose(true);
  8662. set_verbose(integerOptionForVerbose);
  8663. // DQ (8/12/2004): The semantics is to set the global concept of a value
  8664. // for verbose to the maximum of that from the individual files.
  8665. if (SgProject::get_verbose() < integerOptionForVerbose)
  8666. SgProject::set_verbose(integerOptionForVerbose);
  8667. if ( SgProject::get_verbose() >= 1 )
  8668. printf ("verbose mode ON \n");
  8669. }
  8670. //
  8671. // C only option (turns on EDG "--c" option and g++ "-xc" option)
  8672. //
  8673. // DQ (12/2/2006): Note that the filename extension could have set this to C++ mode and we only don't want an explicit specification of "-rose:C" to change this.
  8674. set_C_only(false);
  8675. ROSE_ASSERT (get_C_only() == false);
  8676. if ( CommandlineProcessing::isOption(argv,"-rose:","(C|C_only)",true) == true )
  8677. {
  8678. if ( SgProject::get_verbose() >= 1 )
  8679. printf ("C only mode ON \n");
  8680. set_C_only(true);
  8681. if (get_sourceFileUsesCppFileExtension() == true)
  8682. {
  8683. printf ("Warning, C++ source file name specificed with explicit -rose:C C language option! (ignoring explicit option to mimic gcc behavior) \n");
  8684. set_C_only(false);
  8685. }
  8686. }
  8687. //
  8688. // C99 only option (turns on EDG "--c" option and g++ "-xc" option)
  8689. //
  8690. set_C99_only(false);
  8691. ROSE_ASSERT (get_C99_only() == false);
  8692. if ( CommandlineProcessing::isOption(argv,"-rose:","(C99|C99_only)",true) == true )
  8693. {
  8694. if ( SgProject::get_verbose() >= 1 )
  8695. printf ("C99 mode ON \n");
  8696. set_C99_only(true);
  8697. }
  8698. set_Fortran_only(false);
  8699. ROSE_ASSERT (get_Fortran_only() == false);
  8700. if ( CommandlineProcessing::isOption(argv,"-rose:","(f|F|Fortran)",true) == true )
  8701. {
  8702. if ( SgProject::get_verbose() >= 1 )
  8703. printf ("Fortran only mode ON \n");
  8704. set_Fortran_only(true);
  8705. if (get_sourceFileUsesFortranFileExtension() == false)
  8706. {
  8707. printf ("Warning, Non Fortran source file name specificed with explicit -rose:Fortran Fortran language option! \n");
  8708. set_Fortran_only(false);
  8709. }
  8710. }
  8711. set_F77_only(false);
  8712. ROSE_ASSERT (get_F77_only() == false);
  8713. if ( CommandlineProcessing::isOption(argv,"-rose:","(f77|F77|Fortran77)",true) == true )
  8714. {
  8715. if ( SgProject::get_verbose() >= 1 )
  8716. printf ("Fortran77 only mode ON \n");
  8717. set_F77_only(true);
  8718. set_Fortran_only(true);
  8719. if (get_sourceFileUsesFortran77FileExtension() == false)
  8720. {
  8721. printf ("Warning, Non Fortran77 source file name specificed with explicit -rose:Fortran77 Fortran 77 language option! \n");
  8722. set_F77_only(false);
  8723. }
  8724. }
  8725. set_F90_only(false);
  8726. ROSE_ASSERT (get_F90_only() == false);
  8727. if ( CommandlineProcessing::isOption(argv,"-rose:","(f90|F90|Fortran90)",true) == true )
  8728. {
  8729. if ( SgProject::get_verbose() >= 1 )
  8730. printf ("Fortran90 only mode ON \n");
  8731. set_F90_only(true);
  8732. set_Fortran_only(true);
  8733. if (get_sourceFileUsesFortran90FileExtension() == false)
  8734. {
  8735. printf ("Warning, Non Fortran90 source file name specificed with explicit -rose:Fortran90 Fortran 90 language option! \n");
  8736. set_F90_only(false);
  8737. }
  8738. }
  8739. set_F95_only(false);
  8740. ROSE_ASSERT (get_F95_only() == false);
  8741. if ( CommandlineProcessing::isOption(argv,"-rose:","(f95|F95|Fortran95)",true) == true )
  8742. {
  8743. if ( SgProject::get_verbose() >= 1 )
  8744. printf ("Fortran95 only mode ON \n");
  8745. set_F95_only(true);
  8746. set_Fortran_only(true);
  8747. if (get_sourceFileUsesFortran95FileExtension() == false)
  8748. {
  8749. printf ("Warning, Non Fortran95 source file name specificed with explicit -rose:Fortran95 Fortran 95 language option! \n");
  8750. set_F95_only(false);
  8751. }
  8752. }
  8753. set_F2003_only(false);
  8754. ROSE_ASSERT (get_F2003_only() == false);
  8755. if ( CommandlineProcessing::isOption(argv,"-rose:","(f2003|F2003|Fortran2003)",true) == true )
  8756. {
  8757. if ( SgProject::get_verbose() >= 1 )
  8758. printf ("Fortran2003 only mode ON \n");
  8759. set_F2003_only(true);
  8760. set_Fortran_only(true);
  8761. if (get_sourceFileUsesFortran2003FileExtension() == false)
  8762. {
  8763. printf ("Warning, Non Fortran2003 source file name specificed with explicit -rose:Fortran2003 Fortran 2003 language option! \n");
  8764. set_F2003_only(false);
  8765. }
  8766. }
  8767. // Fixed format v.s. free format option handling (ROSE defaults to fix or free format, depending on the file extension).
  8768. // F77 default is fixed format, F90 and later default is free format.
  8769. // Fortran source file format options for different compilers(for IBM/XL,Intel,Portland,GNU):
  8770. // IBM/XL Intel Portland GNU
  8771. // -qfixed -fixed -Mfixed -ffixed-form
  8772. // -qfree -free -Mfree -free-form
  8773. // GNU gfortran also supports -fno-fixed-form (we could use this to turn off all fixed form
  8774. // formatting independent of the input source).
  8775. set_fixedFormat(false);
  8776. ROSE_ASSERT (get_fixedFormat() == false);
  8777. if ( CommandlineProcessing::isOption(argv,"-","(ffixed-form|fixed|Mfixed|qfixed)",true) == true )
  8778. {
  8779. if ( SgProject::get_verbose() >= 1 )
  8780. printf ("Fortran fixed format mode explicitly set: ON \n");
  8781. set_fixedFormat(true);
  8782. if (get_sourceFileUsesFortranFileExtension() == false)
  8783. {
  8784. printf ("Warning, Non Fortran source file name specificed with explicit fixed format code generation (unparser) option! \n");
  8785. set_fixedFormat(false);
  8786. }
  8787. }
  8788. set_freeFormat(false);
  8789. ROSE_ASSERT (get_freeFormat() == false);
  8790. if ( CommandlineProcessing::isOption(argv,"-","(ffree-form|free|Mfree|qfree)",true) == true )
  8791. {
  8792. if ( SgProject::get_verbose() >= 1 )
  8793. printf ("Fortran free format mode explicitly set: ON \n");
  8794. set_freeFormat(true);
  8795. if (get_sourceFileUsesFortranFileExtension() == false)
  8796. {
  8797. printf ("Warning, Non Fortran source file name specificed with explicit free format code generation (unparser) option! \n");
  8798. set_freeFormat(false);
  8799. }
  8800. }
  8801. // DQ (8/19/2007): This option only controls the output format (unparsing) of Fortran code (free or fixed format).
  8802. // It has no effect on C/C++ code generation (unparsing).
  8803. set_outputFormat(SgFile::e_unknown_output_format);
  8804. ROSE_ASSERT (get_outputFormat() == SgFile::e_unknown_output_format);
  8805. if ( CommandlineProcessing::isOption(argv,"-rose:","(fixedOutput|fixedFormatOutput)",true) == true )
  8806. {
  8807. if ( SgProject::get_verbose() >= 1 )
  8808. printf ("Fortran fixed format output specified \n");
  8809. set_outputFormat(SgFile::e_fixed_form_output_format);
  8810. if (get_sourceFileUsesFortranFileExtension() == false)
  8811. {
  8812. printf ("Warning, Non Fortran source file name specificed with code generation option: free format! \n");
  8813. ROSE_ASSERT(false);
  8814. }
  8815. }
  8816. if ( CommandlineProcessing::isOption(argv,"-rose:","(freeOutput|freeFormatOutput)",true) == true )
  8817. {
  8818. if ( SgProject::get_verbose() >= 1 )
  8819. printf ("Fortran free format mode explicitly set: ON \n");
  8820. set_outputFormat(SgFile::e_free_form_output_format);
  8821. if (get_sourceFileUsesFortranFileExtension() == false)
  8822. {
  8823. printf ("Warning, Non Fortran source file name specificed with code generation option: fixed format! \n");
  8824. ROSE_ASSERT(false);
  8825. }
  8826. }
  8827. set_fortran_implicit_none(false);
  8828. ROSE_ASSERT (get_fortran_implicit_none() == false);
  8829. if ( CommandlineProcessing::isOption(argv,"-","fimplicit_none",true) == true )
  8830. {
  8831. if ( SgProject::get_verbose() >= 1 )
  8832. printf ("Fortran free format mode explicitly set: ON \n");
  8833. set_fortran_implicit_none(true);
  8834. if (get_sourceFileUsesFortranFileExtension() == false)
  8835. {
  8836. printf ("Warning, Non Fortran source file name specificed with explicit free format code generation (unparser) option! \n");
  8837. set_fortran_implicit_none(false);
  8838. }
  8839. }
  8840. // DQ (8/19/2007): I have added the option here so that we can start to support OpenMP for Fortran.
  8841. // Allows handling of OpenMP "!$omp" directives in free form and "c$omp", *$omp and "!$omp" directives in fixed form, enables "!$" conditional
  8842. // compilation sentinels in free form and "c$", "*$" and "!$" sentinels in fixed form and when linking arranges for the OpenMP runtime library
  8843. // to be linked in. (Not implemented yet).
  8844. set_fortran_openmp(false);
  8845. ROSE_ASSERT (get_fortran_openmp() == false);
  8846. if ( CommandlineProcessing::isOption(argv,"-","fopenmp",true) == true )
  8847. {
  8848. if ( SgProject::get_verbose() >= 1 )
  8849. printf ("Fortran OpenMP option specified \n");
  8850. set_fortran_openmp(true);
  8851. if (get_sourceFileUsesFortranFileExtension() == false)
  8852. {
  8853. printf ("Warning, Non Fortran source file name specificed with explicit OpenMP option! \n");
  8854. set_fortran_openmp(false);
  8855. }
  8856. }
  8857. //
  8858. // strict ANSI/ISO mode option
  8859. //
  8860. // set_strict_language_handling(false);
  8861. if ( CommandlineProcessing::isOption(argv,"-rose:","(strict)",true) == true )
  8862. {
  8863. // Optionally specify strict language handling
  8864. set_strict_language_handling(true);
  8865. }
  8866. //
  8867. // specify output file option
  8868. //
  8869. // DQ (10/15/2005): There is a valid default value here, but we want to overwrite it!
  8870. std::string stringParameter;
  8871. if ( CommandlineProcessing::isOptionWithParameter(argv,"-rose:","(o|output)",stringParameter,true) == true )
  8872. {
  8873. // printf ("-rose:output %s \n",stringParameter.c_str());
  8874. if (get_unparse_output_filename().empty() == false)
  8875. {
  8876. printf ("Overwriting value in get_unparse_output_filename() = %s \n",get_unparse_output_filename().c_str());
  8877. }
  8878. // DQ (10/15/2005): This is so much simpler!
  8879. p_unparse_output_filename = stringParameter;
  8880. }
  8881. // printf ("After processing -rose:output option argc = %d \n",argc);
  8882. // ROSE_ABORT();
  8883. // DQ (4/20/2006): Added to support fall through option to be supported by user translators.
  8884. //
  8885. // skip_rose option (just call the backend compiler directly): This causes Rose to act identally
  8886. // to the backend compiler (with no creation of the ROSE AST, translation, code generation, etc.).
  8887. //
  8888. if ( CommandlineProcessing::isOption(argv,"-rose:","(skip_rose)",true) == true )
  8889. {
  8890. printf ("option -rose:skip_rose found \n");
  8891. // set_skip_rose(true);
  8892. // Need these to be set correctly as well
  8893. p_useBackendOnly = true;
  8894. // p_skip_buildHigherLevelGrammars = true;
  8895. p_disable_edg_backend = true; // This variable should be called frontend NOT backend???
  8896. p_skip_transformation = true;
  8897. p_skip_unparse = true;
  8898. p_skipfinalCompileStep = false;
  8899. // Skip all processing of comments
  8900. set_skip_commentsAndDirectives(true);
  8901. set_collectAllCommentsAndDirectives(false);
  8902. }
  8903. //
  8904. // skip_transformation option: if transformations of the AST check this variable then the
  8905. // resulting translators can skip the transformatios via this command-line specified option.
  8906. //
  8907. if ( CommandlineProcessing::isOption(argv,"-rose:","(skip_transformation)",true) == true )
  8908. {
  8909. printf ("option -rose:skip_transformation found \n");
  8910. set_skip_transformation(true);
  8911. }
  8912. //
  8913. // skip_unparse option: if analysis only (without transformatio is required, then this can significantly
  8914. // improve the performance since it will also skip the backend compilation, as I recall)
  8915. //
  8916. if ( CommandlineProcessing::isOption(argv,"-rose:","(skip_unparse)",true) == true )
  8917. {
  8918. printf ("option -rose:skip_unparse found \n");
  8919. set_skip_unparse(true);
  8920. }
  8921. // unparser language option
  8922. // DQ (8/27/2007): This option controls the output language (which language unparser is to be used).
  8923. // This allows the code generation of one language to be tested using input of another langauge. It is
  8924. // mostly a mechanism to test the unparser in the early stages of their development. Unshared language
  8925. // constructs are not supported and would have the be translated. This step does none of this sort of
  8926. // translation, which might be difficult debendingon the input and output languages selected.
  8927. // Supported options are:
  8928. // e_default_output_language
  8929. // e_C_output_language
  8930. // e_Cxx_output_language
  8931. // e_Fortran_output_language
  8932. // e_Promela_output_language
  8933. set_outputLanguage(SgFile::e_default_output_language);
  8934. ROSE_ASSERT (get_outputLanguage() == SgFile::e_default_output_language);
  8935. if ( CommandlineProcessing::isOption(argv,"-rose:","C_output_language",true) == true )
  8936. {
  8937. if ( SgProject::get_verbose() >= 1 )
  8938. printf ("Use the C language code generator (unparser) \n");
  8939. set_outputLanguage(SgFile::e_C_output_language);
  8940. }
  8941. if ( CommandlineProcessing::isOption(argv,"-rose:","Cxx_output_language",true) == true )
  8942. {
  8943. if ( SgProject::get_verbose() >= 1 )
  8944. printf ("Use the C++ language code generator (unparser) \n");
  8945. set_outputLanguage(SgFile::e_Cxx_output_language);
  8946. }
  8947. if ( CommandlineProcessing::isOption(argv,"-rose:","Fortran_output_language",true) == true )
  8948. {
  8949. if ( SgProject::get_verbose() >= 1 )
  8950. printf ("Use the Fortran language code generator (unparser) \n");
  8951. set_outputLanguage(SgFile::e_Fortran_output_language);
  8952. }
  8953. if ( CommandlineProcessing::isOption(argv,"-rose:","Promela_output_language",true) == true )
  8954. {
  8955. if ( SgProject::get_verbose() >= 1 )
  8956. printf ("Use the Promela language code generator (unparser) \n");
  8957. set_outputLanguage(SgFile::e_Promela_output_language);
  8958. }
  8959. //
  8960. // unparse_includes option
  8961. //
  8962. if ( CommandlineProcessing::isOption(argv,"-rose:","(unparse_includes)",true) == true )
  8963. {
  8964. printf ("option -rose:unparse_includes found \n");
  8965. set_unparse_includes(true);
  8966. }
  8967. //
  8968. // collectAllCommentsAndDirectives option: operates across all files (include files) and significantly slows the compilation.
  8969. //
  8970. if ( CommandlineProcessing::isOption(argv,"-rose:","(collectAllCommentsAndDirectives)",true) == true )
  8971. {
  8972. // printf ("option -rose:collectAllCommentsAndDirectives found \n");
  8973. set_collectAllCommentsAndDirectives(true);
  8974. }
  8975. //
  8976. // skip_commentsAndDirectives option: if analysis that does not use comments or CPP directives is required
  8977. // then this option can improve the performance of the compilation.
  8978. //
  8979. if ( CommandlineProcessing::isOption(argv,"-rose:","(skip_commentsAndDirectives)",true) == true )
  8980. {
  8981. printf ("option -rose:skip_commentsAndDirectives found \n");
  8982. set_skip_commentsAndDirectives(true);
  8983. // If we are skipping comments then we should not be collecting all comments (does not make sense)
  8984. ROSE_ASSERT(get_collectAllCommentsAndDirectives() == false);
  8985. // set_collectAllCommentsAndDirectives(false);
  8986. }
  8987. //
  8988. // internal testing option (for internal use only, these may disappear at some point)
  8989. //
  8990. int integerOption = 0;
  8991. if ( CommandlineProcessing::isOptionWithParameter(argv,"-rose:","test",integerOption,true) == true )
  8992. {
  8993. // printf ("option -rose:test %d found \n",integerOption);
  8994. p_testingLevel = integerOption;
  8995. switch (integerOption)
  8996. {
  8997. case 0 :
  8998. // transparent mode (does nothing)
  8999. // p_skip_buildHigherLevelGrammars = true;
  9000. p_disable_edg_backend = true; // This variable should be called frontend NOT backend???
  9001. p_skip_transformation = true;
  9002. p_skip_unparse = true;
  9003. p_skipfinalCompileStep = true;
  9004. break;
  9005. case 1 :
  9006. // run the KCC front end only (can't unparse or compile output)
  9007. // p_skip_buildHigherLevelGrammars = true;
  9008. p_new_frontend = true;
  9009. p_KCC_frontend = true;
  9010. p_skip_transformation = true;
  9011. p_skip_unparse = true;
  9012. p_skipfinalCompileStep = true;
  9013. break;
  9014. case 2 :
  9015. // run the newer version of EDG (compiled separately from SAGE) "edgFrontEnd"
  9016. // (can't unparse or compile output)
  9017. // p_skip_buildHigherLevelGrammars = true;
  9018. p_new_frontend = true;
  9019. p_skip_transformation = true;
  9020. p_skip_unparse = true;
  9021. p_skipfinalCompileStep = true;
  9022. break;
  9023. case 3 :
  9024. // run internal (older) version of edg front end (compiled with SAGE)
  9025. // p_skip_buildHigherLevelGrammars = true;
  9026. p_skip_transformation = true;
  9027. p_skip_unparse = true;
  9028. p_skipfinalCompileStep = true;
  9029. break;
  9030. case 4 :
  9031. // all of 3 (above) plus parse into SAGE program tree
  9032. // p_skip_buildHigherLevelGrammars = true;
  9033. p_skip_transformation = true;
  9034. p_skip_unparse = true;
  9035. p_skipfinalCompileStep = true;
  9036. break;
  9037. case 5 :
  9038. // all of 4 (above) plus unparse to generate (untransformed source code)
  9039. // p_skip_buildHigherLevelGrammars = true;
  9040. p_skip_transformation = true;
  9041. p_skipfinalCompileStep = true;
  9042. break;
  9043. case 6 :
  9044. // all of 4 (above) plus compile generated source code
  9045. // p_skip_buildHigherLevelGrammars = true;
  9046. p_skip_transformation = true;
  9047. break;
  9048. case 7 :
  9049. // all of 5 (above) plus parse into higher level grammars before unparsing
  9050. p_skip_transformation = true;
  9051. p_skipfinalCompileStep = true;
  9052. break;
  9053. case 8 :
  9054. // all of 7 (above) plus compile resulting unparsed code (without transformations)
  9055. p_skip_transformation = true;
  9056. break;
  9057. case 9 :
  9058. // all of 8 (above) plus run transformations before unparsing (do everything)
  9059. break;
  9060. default:
  9061. // default mode is an error
  9062. printf ("Default reached in processing -rose:test # option (use 0-6, input option = %d) \n",integerOption);
  9063. ROSE_ABORT();
  9064. break;
  9065. }
  9066. }
  9067. #if 0
  9068. printf ("Exiting after test of test option! \n");
  9069. exit (0);
  9070. #endif
  9071. // printf ("After processing -rose:test # option argc = %d \n",argc);
  9072. //
  9073. // new_unparser option
  9074. //
  9075. if ( CommandlineProcessing::isOption(argv,"-rose:","(skipfinalCompileStep)",true) == true )
  9076. {
  9077. printf ("option -rose:skipfinalCompileStep found \n");
  9078. set_skipfinalCompileStep(true);
  9079. }
  9080. //
  9081. // Standard compiler options (allows alternative -E option to just run CPP)
  9082. //
  9083. if ( CommandlineProcessing::isOption(argv,"-","(E)",true) == true )
  9084. {
  9085. // printf ("/* option -E found (just run backend compiler with -E to call CPP) */ \n");
  9086. p_useBackendOnly = true;
  9087. // p_skip_buildHigherLevelGrammars = true;
  9088. p_disable_edg_backend = true; // This variable should be called frontend NOT backend???
  9089. p_skip_transformation = true;
  9090. p_skip_unparse = true;
  9091. p_skipfinalCompileStep = false;
  9092. }
  9093. //
  9094. // Standard compiler options (allows alternative -H option to just output header file info)
  9095. //
  9096. if ( CommandlineProcessing::isOption(argv,"-","(H)",true) == true )
  9097. {
  9098. // printf ("option -H found (just run backend compiler with -E to call CPP) \n");
  9099. p_useBackendOnly = true;
  9100. // p_skip_buildHigherLevelGrammars = true;
  9101. p_disable_edg_backend = true; // This variable should be called frontend NOT backend???
  9102. p_skip_transformation = true;
  9103. p_skip_unparse = true;
  9104. p_skipfinalCompileStep = false;
  9105. }
  9106. //
  9107. // negative_test option: allows passing all tests to be treated as an error!
  9108. //
  9109. if ( CommandlineProcessing::isOption(argv,"-rose:","(negative_test)",true) == true )
  9110. {
  9111. printf ("option -rose:negative_test found \n");
  9112. set_negative_test(true);
  9113. }
  9114. #if 1
  9115. //
  9116. // We have processed all rose supported command line options.
  9117. // Anything left in argv now should be a typo or option for either EDG or the C or C++ compiler.
  9118. //
  9119. if ( get_verbose() > 1 )
  9120. {
  9121. cout << "The remaining non-rose options will be passed onto either EDG or the C or C++ the compiler: " << endl;
  9122. for (unsigned int i = 1; i < argv.size(); i++)
  9123. {
  9124. cout << " argv[" << i << "]= " << argv[i] << endl;
  9125. }
  9126. }
  9127. // debugging aid
  9128. // display("SgFile::processRoseCommandLineOptions()");
  9129. #endif
  9130. }
  9131. void
  9132. SgFile::processBackendSpecificCommandLineOptions ( const vector<string>& argvOrig )
  9133. {
  9134. // DQ (6/21/2005): This function processes commandline options that are specific to the backend
  9135. // but which the front-end or ROSE should know about. Examples include template options that
  9136. // would influence how ROSE instatiates or outputs templates in the code generation phase.
  9137. // This function leaves all commandline options in place (for use by the backend)
  9138. // DQ (1/17/2006): test this
  9139. // ROSE_ASSERT(get_fileInfo() != NULL);
  9140. vector<string> argv = argvOrig;
  9141. //
  9142. // -ansi option (fairly general option name across a number of compilers, I think)
  9143. //
  9144. if ( CommandlineProcessing::isOption(argv,"-","ansi",true) == true )
  9145. {
  9146. set_strict_language_handling(true);
  9147. }
  9148. //
  9149. // -fno-implicit-templates option
  9150. //
  9151. p_no_implicit_templates = false;
  9152. if ( CommandlineProcessing::isOption(argv,"-f","no-implicit-templates",true) == true )
  9153. {
  9154. // don't instantiate any inline templates
  9155. printf ("ROSE sees use of -fno-implicit-templates option for use by g++ \n");
  9156. // printf ("ERROR: This g++ specific option is not yet supported \n");
  9157. // ROSE_ASSERT(false);
  9158. p_no_implicit_templates = true;
  9159. }
  9160. //
  9161. // -fno-implicit-inline-templates option
  9162. //
  9163. p_no_implicit_inline_templates = false;
  9164. if ( CommandlineProcessing::isOption(argv,"-f","no-implicit-inline-templates",true) == true )
  9165. {
  9166. // don't instantiate any inline templates
  9167. printf ("ROSE sees use of -fno-implicit-inline-templates option for use by g++ \n");
  9168. p_no_implicit_inline_templates = true;
  9169. }
  9170. }
  9171. bool
  9172. SgFile::isPrelinkPhase() const
  9173. {
  9174. // This function checks if the "-prelink" option was passed to the ROSE preprocessor
  9175. // It could alternatively just check the commandline and set a flag in the SgFile object.
  9176. // But then there would be a redundent flag in each SgFile object (perhaps the design needs to
  9177. // be better, using a common base class for commandline options (in both the SgProject and
  9178. // the SgFile (would not be a new IR node)).
  9179. bool returnValue = false;
  9180. // DQ (5/9/2004): If the parent is not set then this was compiled as a SgFile directly
  9181. // (likely by the rewrite mechanism). IF so it can't be a prelink phase, which is
  9182. // called only on SgProjects). Not happy with this mechanism!
  9183. if (get_parent() != NULL)
  9184. {
  9185. ROSE_ASSERT ( get_parent() != NULL );
  9186. SgProject* project = isSgProject(get_parent());
  9187. ROSE_ASSERT ( project != NULL );
  9188. returnValue = project->get_prelink();
  9189. }
  9190. return returnValue;
  9191. // Note that project can be false if this is called on an intermediate file
  9192. // generated by the rewrite system.
  9193. // return (project == NULL) ? false : project->get_prelink();
  9194. }
  9195. SgProject*
  9196. SgFile::get_project()
  9197. {
  9198. // If the project is a parent of the current SgFile then we find it, else return NULL.
  9199. SgNode* parent = get_parent();
  9200. // DQ (7/12/2005): The parent is NULL if we have only built a single file (e.g. within the rewrite mechanism)
  9201. // ROSE_ASSERT(parent != NULL);
  9202. SgProject* project = NULL;
  9203. // DQ (7/12/2005): The parent is NULL if we have only built a single file (e.g. within the rewrite mechanism)
  9204. // Just return NULL in this case!
  9205. if (parent != NULL)
  9206. {
  9207. project = isSgProject(parent);
  9208. while ( project == NULL && parent->get_parent() != NULL )
  9209. {
  9210. parent = parent->get_parent();
  9211. ROSE_ASSERT(parent != NULL);
  9212. project = isSgProject(parent);
  9213. }
  9214. ROSE_ASSERT ( project != NULL );
  9215. }
  9216. return project;
  9217. }
  9218. void
  9219. SgFile::build_EDG_CommandLine (
  9220. vector<string> & inputCommandLine, vector<string> & argv, int fileNameIndex )
  9221. {
  9222. // This function builds the command line input for the edg_main (the EDG C++ Front-End)
  9223. // There are numerous options that must be set for different architectures. We can find
  9224. // a more general setup of these options within something like Duct-Tape. In this function
  9225. // argv and argc are the parameters from the user's commandline, and inputCommandLine and
  9226. // numberOfCommandLineArguments are parameters for the new command line that will be build
  9227. // for EDG.
  9228. // Old information recorded here (but not useful any more):
  9229. // Complete Command line required to run ROSE Preprocessor (old version for SUN CC 4.2
  9230. // compiler worked out by Kei Davis at LANL):
  9231. // ../src/rose -D__CPLUSPLUS -D__STDC__=0 -Dsun -Dsparc -Dunix -D__KCC -D__sun__
  9232. // -D__sparc__ -D__unix__ -D_parc -D__unix -D__SVR4 -D_NO_LONGLONG
  9233. // -I/opt/SUNWspro/SC4.2/include/CC/ -I$APlusPlus/include test1.C
  9234. // DQ (1/17/2006): test this
  9235. // ROSE_ASSERT(get_fileInfo() != NULL);
  9236. // printf ("##### Inside of SgFile::build_EDG_CommandLine file = %s \n",get_file_info()->get_filenameString().c_str());
  9237. // printf ("##### Inside of SgFile::build_EDG_CommandLine file = %s = %s \n",get_file_info()->get_filenameString().c_str(),get_sourceFileNameWithPath().c_str());
  9238. ROSE_ASSERT(get_file_info()->get_filenameString() == get_sourceFileNameWithPath());
  9239. // ROSE_ASSERT (p_useBackendOnly == false);
  9240. // DQ (4/21/2006): I think we can now assert this!
  9241. ROSE_ASSERT(fileNameIndex == 0);
  9242. // printf ("Inside of SgFile::build_EDG_CommandLine(): fileNameIndex = %d \n",fileNameIndex);
  9243. // BP: (11/26/2001) trying out a new method of figuring out internal compiler definitions
  9244. #if defined(CXX_SPEC_DEF)
  9245. #if 1
  9246. string configDefsString = CXX_SPEC_DEF;
  9247. const string Cxx_ConfigIncludeString = CXX_INCLUDE_STRING;
  9248. const string C_ConfigIncludeString = C_INCLUDE_STRING;
  9249. // Removed reference to __restrict__ so it could be placed into the preinclude vendor specific header file for ROSE.
  9250. // DQ (9/10/2004): Attept to add support for restrict (but I think this just sets it to true, using "-Dxxx=" works)
  9251. // const string roseSpecificDefs = "-DUSE_RESTRICT_POINTERS_IN_ROSE_TRANSFORMATIONS -DUSE_ROSE -D__restrict__=";
  9252. const string roseSpecificDefs = "-DUSE_RESTRICT_POINTERS_IN_ROSE_TRANSFORMATIONS -DUSE_ROSE";
  9253. ROSE_ASSERT(configDefsString.empty() == false);
  9254. ROSE_ASSERT(Cxx_ConfigIncludeString.empty() == false);
  9255. ROSE_ASSERT(C_ConfigIncludeString.empty() == false);
  9256. // printf ("configDefsString = %s \n",configDefsString);
  9257. #if 0
  9258. printf ("Cxx_ConfigIncludeString = %s \n",Cxx_ConfigIncludeString.c_str());
  9259. printf ("C_ConfigIncludeString = %s \n",C_ConfigIncludeString.c_str());
  9260. #endif
  9261. // AS (03/08/2006) Added support for g++ preincludes
  9262. // Rose_STL_Container<std::string> listOfPreincludes;
  9263. // DQ (12/1/2006): Code added by Andreas (07/03/06) and moved to a new position
  9264. // so that we could modify the string input from CXX_SPEC_DEF (configDefsString).
  9265. string preinclude_string_target = "-include";
  9266. string preinclude_string;
  9267. for (unsigned int i=1; i < argv.size(); i++)
  9268. {
  9269. // AS (070306) Handle g++ --include directives
  9270. std::string stack_arg(argv[i]);
  9271. // std::cout << "stack arg is: " << stack_arg << std::endl;
  9272. if( stack_arg.find(preinclude_string_target) <= 2)
  9273. {
  9274. i++;
  9275. ROSE_ASSERT(i<argv.size());
  9276. string currentArgument(argv[i]);
  9277. string headerSuffix = ".h";
  9278. int jlength = headerSuffix.size();
  9279. int length = currentArgument.size();
  9280. ROSE_ASSERT( length > jlength);
  9281. ROSE_ASSERT( ( currentArgument.compare(length - jlength, jlength, headerSuffix) == 0 ) || CommandlineProcessing::isSourceFilename(currentArgument));
  9282. string sourceFilePath = StringUtility::getPathFromFileName(currentArgument);
  9283. currentArgument = StringUtility::stripPathFromFileName(currentArgument);
  9284. if (sourceFilePath == "" )
  9285. sourceFilePath = "./";
  9286. sourceFilePath = StringUtility::getAbsolutePathFromRelativePath(sourceFilePath);
  9287. currentArgument = sourceFilePath+"/"+currentArgument;
  9288. // std::cout << "Found preinclude : " << currentArgument << std::endl;
  9289. preinclude_string += " --preinclude " + currentArgument + " ";
  9290. }
  9291. }
  9292. configDefsString += preinclude_string;
  9293. string initString;
  9294. // This is OK since these use the existing memory and not the C language
  9295. // malloc/free (which would interfere with C++'s new/delete)
  9296. initString = configDefsString;
  9297. initString += " ";
  9298. // initString += Cxx_ConfigIncludeString;
  9299. // DQ (12/2/2006): Both GNU and EDG determin the language mode from the source file name extension.
  9300. // In ROSE we also require that C files be explicitly specified to use the C language mode. Thus
  9301. // C++ source files will be treated as C++ even if the C language rules are specified, however they
  9302. // are restricted to the C subset of C++.
  9303. // bool treatAsCSourceFile = ((get_C_only() == true || get_C99_only() == true) && (get_sourceFileUsesCppFileExtension() == false));
  9304. // if (treatAsCSourceFile == true)
  9305. // Find the C++ sys include path for the rose_edg_required_macros_and_functions.h
  9306. string roseHeaderDirCPP = " --sys_include ";
  9307. Rose_STL_Container<string> internalIncludePathListForHeader = CommandlineProcessing::generateArgListFromString(Cxx_ConfigIncludeString);
  9308. for (Rose_STL_Container<string>::iterator i = internalIncludePathListForHeader.begin(); i != internalIncludePathListForHeader.end(); i++)
  9309. {
  9310. if (i->substr(0,13) == "--sys_include")
  9311. {
  9312. i++;
  9313. if ( ( i != internalIncludePathListForHeader.end() ) && ( (i->substr(0,8) != "--sys_include") || (i->substr(0,2) == "-I") ))
  9314. {
  9315. string file = (*i) + "/rose_edg_required_macros_and_functions.h";
  9316. FILE* testIfFileExist = fopen(file.c_str(),"r");
  9317. if (testIfFileExist)
  9318. {
  9319. roseHeaderDirCPP+=(*i);
  9320. fclose(testIfFileExist);
  9321. break;
  9322. }
  9323. }
  9324. }
  9325. }
  9326. // Find the C sys include path for the rose_edg_required_macros_and_functions.h
  9327. string roseHeaderDirC = " --sys_include ";
  9328. internalIncludePathListForHeader = CommandlineProcessing::generateArgListFromString(C_ConfigIncludeString);
  9329. for (Rose_STL_Container<string>::iterator i = internalIncludePathListForHeader.begin(); i != internalIncludePathListForHeader.end(); i++)
  9330. {
  9331. if (i->substr(0,13) == "--sys_include")
  9332. {
  9333. i++;
  9334. if ( (i != internalIncludePathListForHeader.end() ) && ( (i->substr(0,13) != "--sys_include") || (i->substr(0,2) == "-I") ))
  9335. {
  9336. string file = (*i) + "/rose_edg_required_macros_and_functions.h";
  9337. FILE* testIfFileExist = fopen(file.c_str(),"r");
  9338. // std::cout << file << std::endl;
  9339. if (testIfFileExist)
  9340. {
  9341. roseHeaderDirC+=(*i);
  9342. fclose(testIfFileExist);
  9343. break;
  9344. }
  9345. }
  9346. }
  9347. }
  9348. if (get_C_only() == true || get_C99_only() == true)
  9349. {
  9350. // AS(02/21/07) Add support for the gcc 'nostdinc' and 'nostdinc++' options
  9351. string roseHeaderDir = " --sys_include ";
  9352. // DQ (11/29/2006): if required turn on the use of the __cplusplus macro
  9353. // if (get_requires_cplusplus_macro() == true)
  9354. if (get_sourceFileUsesCppFileExtension() == true)
  9355. {
  9356. // The value here should be 1 to match that of GNU gcc (the C++ standard requires this to be "199711L")
  9357. // initString += " -D__cplusplus=0 ";
  9358. initString += " -D__cplusplus=1 ";
  9359. if ( CommandlineProcessing::isOption(argv,"-","nostdinc",false) == true )
  9360. {
  9361. initString+=roseHeaderDirC;
  9362. // no standard includes when -nostdinc is specified
  9363. }
  9364. else
  9365. {
  9366. if ( CommandlineProcessing::isOption(argv,"-","nostdinc++",false) == true )
  9367. {
  9368. initString += roseHeaderDirCPP;
  9369. initString += C_ConfigIncludeString;
  9370. }
  9371. else
  9372. {
  9373. initString += Cxx_ConfigIncludeString;
  9374. }
  9375. }
  9376. // DQ (11/29/2006): Specify C++ mode for handling in rose_edg_required_macros_and_functions.h
  9377. initString += " -DROSE_CPP_MODE=1 ";
  9378. }
  9379. else
  9380. {
  9381. if ( CommandlineProcessing::isOption(argv,"-","nostdinc",false) == true )
  9382. {
  9383. initString += roseHeaderDirC;
  9384. // no standard includes when -nostdinc is specified
  9385. }
  9386. else
  9387. {
  9388. initString += C_ConfigIncludeString;
  9389. }
  9390. // DQ (11/29/2006): Specify C mode for handling in rose_edg_required_macros_and_functions.h
  9391. initString += " -DROSE_CPP_MODE=0 ";
  9392. }
  9393. }
  9394. else
  9395. {
  9396. if ( CommandlineProcessing::isOption(argv,"-","nostdinc",false) == true )
  9397. {
  9398. initString+=roseHeaderDirCPP;
  9399. // no standard includes when -nostdinc is specified
  9400. }
  9401. else
  9402. {
  9403. if ( CommandlineProcessing::isOption(argv,"-","nostdinc++",false) == true )
  9404. {
  9405. initString += roseHeaderDirCPP;
  9406. initString += C_ConfigIncludeString;
  9407. }
  9408. else
  9409. {
  9410. initString += Cxx_ConfigIncludeString;
  9411. }
  9412. }
  9413. // DQ (11/29/2006): Specify C++ mode for handling in rose_edg_required_macros_and_functions.h
  9414. initString += " -DROSE_CPP_MODE=1 ";
  9415. }
  9416. // AS(02/24/06) Add support for the gcc "-isystem" option (this added a specificed directory
  9417. // to the start of the system include path). This maps to the "--sys_include" in EDG.
  9418. string isystem_string_target = "-isystem";
  9419. string isystem_string;
  9420. for (unsigned int i=1; i < argv.size(); i++)
  9421. {
  9422. // AS (070306) Handle g++ --include directives
  9423. std::string stack_arg(argv[i]);
  9424. // std::cout << "stack arg is: " << stack_arg << std::endl;
  9425. if( stack_arg.find(isystem_string_target) <= 2){
  9426. i++;
  9427. ROSE_ASSERT(i<argv.size());
  9428. std::string currentArgument(argv[i]);
  9429. // std::cout << "Current argument " << currentArgument << std::endl;
  9430. currentArgument = StringUtility::getAbsolutePathFromRelativePath(currentArgument);
  9431. isystem_string += " --sys_include " + currentArgument + " ";
  9432. }
  9433. }
  9434. initString += isystem_string;
  9435. initString += " ";
  9436. initString += roseSpecificDefs;
  9437. // DQ (9/17/2006): We should be able to build a version of this code which hands a std::string to StringUtility::splitStringIntoStrings()
  9438. // Separate the string into substrings consistant with the structure of argv command line input
  9439. inputCommandLine.clear();
  9440. StringUtility::splitStringIntoStrings(initString, ' ', inputCommandLine);
  9441. #endif
  9442. #else
  9443. // Output an error and exit
  9444. cout << "ERROR: The preprocessor definition CXX_SPEC_DEF should have been defined by the configure process!!" << endl;
  9445. ROSE_ABORT();
  9446. #endif
  9447. // We only provide options to change the default values!
  9448. // Handle option for use of ROSE as a C compiler instead of C++
  9449. // some C code can not be compiled with a C++ compiler.
  9450. if (get_C_only() == true)
  9451. {
  9452. // Add option to indicate use of C code (not C++) to EDG frontend
  9453. inputCommandLine.push_back("--c");
  9454. }
  9455. if (get_C99_only() == true)
  9456. {
  9457. // Add option to indicate use of C code (not C++) to EDG frontend
  9458. inputCommandLine.push_back("--c99");
  9459. }
  9460. if (get_strict_language_handling() == true)
  9461. {
  9462. inputCommandLine.push_back("--strict");
  9463. }
  9464. //
  9465. // edg_new_frontend option
  9466. //
  9467. if ( CommandlineProcessing::isOption(argv,"-edg:","(new_frontend)",true) == true || (get_new_frontend() == true) )
  9468. {
  9469. // printf ("option -edg:new_frontend found \n");
  9470. set_new_frontend(true);
  9471. // if we use the new EDG frontend (not connected to SAGE) then we can't
  9472. // generate C++ code so we don't want to call the C++ compiler
  9473. set_skipfinalCompileStep(true);
  9474. }
  9475. //
  9476. // edg_KCC_frontend option
  9477. //
  9478. if ( CommandlineProcessing::isOption(argv,"-edg:","(KCC_frontend)",true) == true || (get_KCC_frontend() == true) )
  9479. {
  9480. // printf ("option -edg:KCC_frontend found \n");
  9481. set_KCC_frontend(true);
  9482. // if we use the new EDG frontend (not connected to SAGE) then we can't
  9483. // generate C++ code so we don't want to call the C++ compiler
  9484. set_skipfinalCompileStep(true);
  9485. }
  9486. //
  9487. // edg_backend option
  9488. //
  9489. if ( CommandlineProcessing::isOption(argv,"-edg:","(disable_edg_backend)",true) == true || (get_disable_edg_backend() == true) )
  9490. {
  9491. // printf ("option -edg:disable_edg_backend found \n");
  9492. set_disable_edg_backend(true);
  9493. }
  9494. #if 0
  9495. //
  9496. // sage_backend option
  9497. //
  9498. if ( CommandlineProcessing::isOption(argv,"-edg:","(disable_edg_backend)",true) == true || (get_disable_edg_backend() == true) )
  9499. {
  9500. // printf ("option -edg:disable_edg_backend found \n");
  9501. set_disable_edg_backend(true);
  9502. }
  9503. #endif
  9504. #if 0
  9505. // Use 1 at end of argument list to SLA to force removal of option from argv and decrement of argc
  9506. optionCount = sla(&argc, argv, "-sage:", "($)", "(disable_sage_backend)",1);
  9507. if( optionCount > 0 || (get_disable_sage_backend() == true) == true )
  9508. {
  9509. printf ("option -sage:disable_sage_backend found \n");
  9510. set_disable_sage_backend(true);
  9511. inputCommandLine.push_back("--disable_sage_backend");
  9512. // We we aren't going to process the code through the backend then there is nothing to compile
  9513. set_skipfinalCompileStep(true);
  9514. }
  9515. // printf ("After processing -sage:disable_sage_backend option argc = %d \n",argc);
  9516. #endif
  9517. #if 0
  9518. //
  9519. // cp_backend option
  9520. //
  9521. // Use 1 at end of argument list to SLA to force removal of option from argv and decrement of agrc
  9522. optionCount = sla(&argc, argv, "-sage:", "($)", "(enable_cp_backend)",1);
  9523. if ( optionCount > 0 || (get_enable_cp_backend() == true) )
  9524. {
  9525. // printf ("option -sage:enable_cp_backend found \n");
  9526. set_enable_cp_backend(true);
  9527. inputCommandLine.push_back("--enable_cp_backend");
  9528. }
  9529. // printf ("After processing -sage:enable_cp_backend option argc = %d \n",argc);
  9530. //
  9531. // preinit_il option
  9532. //
  9533. // Use 1 at end of argument list to SLA to force removal of option from argv and decrement of agrc
  9534. optionCount = sla(&argc, argv, "-sage:", "($)", "(preinit_il)",1);
  9535. if( optionCount > 0 || (get_preinit_il() == true))
  9536. {
  9537. printf ("option -sage:preinit_il found \n");
  9538. set_preinit_il(true);
  9539. inputCommandLine.push_back("--preinit_il");
  9540. }
  9541. // printf ("After processing -sage:preinit_il option argc = %zu \n",argv.size());
  9542. #endif
  9543. // ***********************************************************************
  9544. // Now process the -D options, -I options and the filenames so that these
  9545. // can also be used for the command line passed to the EDG frontend.
  9546. // ***********************************************************************
  9547. // *******************************
  9548. // Add all input macro definitions
  9549. // *******************************
  9550. vector<string> macroDefineOptions;
  9551. // DQ (9/25/2006): Fixed handling of "-D DEFINE_ERROR_WITH_SPACE -DDEFINE_OK_WITHOUT_SPACE"
  9552. // skip the 0th entry since this is just the name of the program (e.g. rose)
  9553. unsigned int argIndex = 1;
  9554. while (argIndex < argv.size())
  9555. {
  9556. // most options appear as -<option>
  9557. // have to process +w2 (warnings option) on some compilers so include +<option>
  9558. if ( (argv[argIndex][0] == '-') && (argv[argIndex][1] == 'D') )
  9559. {
  9560. unsigned int length = argv[argIndex].size();
  9561. // printf ("Look for include path: argv[%d] = %s length = %d \n",argIndex,argv[argIndex],length);
  9562. macroDefineOptions.push_back(argv[argIndex]);
  9563. // DQ (9/19/2006): There must be an option string associated with each "-D" option
  9564. // ROSE_ASSERT(length > 2);
  9565. if (length == 2)
  9566. {
  9567. printf ("Handling the case of \"-D\" with orphened option (unclear if this is legal) \n");
  9568. macroDefineOptions.push_back("-D" + argv[argIndex + 1]);
  9569. ++argIndex;
  9570. }
  9571. }
  9572. argIndex++;
  9573. }
  9574. #if 0
  9575. for (int i=0; i < macroDefineOptionCounter; i++)
  9576. {
  9577. printf (" macroDefineOptions[%d] = %s \n",i,macroDefineOptions[i]);
  9578. }
  9579. #endif
  9580. // Add filenames (of source files) to so that the EDG front end will know what files to process
  9581. inputCommandLine.insert(inputCommandLine.end(), macroDefineOptions.begin(), macroDefineOptions.end());
  9582. // DQ (9/24/2006): Add -D option so that we can know when to turn on vendor compiler specific macros for ANSI/ISO compatability.
  9583. if (get_strict_language_handling() == true)
  9584. {
  9585. inputCommandLine.push_back("-DROSE_STRICT_LANGUAGE_HANDLING");
  9586. }
  9587. // ********************************************************************************************
  9588. // Now add the include paths to the end so that EDG knows where to find header files to process
  9589. // ********************************************************************************************
  9590. // Now add the include paths to the end so that EDG knows where to find head files to process
  9591. // Add all input include paths so that the EDG front end will know where to find headers
  9592. //AS(063006) Changed implementation so that real paths can be found later
  9593. vector<string> includePaths;
  9594. // skip the 0th entry since this is just the name of the program (e.g. rose)
  9595. for (unsigned int i=1; i < argv.size(); i++)
  9596. {
  9597. // most options appear as -<option>
  9598. // have to process +w2 (warnings option) on some compilers so include +<option>
  9599. if ( argv[i].size() >= 2 && (argv[i][0] == '-') && (argv[i][1] == 'I') )
  9600. {
  9601. // int length = strlen(argv[i]);
  9602. // printf ("Look for include path: argv[%d] = %s length = %d \n",i,argv[i],length);
  9603. // AS: Did changes to get absolute path
  9604. std::string includeDirectorySpecifier = argv[i].substr(2);
  9605. includeDirectorySpecifier = "-I"+StringUtility::getAbsolutePathFromRelativePath(includeDirectorySpecifier );
  9606. includePaths.push_back(includeDirectorySpecifier);
  9607. }
  9608. }
  9609. #if 0
  9610. for (int i=0; i < includePathCounter; i++)
  9611. {
  9612. printf (" includePaths[%d] = %s \n",i,includePaths[i]);
  9613. }
  9614. #endif
  9615. // Add the -I definitions to the command line
  9616. inputCommandLine.insert(inputCommandLine.end(), includePaths.begin(), includePaths.end());
  9617. // *******************************************************************
  9618. // Handle general edg options (-xxx)
  9619. // *******************************************************************
  9620. // Strip out all the -edg:xxx options and put them into the edg command line as -xxx
  9621. // Resets modifiedArgc and allocates memory to modifiedArgv
  9622. Rose_STL_Container<string> edgOptionList = CommandlineProcessing::generateOptionList (argv,"-edg:");
  9623. CommandlineProcessing::addListToCommandLine(inputCommandLine,"-",edgOptionList);
  9624. // *******************************************************************
  9625. // Handle general edg options (--xxx)
  9626. // *******************************************************************
  9627. // Strip out all the -edg:xxx options and put them into the edg command line as --xxx
  9628. // Resets modifiedArgc and allocates memory to modifiedArgv
  9629. edgOptionList = CommandlineProcessing::generateOptionList (argv,"--edg:");
  9630. // DQ (8/6/2006): there are a number of options that when specified in their EDG forms
  9631. // should turn on ROSE mechanisms. "--edg:c" should turn on C mode in ROSE.
  9632. // printf ("--edg option processing: edgOptionList.size() = %zu \n",edgOptionList.size());
  9633. Rose_STL_Container<string>::iterator i = edgOptionList.begin();
  9634. while (i != edgOptionList.end())
  9635. {
  9636. // fprintf (stderr, "edgOptionList: i = %s \n",i->c_str());
  9637. if (*i == "c" || *i == "old_c")
  9638. {
  9639. // This is the EDG option "--c" obtained from the ROSE "--edg:c" option
  9640. set_C_only(true);
  9641. }
  9642. if (*i == "c99")
  9643. {
  9644. // This is the EDG option "--c99" obtained from the ROSE "--edg:c99" option
  9645. set_C99_only(true);
  9646. }
  9647. i++;
  9648. }
  9649. CommandlineProcessing::addListToCommandLine(inputCommandLine,"--",edgOptionList);
  9650. // *******************************************************************
  9651. // Handle general edg options (-xxx abc)
  9652. // *******************************************************************
  9653. // Handle edg options taking a parameter (string or integer)
  9654. edgOptionList = CommandlineProcessing::generateOptionWithNameParameterList (argv,"-edg_parameter:");
  9655. CommandlineProcessing::addListToCommandLine(inputCommandLine,"-",edgOptionList);
  9656. // *******************************************************************
  9657. // Handle general edg options (--xxx abc)
  9658. // *******************************************************************
  9659. // Handle edg options taking a parameter (string or integer)
  9660. edgOptionList = CommandlineProcessing::generateOptionWithNameParameterList (argv,"--edg_parameter:");
  9661. CommandlineProcessing::addListToCommandLine(inputCommandLine,"--",edgOptionList);
  9662. // *******************************************************************
  9663. // Some EDG options have to turn on mechanims in ROSE
  9664. // *******************************************************************
  9665. #if 0
  9666. printf ("Some EDG options have to turn on mechanims in ROSE edgOptionList.size() = %ld \n",edgOptionList.size());
  9667. Rose_STL_Container<string>::iterator j = edgOptionList.begin();
  9668. while (j != edgOptionList.end())
  9669. {
  9670. printf ("edgOptionList: j = %s \n",j->c_str());
  9671. j++;
  9672. }
  9673. #endif
  9674. // *******************************************************************
  9675. // Handle specific edg options (-c)
  9676. // *******************************************************************
  9677. //
  9678. // specify compilation only option (new style command line processing)
  9679. //
  9680. #if 0
  9681. if ( CommandlineProcessing::isOption(argc,argv,"-","c",false) == true )
  9682. {
  9683. printf ("In build_EDG_CommandLine(): Option -c found (compile only)! \n");
  9684. set_compileOnly(true);
  9685. }
  9686. else
  9687. {
  9688. printf ("In build_EDG_CommandLine(): Option -c not found (compile AND link) adding --auto_instantiation ... \n");
  9689. Rose_STL_Container<string> additionalOptions_a;
  9690. Rose_STL_Container<string> additionalOptions_b;
  9691. // Even though this is not an error to EDG, it does not appear to force instantiation of all templates
  9692. additionalOptions_a.push_back("auto_instantiation");
  9693. CommandlineProcessing::addListToCommandLine(numberOfCommandLineArguments,inputCommandLine,"--",additionalOptions_a);
  9694. // DQ (5/12/05): Set the instantiation mode to "used" for specify what sort of templates to instantiate automatically
  9695. // (generate "-tused" instead of "--instantiate used" since EDG does not seems to accept options containing white space).
  9696. additionalOptions_b.push_back("tused");
  9697. CommandlineProcessing::addListToCommandLine(numberOfCommandLineArguments,inputCommandLine, "-",additionalOptions_b);
  9698. }
  9699. #else
  9700. bool autoInstantiation = false;
  9701. if ( CommandlineProcessing::isOption(argv,"-","c",false) == true )
  9702. {
  9703. // printf ("In build_EDG_CommandLine(): Option -c found (compile only)! \n");
  9704. set_compileOnly(true);
  9705. }
  9706. else
  9707. {
  9708. // printf ("In build_EDG_CommandLine(): Option -c not found (compile AND link) set autoInstantiation = true ... \n");
  9709. autoInstantiation = true;
  9710. }
  9711. if (isPrelinkPhase() == true)
  9712. {
  9713. printf ("In build_EDG_CommandLine(): isPrelinkPhase() == true set autoInstantiation = true ... \n");
  9714. autoInstantiation = true;
  9715. }
  9716. // DQ (10/15/2005): Trap out case of C programs where it is an EDG error to specify template instantiation details
  9717. if (get_C_only() == true ||get_C99_only() == true )
  9718. {
  9719. // printf ("In build_EDG_CommandLine(): compiling input as C program so turn off all template instantiation details \n");
  9720. autoInstantiation = false;
  9721. }
  9722. Rose_STL_Container<string> additionalOptions_a;
  9723. Rose_STL_Container<string> additionalOptions_b;
  9724. #if 1
  9725. if (autoInstantiation == true)
  9726. {
  9727. // printf ("In build_EDG_CommandLine(): autoInstantiation = true adding --auto_instantiation -tused ... \n");
  9728. // Even though this is not an error to EDG, it does not appear to force instantiation of all templates (because we need "-tused")
  9729. additionalOptions_a.push_back("auto_instantiation");
  9730. CommandlineProcessing::addListToCommandLine(inputCommandLine,"--",additionalOptions_a);
  9731. // DQ (5/12/05): Set the instantiation mode to "used" for specify what sort of templates to instantiate automatically
  9732. // (generate "-tused" instead of "--instantiate used" since EDG does not seems to accept options containing white space).
  9733. additionalOptions_b.push_back("tused");
  9734. CommandlineProcessing::addListToCommandLine(inputCommandLine, "-",additionalOptions_b);
  9735. }
  9736. else
  9737. {
  9738. // There are additional cases where we want to force instantiation of all used templates.
  9739. // DQ (5/20/2005): Force instantiation of all used templated unless it is specified to instantiate no templates (explicitly to ROSE)
  9740. bool instantiateAll = false;
  9741. if (get_project() != NULL)
  9742. {
  9743. instantiateAll = (get_project()->get_template_instantiation_mode() == SgProject::e_default) ||
  9744. (get_project()->get_template_instantiation_mode() == SgProject::e_used) ||
  9745. (get_project()->get_template_instantiation_mode() == SgProject::e_all) ||
  9746. (get_project()->get_template_instantiation_mode() == SgProject::e_local);
  9747. }
  9748. // printf ("get_project()->get_template_instantiation_mode() = %d \n",get_project()->get_template_instantiation_mode());
  9749. // printf ("In build_EDG_CommandLine(): instantiateAll = %s if true then adding --auto_instantiation -tlocal ... \n",
  9750. // instantiateAll ? "true" : "false");
  9751. // DQ (6/1/2005): This is the case of explicitly specifying the complation of C code and
  9752. // not C++ code (EDG reports an error if auto_instantiation is specified for this case).
  9753. if (get_C_only() == true || get_C99_only() == true)
  9754. {
  9755. // printf ("In build_EDG_CommandLine(): compiling input as C program so turn off all template instantiation details \n");
  9756. instantiateAll = false;
  9757. }
  9758. if (instantiateAll == true)
  9759. {
  9760. // printf ("In build_EDG_CommandLine(): autoInstantiation = true adding --auto_instantiation -tlocal ... \n");
  9761. additionalOptions_a.push_back("auto_instantiation");
  9762. CommandlineProcessing::addListToCommandLine(inputCommandLine,"--",additionalOptions_a);
  9763. // additionalOptions_b.push_back("tused");
  9764. additionalOptions_b.push_back("tlocal");
  9765. CommandlineProcessing::addListToCommandLine(inputCommandLine, "-",additionalOptions_b);
  9766. }
  9767. }
  9768. #else
  9769. // DQ (5/20/05): Set the instantiation mode to "used" for specify what sort of templates to instantiate automatically
  9770. // (generate "-tused" instead of "--instantiate used" since EDG does not seems to accept options containing white space).
  9771. printf ("In build_EDG_CommandLine(): autoInstantiation = true adding --auto_instantiation -tused ... \n");
  9772. // Even though this is not an error to EDG, it does not appear to force instantiation of all templates (because we need "-tused")
  9773. additionalOptions_a.push_back("auto_instantiation");
  9774. CommandlineProcessing::addListToCommandLine(inputCommandLine,"--",additionalOptions_a);
  9775. additionalOptions_b.push_back("tused");
  9776. CommandlineProcessing::addListToCommandLine(inputCommandLine, "-",additionalOptions_b);
  9777. #endif
  9778. #endif
  9779. // printf ("###### Located source filename = %s \n",get_sourceFileNameWithPath().c_str());
  9780. // ROSE_ASSERT ( get_numberOfSourceFileNames() > 0 );
  9781. ROSE_ASSERT ( get_sourceFileNameWithPath().empty() == false);
  9782. //AS Added support for absolute paths
  9783. Rose_STL_Container<string> fileList;
  9784. std::string sourceFile = get_sourceFileNameWithPath();
  9785. std::string sourceFilePath = StringUtility::getPathFromFileName(sourceFile);
  9786. sourceFile = StringUtility::stripPathFromFileName(sourceFile);
  9787. if(sourceFilePath == "" )
  9788. sourceFilePath = "./";
  9789. sourceFilePath = StringUtility::getAbsolutePathFromRelativePath(sourceFilePath);
  9790. fileList.push_back(sourceFilePath+"/"+sourceFile);
  9791. CommandlineProcessing::addListToCommandLine(inputCommandLine,"",fileList);
  9792. // AS Add Support for g++ style preincludes
  9793. // CommandlineProcessing::addListToCommandLine(inputCommandLine,"--preinclude ",listOfPreincludes);
  9794. // ROSE_ASSERT (saveSkipfinalCompileStep == p_skipfinalCompileStep);
  9795. // Debugging (verbose) output
  9796. if ( (get_verbose() > 1) )
  9797. {
  9798. std::string argString = CommandlineProcessing::generateStringFromArgList(inputCommandLine,false,false);
  9799. printf ("In build_EDG_CommandLine(): Input Command Line Arguments: \n%s \n",argString.c_str());
  9800. // Alternative way of displaying the commandline parameters
  9801. for (unsigned int i=0; i < inputCommandLine.size(); i++)
  9802. printf ("inputCommandLine[%u] = %s \n",i,inputCommandLine[i].c_str());
  9803. }
  9804. #if 0
  9805. printf ("Exiting at base of build_EDG_CommandLine() \n");
  9806. ROSE_ABORT();
  9807. #endif
  9808. // display("at base of build_EDG_CommandLine()");
  9809. }
  9810. #if 1
  9811. // DQ (2/11/2004): This is still defined in the ROSE/src/command_line_options
  9812. void
  9813. SgFile::usage ( int status )
  9814. {
  9815. if (status != 0)
  9816. fprintf (stderr,"Try option `--help' for more information.\n");
  9817. else
  9818. {
  9819. // it would be nice to insert the version of ROSE being used (using the VERSION macro)
  9820. fputs(
  9821. "\n"
  9822. "This ROSE translator provides a means for operating on C, C++, and Fortran\n"
  9823. "source code, as well as on x86 and ARM object code.\n"
  9824. "\n"
  9825. "Usage: rose [OPTION]... FILENAME...\n"
  9826. "\n"
  9827. "If a long option shows a mandatory argument, it is mandatory for the equivalent\n"
  9828. "short option as well, and similarly for optional arguments.\n"
  9829. "\n"
  9830. "Main operation mode:\n"
  9831. " -rose:(o|output) FILENAME\n"
  9832. " file containing final unparsed C++ code\n"
  9833. "\n"
  9834. "Operation modifiers:\n"
  9835. " -rose:C_only, -rose:C follow C89 standard, disable C++\n"
  9836. " -rose:C99_only, -rose:C99\n"
  9837. " follow C99 standard, disable C++\n"
  9838. " -rose:Fortran, -rose:F, -rose:f\n"
  9839. " compile Fortran code, determining version of\n"
  9840. " Fortran from file suffix)\n"
  9841. " -rose:Fortran77, -rose:F77, -rose:f77\n"
  9842. " compile Fortran 77 code\n"
  9843. " -rose:Fortran90, -rose:F90, -rose:f90\n"
  9844. " compile Fortran 90 code\n"
  9845. " -rose:Fortran95, -rose:F95, -rose:f95\n"
  9846. " compile Fortran 95 code\n"
  9847. " -rose:Fortran2003, -rose:F2003, -rose:f2003\n"
  9848. " compile Fortran 2003 code\n"
  9849. " -rose:strict strict enforcement of ANSI/ISO standards\n"
  9850. " -rose:astMerge merge ASTs from different files\n"
  9851. " -rose:astMergeCommandFile FILE\n"
  9852. " filename where compiler command lines are stored\n"
  9853. " for later processing (using AST merge mechanism)\n"
  9854. " -rose:compilationPerformanceFile FILE\n"
  9855. " filename where compiler performance for internal\n"
  9856. " phases (in CSV form) is placed for later\n"
  9857. " processing (using script/graphPerformance)\n"
  9858. " -rose:skip_rose process command line and call backend directly,\n"
  9859. " skipping all ROSE-specific processing\n"
  9860. " -rose:skip_transformation\n"
  9861. " read input file and skip all transformations\n"
  9862. " -rose:skip_unparse read and process input file but skip generation of\n"
  9863. " final C++ output file\n"
  9864. " -rose:unparse_includes unparse all include files into the source file.\n"
  9865. " This is a backup option for fail-safe processing\n"
  9866. " of CPP directives (which can be tricky)\n"
  9867. " -rose:collectAllCommentsAndDirectives\n"
  9868. " store all comments and CPP directives in header\n"
  9869. " files into the AST\n"
  9870. " -rose:excludeCommentsAndDirectives PATH\n"
  9871. " provide path to exclude when using the\n"
  9872. " collectAllCommentsAndDirectives option\n"
  9873. " -rose:excludeCommentsAndDirectivesFrom FILENAME\n"
  9874. " provide filename to file with paths to exclude\n"
  9875. " when using the collectAllCommentsAndDirectives\n"
  9876. " option\n"
  9877. " -rose:includeCommentsAndDirectives PATH\n"
  9878. " provide path to include when using the\n"
  9879. " collectAllCommentsAndDirectives option\n"
  9880. " -rose:includeCommentsAndDirectivesFrom FILENAME\n"
  9881. " provide filename to file with paths to include\n"
  9882. " when using the collectAllCommentsAndDirectives\n"
  9883. " option\n"
  9884. " -rose:skip_commentsAndDirectives\n"
  9885. " ignore all comments and CPP directives (can\n"
  9886. " generate (unparse) invalid code if not used with\n"
  9887. " -rose:unparse_includes)\n"
  9888. " -rose:skipfinalCompileStep\n"
  9889. " read input file and skip all transformations\n"
  9890. " -rose:prelink activate prelink mechanism to force instantiation\n"
  9891. " of templates and assignment to files\n"
  9892. " -rose:instantiation XXX control template instantiation\n"
  9893. " XXX is one of (none, used, all, local)\n"
  9894. "\n"
  9895. "GNU g++ options recognized:\n"
  9896. " -ansi equivalent to -rose:strict\n"
  9897. " -fno-implicit-templates disable output of template instantiations in\n"
  9898. " generated source\n"
  9899. " -fno-implicit-inline-templates\n"
  9900. " disable output of inlined template instantiations\n"
  9901. " in generated source\n"
  9902. "\n"
  9903. "Informative output:\n"
  9904. " -rose:help, --help, -help, --h\n"
  9905. " print this help, then exit\n"
  9906. " -rose:version, --version, --V\n"
  9907. " print ROSE program version number, then exit\n"
  9908. " -rose:markGeneratedFiles\n"
  9909. " add \"#define ROSE_GENERATED_CODE\" to top of all\n"
  9910. " generated code\n"
  9911. " -rose:verbose [LEVEL] verbosely list internal processing (default=0)\n"
  9912. " Higher values generate more output (can be\n"
  9913. " applied to individual files and to the project\n"
  9914. " separately).\n"
  9915. " -rose:embedColorCodesInGeneratedCode LEVEL\n"
  9916. " embed color codes into generated output for\n"
  9917. " visualization of highlighted text using tview\n"
  9918. " tool for constructs specified by LEVEL\n"
  9919. " LEVEL is one of:\n"
  9920. " 1: missing position information\n"
  9921. " 2: compiler-generated code\n"
  9922. " 3: other code\n"
  9923. " -rose:generateSourcePositionCodes LEVEL\n"
  9924. " generate separate file of source position\n"
  9925. " information for highlighting original source\n"
  9926. " file using tview tool for constructs specified\n"
  9927. " by LEVEL\n"
  9928. " LEVEL is one of:\n"
  9929. " 1: statements, preprocessor directives and\n"
  9930. " comments\n"
  9931. " 2: expressions\n"
  9932. "\n"
  9933. "Control EDG frontend processing:\n"
  9934. " -edg:new_frontend force use of external EDG front end (disables use\n"
  9935. " of rest of ROSE/SAGE)\n"
  9936. " -edg:KCC_frontend for use of KCC (with -c option) as new frontend\n"
  9937. " (must be specified with -edg:new_frontend)\n"
  9938. " -edg:XXX pass -XXX to EDG front-end\n"
  9939. " --edg:XXX pass --XXX to EDG front-end\n"
  9940. " -edg_parameter: XXX YYY pass -XXX YYY to EDG front-end\n"
  9941. " --edg_parameter: XXX YYY pass --XXX YYY to EDG front-end\n"
  9942. "\n"
  9943. "Control code generation:\n"
  9944. " -rose:C_output_language\n"
  9945. " force use of C as output language (currently\n"
  9946. " generates C/C++)\n"
  9947. " -rose:Cxx_output_language\n"
  9948. " force use of C++ as output language\n"
  9949. " -rose:Fortran_output_language\n"
  9950. " force use of Fortran as output language\n"
  9951. " -rose:Promela_output_language\n"
  9952. " force use of Promela as output language (not\n"
  9953. " supported)\n"
  9954. "\n"
  9955. "Testing Options:\n"
  9956. " -rose:negative_test test ROSE using input that is expected to fail\n"
  9957. " (returns 0 if input test failed, else error if\n"
  9958. " passed)\n"
  9959. " -rose:test LEVEL limit parts of ROSE which are run\n"
  9960. " LEVEL is one of:\n"
  9961. " 0: transparent (ROSE translator does nothing)\n"
  9962. " 1: run the KCC front end only (assumes it is in\n"
  9963. " path)\n"
  9964. " 2: run the newer version of EDG (compiled\n"
  9965. " separately from SAGE) 'edgFrontEnd'\n"
  9966. " (see\n"
  9967. " src/frontend/EDG/EDG_3.3/src/Makefile.am\n"
  9968. " for instructions on how to build EDG\n"
  9969. " without SAGE III)\n"
  9970. " 3: run internal (older) version of edg front end\n"
  9971. " (deprecated option)\n"
  9972. " 4: same as 3 plus parse into Sage III program\n"
  9973. " tree\n"
  9974. " 5: same as 4 plus unparse untransformed source\n"
  9975. " code\n"
  9976. " 6: same as 5 plus compile generated source code\n"
  9977. " 7: same as 5 plus build higher level grammars\n"
  9978. " before unparsing\n"
  9979. " 8: same as 6 plus run midend (transformations)\n"
  9980. " before unparsing\n"
  9981. "\n"
  9982. "Report bugs to <dquinlan@llnl.gov>.\n"
  9983. , stdout);
  9984. // Obsolete options
  9985. // -sage:sage_backend have EDG call the sage backend
  9986. // -sage:disable_cp_backend prevent EDG from calling the cp backend
  9987. // -rose:outputGrammarTreeFiles write out program tree representation in C++ grammar (useful for internal debugging)
  9988. // -rose:outputGrammarTreeFilesForHeaderFiles (include header files in above option (must be specified after above option)
  9989. // DQ (5/20/2005): More obsolete options
  9990. // -edg:disable_edg_backend prevent EDG from calling the sage backend
  9991. // -sage:disable_sage_backend prevent EDG from calling the sage backend
  9992. // -sage:enable_cp_backend have EDG call the cp backend
  9993. // -sage:preinit_il do a preinit stage between the front-end and
  9994. }
  9995. #if 1
  9996. // Comment this out for now while we test!
  9997. exit (status);
  9998. #endif
  9999. }
  10000. #endif
  10001. //! get the current directory
  10002. string
  10003. SgFile::getWorkingDirectory ()
  10004. {
  10005. int i = 0; // index variable declaration
  10006. const int maxPathNameLength = 1024;
  10007. char* currentDirectory = new char [maxPathNameLength];
  10008. for (i=0; i < maxPathNameLength; i++)
  10009. currentDirectory[i] = '\0'; // set to NULL string
  10010. char* returnString = getcwd(currentDirectory,maxPathNameLength - 1);
  10011. ROSE_ASSERT (returnString != NULL);
  10012. currentDirectory[maxPathNameLength - 1] = 0; // Just in case
  10013. // The semantics of the getcwd is that these shuld be the same (see if they are)
  10014. // printf ("In ROSE::getWorkingDirectory: Current directory = %s \n",currentDirectory);
  10015. // printf ("In ROSE::getWorkingDirectory: Current directory = %s \n",returnString);
  10016. // live with the possible memory leak for now
  10017. // delete currentDirectory;
  10018. currentDirectory = NULL;
  10019. return returnString;
  10020. }
  10021. //! get the source directory
  10022. string
  10023. SgFile::getSourceDirectory ()
  10024. {
  10025. #if 0
  10026. int i = 0; // index variable declaration
  10027. const int maxPathNameLength = 1024;
  10028. char* currentDirectory = new char [maxPathNameLength];
  10029. for (i=0; i < maxPathNameLength; i++)
  10030. currentDirectory[i] = '\0'; // set to NULL string
  10031. #endif
  10032. printf ("SgFile::getSourceDirectory not implemented! \n");
  10033. ROSE_ABORT();
  10034. return "";
  10035. }
  10036. string
  10037. SgFile::generateOutputFileName() const
  10038. {
  10039. // DQ (10/16/2005): This function abstracts the generation of an
  10040. // output file name from the source file name.
  10041. std::string sourceFileName = get_sourceFileNameWithPath();
  10042. // std::string baseFileName = ROSE::stripPathFromFileName(sourceFileName.c_str());
  10043. std::string baseFileName = StringUtility::stripPathFromFileName(sourceFileName);
  10044. std::string baseFileNameWithoutSuffix = StringUtility::stripFileSuffixFromFileName(baseFileName);
  10045. // printf ("sourceFileName = %s oldFileName = %s\n",sourceFileName.c_str(),baseFileName.c_str());
  10046. std::string objectFileName;
  10047. // DQ (1/17/2006): test this
  10048. // ROSE_ASSERT(get_fileInfo() != NULL);
  10049. #if 0
  10050. printf ("sourceFileName = %s \n",sourceFileName.c_str());
  10051. printf ("baseFileName = %s \n",baseFileName.c_str());
  10052. printf ("baseFileNameWithoutSuffix = %s \n",baseFileNameWithoutSuffix.c_str());
  10053. #endif
  10054. #ifndef USE_ORIGINAL_SOURCE_FILE_NAME_IN_PRELINKING
  10055. // DQ (8/12/2007): I think this was part of the prelinker which is not no longer used!
  10056. // printf ("isPrelinkPhase() = %s \n",isPrelinkPhase() ? "true" : "false");
  10057. ROSE_ASSERT(isPrelinkPhase() == false);
  10058. if (isPrelinkPhase() == true)
  10059. {
  10060. // test for leading "rose_" prefix in name (it should be present)
  10061. ROSE_ASSERT(baseFileName.find("rose_") == 0);
  10062. // and remove it since we want the unmodified file name to be used as a name of the object file!
  10063. baseFileName.erase(0,5);
  10064. // test for leading "rose_" prefix in name (it should NOT be present now)
  10065. ROSE_ASSERT(baseFileName.find("rose_") == std::string::npos);
  10066. }
  10067. #endif
  10068. #if 0
  10069. // DQ (12/5/2006): Make sure that the baseFileName is long enough (fixed small filename test).
  10070. // DQ (12/8/2004): Build the *.o file based on the old name not the new name (what was I thinking!)
  10071. // AS(07/07/04) modified to create .o files for .cpp files also
  10072. // if ( baseFileName.substr(baseFileName.length()-4, baseFileName.length()) == std::string(".cpp") )
  10073. if ( (baseFileName.length() >= 4) && (baseFileName.substr(baseFileName.length()-4, baseFileName.length()) == std::string(".cpp") ) )
  10074. {
  10075. objectFileName = baseFileName.substr(0,baseFileName.length()-4) + std::string(".o");
  10076. }
  10077. else
  10078. {
  10079. // DQ (12/5/2006): Make sure that the baseFileName is long enough (fixed small filename test).
  10080. // DQ (9/10/2004): Added support for ".cc" suffix to handle KOLAH and Kull files
  10081. // if ( baseFileName.substr(baseFileName.length()-3, baseFileName.length()) == std::string(".cc") )
  10082. if ( (baseFileName.length() >= 3) && (baseFileName.substr(baseFileName.length()-3, baseFileName.length()) == std::string(".cc") ) )
  10083. {
  10084. objectFileName = baseFileName.substr(0,baseFileName.length()-3) + std::string(".o");
  10085. }
  10086. else
  10087. {
  10088. // DQ (12/5/2006): Added a lower bound for baseFileName size.
  10089. if (baseFileName.length() >= 2)
  10090. {
  10091. objectFileName = baseFileName.substr(0,baseFileName.length()-2) + std::string(".o");
  10092. }
  10093. else
  10094. {
  10095. printf ("Error: base filename = %s is too short \n",baseFileName.c_str());
  10096. // Maybe we should allow this to a least be defined if we decide later that files names can be allowed to be this short.
  10097. objectFileName = baseFileName;
  10098. }
  10099. ROSE_ASSERT(baseFileName.length() >= 2);
  10100. }
  10101. }
  10102. #else
  10103. // DQ (8/12/2007): Newer simpler code, made possible because of better internal support.
  10104. // This version is also now language independent and so supports the Fortran work.
  10105. objectFileName = baseFileNameWithoutSuffix + ".o";
  10106. #endif
  10107. // printf ("At base of SgFile::generateOutputFileName(): objectFileName = %s \n",objectFileName.c_str());
  10108. // display("In SgFile::generateOutputFileName()");
  10109. return objectFileName;
  10110. }
  10111. string
  10112. SgFile::buildCompilerCommandLineOptions ( vector<string> & argv, int fileNameIndex, const string& compilerName )
  10113. {
  10114. // This function assembles the commandline that will be passed to the backend (vendor) C++/C compiler
  10115. // (using the new generated source code from the ROSE unparser).
  10116. // DQ (4/21/2006): I think we can now assert this!
  10117. ROSE_ASSERT(fileNameIndex == 0);
  10118. // display("Data in SgFile in buildCompilerCommandLineOptions()");
  10119. // To use rose in place of a C or C++ compiler specify the compiler name using
  10120. // rose -compiler <originalCompilerName> ...
  10121. // the default value of "originalCompilerName" is "CC"
  10122. std::string compilerNameString = compilerName;
  10123. // DQ (1/17/2006): test this
  10124. // ROSE_ASSERT(get_fileInfo() != NULL);
  10125. #if 0
  10126. printf ("C compiler = %s \n",BACKEND_C_COMPILER_NAME_WITH_PATH);
  10127. printf ("C++ compiler = %s \n",BACKEND_CXX_COMPILER_NAME_WITH_PATH);
  10128. printf ("get_C_only() = %s \n",(get_C_only() == true) ? "true" : "false");
  10129. printf ("get_C99_only() = %s \n",(get_C99_only() == true) ? "true" : "false");
  10130. printf ("get_Fortran_only() = %s \n",(get_Fortran_only() == true) ? "true" : "false");
  10131. printf ("get_F77_only() = %s \n",(get_F77_only() == true) ? "true" : "false");
  10132. printf ("get_F90_only() = %s \n",(get_F90_only() == true) ? "true" : "false");
  10133. printf ("get_F95_only() = %s \n",(get_F95_only() == true) ? "true" : "false");
  10134. printf ("get_F2003_only() = %s \n",(get_F2003_only() == true) ? "true" : "false");
  10135. #endif
  10136. // DQ (9/10/2006): We now explicitly store the C and C++ compiler names with
  10137. // paths so that we can assemble the final commandline to compile the generated
  10138. // code within ROSE.
  10139. // We need a better way of identifying the C compiler which might not be known
  10140. // ideally it should be specified at configure time so that it can be known in
  10141. // case the -rose:C_only option is used.
  10142. if (get_C_only() == true || get_C99_only() == true)
  10143. {
  10144. // compilerNameString = "gcc ";
  10145. compilerNameString = BACKEND_C_COMPILER_NAME_WITH_PATH;
  10146. }
  10147. else
  10148. {
  10149. compilerNameString = BACKEND_CXX_COMPILER_NAME_WITH_PATH;
  10150. if (get_Fortran_only() == true)
  10151. {
  10152. // compilerNameString = "f77 ";
  10153. compilerNameString = "gfortran ";
  10154. }
  10155. }
  10156. // printf ("compilerName = %s \n",compilerName);
  10157. // printf ("compilerNameString = %s \n",compilerNameString.c_str());
  10158. if (compilerNameString.find("icc") != string::npos)
  10159. {
  10160. // This is the Intel C compiler: icc, we need to add the -restrict option
  10161. compilerNameString += " -restrict";
  10162. }
  10163. if (compilerNameString.find("icpc") != string::npos)
  10164. {
  10165. // This is the Intel C++ compiler: icc, we need to add the -restrict option
  10166. compilerNameString += " -restrict";
  10167. }
  10168. // DQ (9/24/2006): Not clear if we want this, if we just skip stripping it out then it will be passed to the backend directly!
  10169. // But we have to add it in the case of "-rose:strict", so we have to add it uniformally and strip it from the input.
  10170. if (get_strict_language_handling() == true)
  10171. {
  10172. // Check if it is appears as "-ansi" on the original commandline
  10173. if ( CommandlineProcessing::isOption(argv,"-","ansi",false) == true )
  10174. {
  10175. printf ("Option -ansi detected on the original commandline \n");
  10176. }
  10177. else
  10178. {
  10179. // This is might be specific to GNU
  10180. compilerNameString += " -ansi ";
  10181. }
  10182. }
  10183. // printf ("Selected compiler = %s \n",compilerNameString.c_str());
  10184. // Since we need to do this often, support is provided in the utility_functions.C
  10185. // and we can simplify this code.
  10186. std::string currentDirectory = getWorkingDirectory();
  10187. // printf ("In buildCompilerCommandLineOptions(): currentDirectory = %s \n",currentDirectory);
  10188. // specify compilation only option (new style command line processing)
  10189. if ( CommandlineProcessing::isOption(argv,"-","c",false) == true )
  10190. {
  10191. // printf ("Option -c found (compile only)! \n");
  10192. set_compileOnly(true);
  10193. }
  10194. else
  10195. {
  10196. // printf ("Option -c not found (compile AND link) ... \n");
  10197. // compilerNameString += " -c ";
  10198. }
  10199. // DQ (3/31/2004): New cleaned up source file handling
  10200. Rose_STL_Container<string> argcArgvList = argv;
  10201. // DQ (9/25/2007): Moved to std::vector from std::list uniformally within ROSE.
  10202. // Remove the first argument (argv[0])
  10203. // argcArgvList.pop_front();
  10204. argcArgvList.erase(argcArgvList.begin());
  10205. SgProject* project = isSgProject(this->get_parent());
  10206. ROSE_ASSERT (project != NULL);
  10207. Rose_STL_Container<string> sourceFilenames = project->get_sourceFileNameList();
  10208. // printf ("sourceFilenames.size() = %zu sourceFilenames = %s \n",sourceFilenames.size(),StringUtility::listToString(sourceFilenames).c_str());
  10209. // DQ (4/20/2006): Modified to only do this when generating code and compiling it
  10210. // Remove the source names from the argcArgvList (translated versions of these will be inserted later)
  10211. // if (get_skip_unparse() == true && get_skipfinalCompileStep() == false)
  10212. if (get_skip_unparse() == false)
  10213. {
  10214. for (Rose_STL_Container<string>::iterator i = sourceFilenames.begin(); i != sourceFilenames.end(); i++)
  10215. {
  10216. // printf ("Removing sourceFilenames list element i = %s \n",(*i).c_str());
  10217. #if USE_ABSOLUTE_PATHS_IN_SOURCE_FILE_LIST
  10218. #error "USE_ABSOLUTE_PATHS_IN_SOURCE_FILE_LIST is not supported yet"
  10219. // DQ (9/1/2006): Check for use of absolute path and convert filename to absolute path if required
  10220. bool usesAbsolutePath = ((*i)[0] == '/');
  10221. if (usesAbsolutePath == false)
  10222. {
  10223. string targetSourceFileToRemove = StringUtility::getAbsolutePathFromRelativePath(*i);
  10224. // printf ("Converting source file to absolute path to search for it and remove it! targetSourceFileToRemove = %s \n",targetSourceFileToRemove.c_str());
  10225. argcArgvList.remove(targetSourceFileToRemove);
  10226. }
  10227. else
  10228. {
  10229. // printf ("This source file used the absolute path so no conversion to absolute path is required! \n");
  10230. argcArgvList.remove(*i);
  10231. }
  10232. #else
  10233. // DQ (9/25/2007): Moved to std::vector from std::list uniformally within ROSE.
  10234. // printf ("Skipping test for absolute path removing the source filename as it appears in the source file name list file = % \n",i->c_str());
  10235. // argcArgvList.remove(*i);
  10236. argcArgvList.erase(find(argcArgvList.begin(),argcArgvList.end(),*i));
  10237. #endif
  10238. }
  10239. }
  10240. // printf ("After removing source file name: argcArgvList.size() = %zu argcArgvList = %s \n",argcArgvList.size(),StringUtility::listToString(argcArgvList).c_str());
  10241. // ROSE_ASSERT(false);
  10242. // AS(080704) Fix so that if user specifies name of -o file rose do not specify another in addition
  10243. bool objectNameSpecified = false;
  10244. for (Rose_STL_Container<string>::iterator i = argcArgvList.begin(); i != argcArgvList.end(); i++)
  10245. {
  10246. // printf ("In SgFile::buildCompilerCommandLineOptions(): Loop over commandline arguments i = %s \n",i->c_str());
  10247. // DQ (8/17/2006): This fails for directories such as "ROSE/projects/OpenMP_Translator/tests/npb2.3-omp-c"
  10248. // which can be repeated in the specification of include directives on the commandline.
  10249. // We need to check for the leading characters and nothing else.
  10250. // if (i->find("-o") != std::string::npos)
  10251. // if (i->find("-o ") != std::string::npos)
  10252. // printf ("i->substr(0,2) = %s \n",i->substr(0,2).c_str());
  10253. if (i->substr(0,2) == "-o")
  10254. {
  10255. // DQ (6/12/2005): Added error checking!
  10256. if (objectNameSpecified == true)
  10257. {
  10258. // Error: "-o" has been specified twice
  10259. printf ("Error: \"-o \" has been specified twice \n");
  10260. }
  10261. ROSE_ASSERT(objectNameSpecified == false);
  10262. objectNameSpecified = true;
  10263. }
  10264. }
  10265. // DQ (4/14/2005): Fixup quoted strings in args fix "-DTEST_STRING_MACRO="Thu Apr 14 08:18:33 PDT 2005"
  10266. // to be -DTEST_STRING_MACRO=\""Thu Apr 14 08:18:33 PDT 2005"\" This is a problem in the compilation of
  10267. // a Kull file (version.cc), when the backend is specified as /usr/apps/kull/tools/mpig++-3.4.1. The
  10268. // problem is that /usr/apps/kull/tools/mpig++-3.4.1 is a wrapper for a shell script /usr/local/bin/mpiCC
  10269. // which does not tend to observe quotes well. The solution is to add additional escaped quotes.
  10270. for (Rose_STL_Container<string>::iterator i = argcArgvList.begin(); i != argcArgvList.end(); i++)
  10271. {
  10272. #if 0
  10273. printf ("sizeof(std::string::size_type) = %d \n",sizeof(std::string::size_type));
  10274. printf ("sizeof(std::string::iterator) = %d \n",sizeof(std::string::iterator));
  10275. printf ("sizeof(unsigned int) = %d \n",sizeof(unsigned int));
  10276. printf ("sizeof(unsigned long) = %d \n",sizeof(unsigned long));
  10277. #endif
  10278. // DQ (1/26/2006): Fix for 64 bit support.
  10279. // unsigned int startingQuote = i->find("\"");
  10280. std::string::size_type startingQuote = i->find("\"");
  10281. if (startingQuote != std::string::npos)
  10282. {
  10283. // This string at least has a quote
  10284. // unsigned int endingQuote = i->rfind("\"");
  10285. std::string::size_type endingQuote = i->rfind("\"");
  10286. // There should be a double quote on both ends of the string
  10287. ROSE_ASSERT (endingQuote != std::string::npos);
  10288. std::string quotedSubstring = i->substr(startingQuote,endingQuote);
  10289. // printf ("quotedSubstring = %s \n",quotedSubstring.c_str());
  10290. std::string fixedQuotedSubstring = std::string("\\\"") + quotedSubstring + std::string("\\\"");
  10291. // printf ("fixedQuotedSubstring = %s \n",fixedQuotedSubstring.c_str());
  10292. // Now replace the quotedSubstring with the fixedQuotedSubstring
  10293. i->replace(startingQuote,endingQuote,fixedQuotedSubstring);
  10294. // printf ("Modified argument = %s \n",(*i).c_str());
  10295. }
  10296. }
  10297. // Add any options specified by the user (and add space at the end)
  10298. compilerNameString += std::string(" ") + StringUtility::listToString(argcArgvList) + std::string(" ");
  10299. // printf ("buildCompilerCommandLineOptions() #1: compilerNameString = \n%s \n",compilerNameString.c_str());
  10300. std::string sourceFileName = get_sourceFileNameWithPath();
  10301. std::string oldFileNamePathOnly = ROSE::getPathFromFileName(sourceFileName.c_str());
  10302. std::string oldFileName = ROSE::stripPathFromFileName(sourceFileName.c_str());
  10303. #if 0
  10304. printf ("oldFileNamePathOnly = %s \n",oldFileNamePathOnly.c_str());
  10305. printf ("oldFileName = %s \n",oldFileName.c_str());
  10306. #endif
  10307. // DQ (12/8/2004): Add -Ipath option so that source file's directory will be searched for any
  10308. // possible headers. This is especially important when we are compiling the generated file
  10309. // located in a different directory! (When the original source file included header files
  10310. // in the source directory!) This is only important when get_useBackendOnly() == false
  10311. // since otherwise the source file is the original source file and the compiler will search
  10312. // its directory for header files. Be sure the put the oldFile's source directory last in the
  10313. // list of -I options so that it will be searched last (preserving the semantics of #include "...").
  10314. // Only add the path if it is a valid name (not an empty name, in which case skip it since the oldFile
  10315. // is in the current directory (likely a generated file itself; e.g. swig or ROSE applied recursively, etc.)).
  10316. // printf ("oldFileNamePathOnly.length() = %d \n",oldFileNamePathOnly.length());
  10317. if (oldFileNamePathOnly.empty() == false)
  10318. compilerNameString += std::string("-I") + oldFileNamePathOnly + " ";
  10319. // DQ (4/20/2006): This allows the ROSE translator to be just a wrapper for the backend (vendor) compiler.
  10320. // compilerNameString += get_unparse_output_filename();
  10321. if (get_skip_unparse() == false)
  10322. {
  10323. // Generate the name of the ROSE generated source file (instead of the original source file)
  10324. // this file will be compiled by the backend (vendor) compiler.
  10325. ROSE_ASSERT(get_unparse_output_filename().empty() == false);
  10326. compilerNameString += get_unparse_output_filename();
  10327. }
  10328. else
  10329. {
  10330. // In this case the compilerNameString already has the original file name since it was not removed
  10331. // compilerNameString += get_unparse_output_filename();
  10332. // printf ("Case of skip_unparse() == true: original source file name should be present compilerNameString = %s \n",compilerNameString.c_str());
  10333. }
  10334. if ( get_compileOnly() == true )
  10335. {
  10336. std::string objectFileName = generateOutputFileName();
  10337. // printf ("In buildCompilerCommandLineOptions: objectNameSpecified = %s objectFileName = %s \n",objectNameSpecified ? "true" : "false",objectFileName.c_str());
  10338. // DQ (7/14/2004): Suggested fix from Andreas
  10339. if (objectNameSpecified == false)
  10340. {
  10341. compilerNameString += " -o " + currentDirectory + "/" + objectFileName;
  10342. }
  10343. }
  10344. // printf ("At base of buildCompilerCommandLineOptions: compilerNameString = \n%s\n",compilerNameString.c_str());
  10345. #if 0
  10346. printf ("Exiting at base of buildCompilerCommandLineOptions() ... \n");
  10347. ROSE_ASSERT (false);
  10348. #endif
  10349. return compilerNameString;
  10350. }
  10351. // Forward declarations of classes used to control and tailor the code generation.
  10352. // class UnparseDelegate;
  10353. // class UnparseFormatHelp;
  10354. // DQ (3/18/2006): Modified interface to allow specification of pointer to user
  10355. // defined UnparseFormatHelp object (to control code generation).
  10356. // DQ (8/20/2005): Removed default parameter from extern function declaration
  10357. // extern void unparseFile( SgFile&, UnparseDelegate* repl = NULL );
  10358. extern void unparseFile( SgFile* file, UnparseFormatHelp *unparseFormatHelp = NULL, UnparseDelegate* unparseDelegate = NULL );
  10359. void
  10360. // SgFile::unparse ()
  10361. SgFile::unparse ( UnparseFormatHelp *unparseFormatHelp, UnparseDelegate* unparseDelegate )
  10362. {
  10363. // DQ (7/12/2005): Introduce tracking of performance of ROSE.
  10364. TimingPerformance timer ("AST Code Generation (unparsing):");
  10365. // DQ (1/17/2006): test this
  10366. // ROSE_ASSERT(get_fileInfo() != NULL);
  10367. // printf ("Inside of SgFile::unparse () ROSE_DEBUG = %d \n",ROSE_DEBUG);
  10368. #if 0
  10369. // DQ (4/21/2006): this has been moved to the backen unparseFile function (as late as possible)
  10370. ROSE_ASSERT (get_unparse_output_filename().empty() == true);
  10371. string outputFilename;
  10372. if (get_skip_unparse() == true)
  10373. {
  10374. // We we are skipping the unparsing then we didn't generate an intermediate
  10375. // file and so we want to compile the original source file.
  10376. outputFilename = get_sourceFileNameWithPath();
  10377. }
  10378. else
  10379. {
  10380. // If we did unparse an intermediate file then we want to compile that
  10381. // file instead of the original source file.
  10382. outputFilename = "rose_" + get_sourceFileNameWithoutPath();
  10383. }
  10384. set_unparse_output_filename(outputFilename);
  10385. ROSE_ASSERT (get_unparse_output_filename().empty() == false);
  10386. printf ("Inside of SgFile::unparse(UnparseFormatHelp*,UnparseDelegate*) outputFilename = %s \n",outputFilename.c_str());
  10387. #endif
  10388. // Check that these are set and not reset to null!
  10389. // ROSE_ASSERT (p_commandLineArgumentList != NULL);
  10390. // Call the unparser mechanism
  10391. // unparseFile ( *this );
  10392. unparseFile ( this, unparseFormatHelp, unparseDelegate );
  10393. // Check that these are set and not reset to null!
  10394. // ROSE_ASSERT (p_commandLineArgumentList != NULL);
  10395. }
  10396. int
  10397. SgFile::compileOutput ( vector<string>& argv, int fileNameIndex, const string& compilerNameOrig )
  10398. {
  10399. // DQ (7/12/2005): Introduce tracking of performance of ROSE.
  10400. TimingPerformance timer ("AST Object Code Generation (compile output):");
  10401. // DQ (4/21/2006): I think we can now assert this!
  10402. ROSE_ASSERT(fileNameIndex == 0);
  10403. // This function does the final compilation of the unparsed file
  10404. // Remaining arguments from the original compile time are used as well
  10405. // as additional arguments added by the buildCompilerCommandLineOptions() function
  10406. // DQ NOTE: This function has to be modified to compile more than
  10407. // just one file (as part of the multi-file support)
  10408. // ROSE_ASSERT (sageProject.numberOfFiles() == 1);
  10409. // ******************************************************************************
  10410. // At this point in the control flow (for ROSE) we have returned from the processing
  10411. // via the EDG frontend (or skipped it if that option was specified).
  10412. // The following has been done or explicitly skipped if such options were specified
  10413. // on the commandline:
  10414. // 1) The application program has been parsed
  10415. // 2) All AST's have been build (one for each grammar)
  10416. // 3) The transformations have been edited into the C++ AST
  10417. // 4) The C++ AST has been unparsed to form the final output file (all code has
  10418. // been generated into a different filename)
  10419. // ******************************************************************************
  10420. // What remains is to run the specified compiler (typically the C++ compiler) using
  10421. // the generated output file (unparsed and transformed application code).
  10422. int returnValueForRose = 0;
  10423. // DQ (1/17/2006): test this
  10424. // ROSE_ASSERT(get_fileInfo() != NULL);
  10425. // BP : 11/13/2001, checking to see that the compiler name is set
  10426. string compilerName = compilerNameOrig + " ";
  10427. // DQ (4/21/2006): Setup the output file name.
  10428. // Rose_STL_Container<string> fileList = CommandlineProcessing::generateSourceFilenames(argc,argv);
  10429. // ROSE_ASSERT (fileList.size() == 1);
  10430. // p_sourceFileNameWithPath = *(fileList.begin());
  10431. // p_sourceFileNameWithoutPath = ROSE::stripPathFromFileName(p_sourceFileNameWithPath.c_str());
  10432. #if 1
  10433. // ROSE_ASSERT (get_unparse_output_filename().empty() == true);
  10434. // DQ (4/21/2006): If we have not set the unparse_output_filename then we could not have called
  10435. // unparse and we want to compile the original source file as a backup mechanism to generate an
  10436. // object file.
  10437. if (get_unparse_output_filename().empty() == true)
  10438. {
  10439. ROSE_ASSERT(get_skip_unparse() == true);
  10440. string outputFilename = get_sourceFileNameWithPath();
  10441. #if 0
  10442. if (get_skip_unparse() == true)
  10443. {
  10444. // We we are skipping the unparsing then we didn't generate an intermediate
  10445. // file and so we want to compile the original source file.
  10446. outputFilename = get_sourceFileNameWithPath();
  10447. }
  10448. else
  10449. {
  10450. // If we did unparse an intermediate file then we want to compile that
  10451. // file instead of the original source file.
  10452. outputFilename = "rose_" + get_sourceFileNameWithoutPath();
  10453. }
  10454. #endif
  10455. set_unparse_output_filename(outputFilename);
  10456. // DQ (6/25/2006): I think it is OK to not have an output file name specified.
  10457. // display ("In SgFile::compileOutput(): get_unparse_output_filename().empty() == true");
  10458. }
  10459. #endif
  10460. ROSE_ASSERT (get_unparse_output_filename().empty() == false);
  10461. // Now call the compiler that rose is replacing
  10462. // if (get_useBackendOnly() == false)
  10463. if ( SgProject::get_verbose() >= 1 )
  10464. printf ("Now call the backend (vendor's) compiler for file = %s \n",get_unparse_output_filename().c_str());
  10465. // Build the commandline to hand off to the C++/C compiler
  10466. std::string compilerNameString = buildCompilerCommandLineOptions (argv,fileNameIndex, compilerName );
  10467. // ROSE_ASSERT (compilerNameString != NULL);
  10468. int returnValueForCompiler = 0;
  10469. // error checking
  10470. // display("Called from SgFile::compileOutput()");
  10471. // allow conditional skipping of the final compile step for testing ROSE
  10472. if (get_skipfinalCompileStep() == false)
  10473. {
  10474. if ( get_verbose() > 1 )
  10475. printf ("calling system(%s) \n",compilerNameString.c_str());
  10476. returnValueForCompiler = system (compilerNameString.c_str());
  10477. }
  10478. else
  10479. {
  10480. if ( get_verbose() > 1 )
  10481. printf ("COMPILER NOT CALLED: compilerNameString = %s \n",compilerNameString.c_str());
  10482. printf ("Skipped call to backend vendor compiler! \n");
  10483. }
  10484. // DQ (7/20/2006): Catch errors returned from unix "system" function (commonly "out of memory" errors, suggested by Peter and Jeremiah).
  10485. if (returnValueForCompiler < 0)
  10486. {
  10487. perror("Serious Error returned from internal system command");
  10488. }
  10489. // Assemble an exit status that combines the values for ROSE and the C++/C compiler
  10490. // return an exit status which is the boolean OR of the bits from the EDG/SAGE/ROSE and the compile step
  10491. int finalCompiledExitStatus = returnValueForRose | returnValueForCompiler;
  10492. // It is a strange property of the UNIX $status that it does not map uniformally from
  10493. // the return value of the "exit" command (or "return" statement). So if the exit
  10494. // status from the compilation stage is nonzero then we just make the exit status 1
  10495. // (this does seem to be a portable solution).
  10496. // FYI: only the first 8 bits of the exit value are significant (Solaris uses 'exit_value mod 256').
  10497. if (finalCompiledExitStatus != 0)
  10498. {
  10499. // If this it is non-zero then make it 1 to be more clear to external tools (e.g. make)
  10500. finalCompiledExitStatus = 1;
  10501. }
  10502. // DQ (9/19/2006): We need to invert the test result (return code) for
  10503. // negative tests (where failure is expected and success is an error).
  10504. if (get_negative_test() == true)
  10505. {
  10506. if ( get_verbose() > 1 )
  10507. printf ("This is a negative tests, so an error in compilation is a PASS and successful compilation is a FAIL (vendor compiler return value = %d) \n",returnValueForCompiler);
  10508. // printf (" (before) finalCompiledExitStatus = %d \n",finalCompiledExitStatus);
  10509. finalCompiledExitStatus = (finalCompiledExitStatus == 0) ? /* error */ 1 : /* success */ 0;
  10510. // printf (" (after) finalCompiledExitStatus = %d \n",finalCompiledExitStatus);
  10511. }
  10512. // printf ("Program Terminated Normally (exit status = %d)! \n\n\n\n",finalCompiledExitStatus);
  10513. return finalCompiledExitStatus;
  10514. }
  10515. void
  10516. SgFile::display ( const std::string & label ) const
  10517. {
  10518. // This function prints out the member data values within the object
  10519. printf ("\nIn SgFile::display(%s) \n",label.c_str());
  10520. // DQ (1/17/2006): test this
  10521. // ROSE_ASSERT(get_fileInfo() != NULL);
  10522. printf (" p_root is %s pointer \n",(p_root != NULL) ? "VALID" : "NULL");
  10523. ROSE_ASSERT (p_root != NULL);
  10524. // printf ("Output the SgFile::p_file_info object = %p \n",get_file_info());
  10525. // get_file_info()->display("Called from SgFile::display");
  10526. printf ("Output the SgFile::p_startOfConstruct object = %p \n",get_startOfConstruct());
  10527. ROSE_ASSERT (get_startOfConstruct() != NULL);
  10528. get_startOfConstruct()->display("Called from SgFile::display");
  10529. printf (" p_preprocessorDirectivesAndCommentsList is %s pointer \n",(p_preprocessorDirectivesAndCommentsList != NULL) ? "VALID" : "NULL");
  10530. // ROSE_ASSERT (p_preprocessorDirectivesAndCommentsList != NULL);
  10531. // printf (" p_unparse_output_filename = %s \n",(p_unparse_output_filename != NULL) ? p_unparse_output_filename : "NULL POINTER");
  10532. printf (" p_unparse_output_filename = %s \n",p_unparse_output_filename.c_str());
  10533. printf (" p_verbose = %s (value=%d) \n", (p_verbose > 1) ? "true" : "false",p_verbose);
  10534. printf (" p_useBackendOnly = %s \n",(p_useBackendOnly == true) ? "true" : "false");
  10535. printf (" p_skip_transformation = %s \n",(p_skip_transformation == true) ? "true" : "false");
  10536. printf (" p_skip_unparse = %s \n",(p_skip_unparse == true) ? "true" : "false");
  10537. printf (" p_outputGrammarTreeFiles = %s \n",(p_outputGrammarTreeFiles == true) ? "true" : "false");
  10538. printf (" p_outputGrammarTreeFilesForHeaderFiles = %s \n",(p_outputGrammarTreeFilesForHeaderFiles == true) ? "true" : "false");
  10539. printf (" p_unparse_includes = %s \n",(p_unparse_includes == true) ? "true" : "false");
  10540. printf (" p_KCC_frontend = %s \n",(p_KCC_frontend == true) ? "true" : "false");
  10541. printf (" p_new_frontend = %s \n",(p_new_frontend == true) ? "true" : "false");
  10542. printf (" p_skipfinalCompileStep = %s \n",(p_skipfinalCompileStep == true) ? "true" : "false");
  10543. printf (" p_disable_edg_backend = %s \n",(p_disable_edg_backend == true) ? "true" : "false");
  10544. printf (" p_disable_sage_backend = %s \n",(p_disable_sage_backend == true) ? "true" : "false");
  10545. printf (" p_testingLevel = %d \n",p_testingLevel);
  10546. printf (" p_preinit_il = %s \n",(p_preinit_il == true) ? "true" : "false");
  10547. printf (" p_enable_cp_backend = %s \n",(p_enable_cp_backend == true) ? "true" : "false");
  10548. // printf (" p_numberOfSourceFileNames = %d \n",p_numberOfSourceFileNames);
  10549. printf (" p_C_only() = %s \n",(p_C_only == true) ? "true" : "false");
  10550. printf (" p_C99_only() = %s \n",(p_C99_only == true) ? "true" : "false");
  10551. printf (" p_Fortran_only() = %s \n",(p_Fortran_only == true) ? "true" : "false");
  10552. printf (" p_F77_only() = %s \n",(p_F77_only == true) ? "true" : "false");
  10553. printf (" p_F90_only() = %s \n",(p_F90_only == true) ? "true" : "false");
  10554. printf (" p_F95_only() = %s \n",(p_F95_only == true) ? "true" : "false");
  10555. printf (" p_F2003_only() = %s \n",(p_F2003_only == true) ? "true" : "false");
  10556. #if 0
  10557. for (int i = 0; i < p_numberOfSourceFileNames; i++)
  10558. {
  10559. printf (" p_sourceFileNamesWithPath [%d] = %s \n",
  10560. i,(p_sourceFileNamesWithPath[i] != NULL) ? p_sourceFileNamesWithPath[i] : "NULL STRING");
  10561. printf (" p_sourceFileNamesWithoutPath [%d] = %s \n",
  10562. i,(p_sourceFileNamesWithoutPath[i] != NULL) ? p_sourceFileNamesWithoutPath[i] : "NULL STRING");
  10563. }
  10564. #else
  10565. printf (" p_sourceFileNameWithPath = %s \n",p_sourceFileNameWithPath.c_str());
  10566. printf (" p_sourceFileNameWithoutPath = %s \n",p_sourceFileNameWithoutPath.c_str());
  10567. #endif
  10568. // printf (" p_skip_buildHigherLevelGrammars = %s \n",(p_skip_buildHigherLevelGrammars == true) ? "true" : "false");
  10569. printf (" p_outputGrammarTreeFilesForEDG = %s \n",(p_outputGrammarTreeFilesForEDG == true) ? "true" : "false");
  10570. // DQ (1/17/2006): test this
  10571. // ROSE_ASSERT(get_fileInfo() != NULL);
  10572. // printf ("p_ = %s \n",(p_ == true) ? "true" : "false");
  10573. // printf (" is %s pointer \n",( != NULL) ? "VALID" : "NULL");
  10574. }
  10575. // End of memberFunctionString
  10576. // Start of memberFunctionString
  10577. #line 331 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Common.code"
  10578. // *** COMMON CODE SECTION BEGINS HERE ***
  10579. int
  10580. SgFile::getVariant() const
  10581. {
  10582. // This function is used in ROSE while "variant()" is used in SAGE
  10583. assert(this != NULL);
  10584. return variant();
  10585. }
  10586. // This function is used in ROSE in treeTraversal code
  10587. // eventually replaces getVariant() and variant()
  10588. // though after variant() has been removed for a while we will
  10589. // want to change the name of variantT() back to variant()
  10590. // (since the "T" was ment to stand for temporary).
  10591. // When this happens the variantT() will be depricated.
  10592. VariantT
  10593. SgFile::variantT() const {
  10594. return V_SgFile;
  10595. }
  10596. #if 0
  10597. int
  10598. SgFile::variant() const
  10599. {
  10600. // This function is used in SAGE
  10601. assert(this != NULL);
  10602. return FileTag;
  10603. }
  10604. #endif
  10605. const char*
  10606. SgFile::sage_class_name() const
  10607. {
  10608. assert(this != NULL);
  10609. return "SgFile";
  10610. }
  10611. std::string
  10612. SgFile::class_name() const
  10613. {
  10614. assert(this != NULL);
  10615. return "SgFile";
  10616. }
  10617. // DQ (11/26/2005): Support for visitor pattern mechanims
  10618. // (inferior to ROSE traversal mechanism, experimental).
  10619. void
  10620. SgFile::executeVisitorMemberFunction (ROSE_VisitorPattern & visitor)
  10621. {
  10622. ROSE_ASSERT(this != NULL);
  10623. visitor.visit(this);
  10624. }
  10625. // *** COMMON CODE SECTION ENDS HERE ***
  10626. // End of memberFunctionString
  10627. // Start of memberFunctionString
  10628. #line 1387 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Node.code"
  10629. #if 0
  10630. //! Error checking support
  10631. /*! Verifies the following:
  10632. - working getVariant() member function
  10633. - calls base class's error() member function
  10634. Every class has one of these functions.
  10635. */
  10636. bool
  10637. SgFile::error()
  10638. {
  10639. // Put error checking here
  10640. ROSE_ASSERT (this != NULL);
  10641. if (getVariant() != FileTag)
  10642. {
  10643. printf ("Error in SgFile::error(): SgFile object has a %s variant \n",
  10644. Cxx_GrammarTerminalNames[getVariant()].name);
  10645. // printf ("Error in SgFile::error() \n");
  10646. ROSE_ABORT();
  10647. }
  10648. ROSE_ASSERT (getVariant() == FileTag);
  10649. return SgSupport::error();
  10650. }
  10651. #endif
  10652. // End of memberFunctionString
  10653. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarVariantFunctionDefinitionMacros.macro"
  10654. int
  10655. SgFile::variant() const
  10656. {
  10657. // This function is generated from grammarVariantFunctionDefinitionMacros.macro
  10658. #ifdef DEBUG
  10659. // printf ("In SgFile::variant() const \n");
  10660. #endif
  10661. assert(this != NULL);
  10662. return FileTag;
  10663. }
  10664. #line 1 ""
  10665. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarIsClassNameFunctionDefinitionMacros.macro"
  10666. SgFile* isSgFile ( SgNode* inputDerivedClassPointer )
  10667. {
  10668. return dynamic_cast<SgFile*>(inputDerivedClassPointer);
  10669. }
  10670. // DQ (11/8/2003): Added version of functions taking const pointer
  10671. const SgFile* isSgFile ( const SgNode* inputDerivedClassPointer )
  10672. {
  10673. return dynamic_cast<const SgFile*>(inputDerivedClassPointer);
  10674. }
  10675. #line 1 ""
  10676. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  10677. /**
  10678. \brief Generated destructor
  10679. This destructor is automatically generated (by ROSETTA). This destructor
  10680. only frees memory of data members associated with the parts of the current IR node which
  10681. are NOT traversed. Those data members that are part of a traversal can be freed using
  10682. a traversal (calling this destructor on all children in a post-order traversal). Such
  10683. a traversal which deletes a whole AST is provided by DeleteSgTree(SgNode*).
  10684. \internal All IR nodes with data members specified using setDataPrototype() within ROSETTA
  10685. are specified as NO_DELETE is also specified as DEF_TRAVERSAL. Those marked as
  10686. NO_TRAVERSAL can be marked as NO_DELETE or DEF_DELETE.
  10687. \note All SgSymbol IR nodes are deleted when the symbol table is deleted. Currently most
  10688. SgType IR nodes are not deleted (since they are shared). Also, all STL lists of
  10689. pointers are not yet implemented to call delete on eash pointer in the container.
  10690. (This could be done by derivation from the STL containers to define containers that
  10691. automatically deleted their members.)
  10692. */
  10693. SgFile::~SgFile ()
  10694. {
  10695. #if 0
  10696. // debugging information!
  10697. printf ("In SgFile::~SgFile (destructor) \n");
  10698. #endif
  10699. #if 1
  10700. // DQ (6/25/2006): Commented out destructor body to allow the File I/O to work.
  10701. delete p_startOfConstruct;
  10702. delete p_preprocessorDirectivesAndCommentsList;
  10703. // case: not a listType for startOfConstruct
  10704. p_startOfConstruct = NULL; // non list case
  10705. // case: not a listType for root
  10706. p_root = NULL; // non list case
  10707. // case: not a listType for verbose
  10708. p_verbose = 0; // non list case
  10709. // case: not a listType for C_only
  10710. p_C_only = false; // non list case
  10711. // case: not a listType for C99_only
  10712. p_C99_only = false; // non list case
  10713. // case: not a listType for Fortran_only
  10714. p_Fortran_only = false; // non list case
  10715. // case: not a listType for F77_only
  10716. p_F77_only = false; // non list case
  10717. // case: not a listType for F90_only
  10718. p_F90_only = false; // non list case
  10719. // case: not a listType for F95_only
  10720. p_F95_only = false; // non list case
  10721. // case: not a listType for F2003_only
  10722. p_F2003_only = false; // non list case
  10723. // case: not a listType for fixedFormat
  10724. p_fixedFormat = false; // non list case
  10725. // case: not a listType for freeFormat
  10726. p_freeFormat = false; // non list case
  10727. // case: not a listType for outputFormat
  10728. p_outputFormat = SgFile::e_unknown_output_format; // non list case
  10729. // case: not a listType for fortran_implicit_none
  10730. p_fortran_implicit_none = false; // non list case
  10731. // case: not a listType for fortran_openmp
  10732. p_fortran_openmp = false; // non list case
  10733. // case: not a listType for skip_transformation
  10734. p_skip_transformation = false; // non list case
  10735. // case: not a listType for skip_unparse
  10736. p_skip_unparse = false; // non list case
  10737. // case: not a listType for unparse_includes
  10738. p_unparse_includes = false; // non list case
  10739. // case: not a listType for skipfinalCompileStep
  10740. p_skipfinalCompileStep = false; // non list case
  10741. // case: not a listType for outputLanguage
  10742. p_outputLanguage = SgFile::e_default_output_language; // non list case
  10743. // case: not a listType for sourceFileNameWithPath
  10744. p_sourceFileNameWithPath = ""; // non list case
  10745. // case: not a listType for sourceFileNameWithoutPath
  10746. p_sourceFileNameWithoutPath = ""; // non list case
  10747. // case: not a listType for unparse_output_filename
  10748. p_unparse_output_filename = ""; // non list case
  10749. // case: not a listType for useBackendOnly
  10750. p_useBackendOnly = false; // non list case
  10751. // case: not a listType for compileOnly
  10752. p_compileOnly = false; // non list case
  10753. // case: not a listType for savedFrontendCommandLine
  10754. p_savedFrontendCommandLine = ""; // non list case
  10755. // case: not a listType for no_implicit_templates
  10756. p_no_implicit_templates = false; // non list case
  10757. // case: not a listType for no_implicit_inline_templates
  10758. p_no_implicit_inline_templates = false; // non list case
  10759. // case: not a listType for skip_commentsAndDirectives
  10760. p_skip_commentsAndDirectives = false; // non list case
  10761. // case: not a listType for collectAllCommentsAndDirectives
  10762. p_collectAllCommentsAndDirectives = false; // non list case
  10763. // case: not a listType for preprocessorDirectivesAndCommentsList
  10764. p_preprocessorDirectivesAndCommentsList = NULL; // non list case
  10765. // case: not a listType for attributeMechanism
  10766. p_attributeMechanism = NULL; // non list case
  10767. // case: not a listType for KCC_frontend
  10768. p_KCC_frontend = false; // non list case
  10769. // case: not a listType for new_frontend
  10770. p_new_frontend = false; // non list case
  10771. // case: not a listType for travTraceToDOT
  10772. p_travTraceToDOT = false; // non list case
  10773. // case: not a listType for disable_edg_backend
  10774. p_disable_edg_backend = false; // non list case
  10775. // case: not a listType for disable_sage_backend
  10776. p_disable_sage_backend = false; // non list case
  10777. // case: not a listType for testingLevel
  10778. p_testingLevel = -1; // non list case
  10779. // case: not a listType for preinit_il
  10780. p_preinit_il = false; // non list case
  10781. // case: not a listType for enable_cp_backend
  10782. p_enable_cp_backend = false; // non list case
  10783. // case: not a listType for outputGrammarTreeFiles
  10784. p_outputGrammarTreeFiles = false; // non list case
  10785. // case: not a listType for outputGrammarTreeFilesForHeaderFiles
  10786. p_outputGrammarTreeFilesForHeaderFiles = false; // non list case
  10787. // case: not a listType for outputGrammarTreeFilesForEDG
  10788. p_outputGrammarTreeFilesForEDG = false; // non list case
  10789. // case: not a listType for markGeneratedFiles
  10790. p_markGeneratedFiles = false; // non list case
  10791. // case: not a listType for negative_test
  10792. p_negative_test = false; // non list case
  10793. // case: not a listType for strict_language_handling
  10794. p_strict_language_handling = false; // non list case
  10795. // case: not a listType for embedColorCodesInGeneratedCode
  10796. p_embedColorCodesInGeneratedCode = 0; // non list case
  10797. // case: not a listType for generateSourcePositionCodes
  10798. p_generateSourcePositionCodes = 0; // non list case
  10799. // case: not a listType for sourceFileUsesCppFileExtension
  10800. p_sourceFileUsesCppFileExtension = false; // non list case
  10801. // case: not a listType for sourceFileUsesFortranFileExtension
  10802. p_sourceFileUsesFortranFileExtension = false; // non list case
  10803. // case: not a listType for sourceFileUsesFortran77FileExtension
  10804. p_sourceFileUsesFortran77FileExtension = false; // non list case
  10805. // case: not a listType for sourceFileUsesFortran90FileExtension
  10806. p_sourceFileUsesFortran90FileExtension = false; // non list case
  10807. // case: not a listType for sourceFileUsesFortran95FileExtension
  10808. p_sourceFileUsesFortran95FileExtension = false; // non list case
  10809. // case: not a listType for sourceFileUsesFortran2003FileExtension
  10810. p_sourceFileUsesFortran2003FileExtension = false; // non list case
  10811. // case: not a listType for binaryFile
  10812. p_binaryFile = NULL; // non list case
  10813. #line 32 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarDestructorDefinitionMacros.macro"
  10814. #endif
  10815. }
  10816. #line 1 ""
  10817. #line 1 ""
  10818. #line 6 "../Grammar/grammarClassDefinitionMacros.macro after marker MEMBER_FUNCTION_DEFINITIONS"
  10819. #line 7 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  10820. // ********************************************************
  10821. // member functions common across all array grammar objects
  10822. // ********************************************************
  10823. #line 1 ""
  10824. #line 1 ""
  10825. #line 1 ""
  10826. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/grammarClassDefinitionMacros.macro"
  10827. // ********************************************************
  10828. // member functions specific to each node in the grammar
  10829. // ********************************************************
  10830. #line 6 "../Grammar/grammarClassDefinitionMacros.macro before marker MEMBER_FUNCTION_DEFINITIONS"
  10831. #line 1 ""
  10832. #line 1 ""
  10833. // Start of memberFunctionString
  10834. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  10835. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  10836. SgFilePtrListPtr
  10837. SgProject::get_fileList () const
  10838. {
  10839. assert (this != NULL);
  10840. return p_fileList;
  10841. }
  10842. void
  10843. SgProject::set_fileList ( SgFilePtrListPtr fileList )
  10844. {
  10845. assert (this != NULL);
  10846. set_isModified(true);
  10847. p_fileList = fileList;
  10848. }
  10849. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  10850. // End of memberFunctionString
  10851. // Start of memberFunctionString
  10852. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  10853. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  10854. SgStringList
  10855. SgProject::get_originalCommandLineArgumentList () const
  10856. {
  10857. assert (this != NULL);
  10858. return p_originalCommandLineArgumentList;
  10859. }
  10860. void
  10861. SgProject::set_originalCommandLineArgumentList ( SgStringList originalCommandLineArgumentList )
  10862. {
  10863. assert (this != NULL);
  10864. set_isModified(true);
  10865. p_originalCommandLineArgumentList = originalCommandLineArgumentList;
  10866. }
  10867. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  10868. // End of memberFunctionString
  10869. // Start of memberFunctionString
  10870. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  10871. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  10872. int
  10873. SgProject::get_frontendErrorCode () const
  10874. {
  10875. assert (this != NULL);
  10876. return p_frontendErrorCode;
  10877. }
  10878. void
  10879. SgProject::set_frontendErrorCode ( int frontendErrorCode )
  10880. {
  10881. assert (this != NULL);
  10882. set_isModified(true);
  10883. p_frontendErrorCode = frontendErrorCode;
  10884. }
  10885. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  10886. // End of memberFunctionString
  10887. // Start of memberFunctionString
  10888. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  10889. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  10890. int
  10891. SgProject::get_backendErrorCode () const
  10892. {
  10893. assert (this != NULL);
  10894. return p_backendErrorCode;
  10895. }
  10896. void
  10897. SgProject::set_backendErrorCode ( int backendErrorCode )
  10898. {
  10899. assert (this != NULL);
  10900. set_isModified(true);
  10901. p_backendErrorCode = backendErrorCode;
  10902. }
  10903. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  10904. // End of memberFunctionString
  10905. // Start of memberFunctionString
  10906. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  10907. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  10908. std::string
  10909. SgProject::get_outputFileName () const
  10910. {
  10911. assert (this != NULL);
  10912. return p_outputFileName;
  10913. }
  10914. void
  10915. SgProject::set_outputFileName ( std::string outputFileName )
  10916. {
  10917. assert (this != NULL);
  10918. set_isModified(true);
  10919. p_outputFileName = outputFileName;
  10920. }
  10921. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  10922. // End of memberFunctionString
  10923. // Start of memberFunctionString
  10924. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  10925. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  10926. SgStringList
  10927. SgProject::get_sourceFileNameList () const
  10928. {
  10929. assert (this != NULL);
  10930. return p_sourceFileNameList;
  10931. }
  10932. void
  10933. SgProject::set_sourceFileNameList ( SgStringList sourceFileNameList )
  10934. {
  10935. assert (this != NULL);
  10936. set_isModified(true);
  10937. p_sourceFileNameList = sourceFileNameList;
  10938. }
  10939. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  10940. // End of memberFunctionString
  10941. // Start of memberFunctionString
  10942. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  10943. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  10944. SgStringList
  10945. SgProject::get_objectFileNameList () const
  10946. {
  10947. assert (this != NULL);
  10948. return p_objectFileNameList;
  10949. }
  10950. void
  10951. SgProject::set_objectFileNameList ( SgStringList objectFileNameList )
  10952. {
  10953. assert (this != NULL);
  10954. set_isModified(true);
  10955. p_objectFileNameList = objectFileNameList;
  10956. }
  10957. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  10958. // End of memberFunctionString
  10959. // Start of memberFunctionString
  10960. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  10961. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  10962. SgStringList
  10963. SgProject::get_libraryFileList () const
  10964. {
  10965. assert (this != NULL);
  10966. return p_libraryFileList;
  10967. }
  10968. void
  10969. SgProject::set_libraryFileList ( SgStringList libraryFileList )
  10970. {
  10971. assert (this != NULL);
  10972. set_isModified(true);
  10973. p_libraryFileList = libraryFileList;
  10974. }
  10975. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  10976. // End of memberFunctionString
  10977. // Start of memberFunctionString
  10978. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  10979. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  10980. SgStringList
  10981. SgProject::get_librarySpecifierList () const
  10982. {
  10983. assert (this != NULL);
  10984. return p_librarySpecifierList;
  10985. }
  10986. void
  10987. SgProject::set_librarySpecifierList ( SgStringList librarySpecifierList )
  10988. {
  10989. assert (this != NULL);
  10990. set_isModified(true);
  10991. p_librarySpecifierList = librarySpecifierList;
  10992. }
  10993. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  10994. // End of memberFunctionString
  10995. // Start of memberFunctionString
  10996. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  10997. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  10998. SgStringList
  10999. SgProject::get_libraryDirectorySpecifierList () const
  11000. {
  11001. assert (this != NULL);
  11002. return p_libraryDirectorySpecifierList;
  11003. }
  11004. void
  11005. SgProject::set_libraryDirectorySpecifierList ( SgStringList libraryDirectorySpecifierList )
  11006. {
  11007. assert (this != NULL);
  11008. set_isModified(true);
  11009. p_libraryDirectorySpecifierList = libraryDirectorySpecifierList;
  11010. }
  11011. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  11012. // End of memberFunctionString
  11013. // Start of memberFunctionString
  11014. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  11015. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  11016. SgStringList
  11017. SgProject::get_includeDirectorySpecifierList () const
  11018. {
  11019. assert (this != NULL);
  11020. return p_includeDirectorySpecifierList;
  11021. }
  11022. void
  11023. SgProject::set_includeDirectorySpecifierList ( SgStringList includeDirectorySpecifierList )
  11024. {
  11025. assert (this != NULL);
  11026. set_isModified(true);
  11027. p_includeDirectorySpecifierList = includeDirectorySpecifierList;
  11028. }
  11029. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  11030. // End of memberFunctionString
  11031. // Start of memberFunctionString
  11032. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  11033. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  11034. bool
  11035. SgProject::get_compileOnly () const
  11036. {
  11037. assert (this != NULL);
  11038. return p_compileOnly;
  11039. }
  11040. void
  11041. SgProject::set_compileOnly ( bool compileOnly )
  11042. {
  11043. assert (this != NULL);
  11044. set_isModified(true);
  11045. p_compileOnly = compileOnly;
  11046. }
  11047. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  11048. // End of memberFunctionString
  11049. // Start of memberFunctionString
  11050. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  11051. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  11052. bool
  11053. SgProject::get_prelink () const
  11054. {
  11055. assert (this != NULL);
  11056. return p_prelink;
  11057. }
  11058. void
  11059. SgProject::set_prelink ( bool prelink )
  11060. {
  11061. assert (this != NULL);
  11062. set_isModified(true);
  11063. p_prelink = prelink;
  11064. }
  11065. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  11066. // End of memberFunctionString
  11067. // Start of memberFunctionString
  11068. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  11069. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  11070. SgProject::template_instantiation_enum
  11071. SgProject::get_template_instantiation_mode () const
  11072. {
  11073. assert (this != NULL);
  11074. return p_template_instantiation_mode;
  11075. }
  11076. void
  11077. SgProject::set_template_instantiation_mode ( SgProject::template_instantiation_enum template_instantiation_mode )
  11078. {
  11079. assert (this != NULL);
  11080. set_isModified(true);
  11081. p_template_instantiation_mode = template_instantiation_mode;
  11082. }
  11083. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  11084. // End of memberFunctionString
  11085. // Start of memberFunctionString
  11086. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  11087. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  11088. bool
  11089. SgProject::get_astMerge () const
  11090. {
  11091. assert (this != NULL);
  11092. return p_astMerge;
  11093. }
  11094. void
  11095. SgProject::set_astMerge ( bool astMerge )
  11096. {
  11097. assert (this != NULL);
  11098. set_isModified(true);
  11099. p_astMerge = astMerge;
  11100. }
  11101. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  11102. // End of memberFunctionString
  11103. // Start of memberFunctionString
  11104. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  11105. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  11106. std::string
  11107. SgProject::get_astMergeCommandFile () const
  11108. {
  11109. assert (this != NULL);
  11110. return p_astMergeCommandFile;
  11111. }
  11112. void
  11113. SgProject::set_astMergeCommandFile ( std::string astMergeCommandFile )
  11114. {
  11115. assert (this != NULL);
  11116. set_isModified(true);
  11117. p_astMergeCommandFile = astMergeCommandFile;
  11118. }
  11119. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  11120. // End of memberFunctionString
  11121. // Start of memberFunctionString
  11122. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  11123. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  11124. bool
  11125. SgProject::get_C_PreprocessorOnly () const
  11126. {
  11127. assert (this != NULL);
  11128. return p_C_PreprocessorOnly;
  11129. }
  11130. void
  11131. SgProject::set_C_PreprocessorOnly ( bool C_PreprocessorOnly )
  11132. {
  11133. assert (this != NULL);
  11134. set_isModified(true);
  11135. p_C_PreprocessorOnly = C_PreprocessorOnly;
  11136. }
  11137. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  11138. // End of memberFunctionString
  11139. // Start of memberFunctionString
  11140. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  11141. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  11142. AstAttributeMechanism*
  11143. SgProject::get_attributeMechanism () const
  11144. {
  11145. assert (this != NULL);
  11146. return p_attributeMechanism;
  11147. }
  11148. void
  11149. SgProject::set_attributeMechanism ( AstAttributeMechanism* attributeMechanism )
  11150. {
  11151. assert (this != NULL);
  11152. set_isModified(true);
  11153. #if DEBUG_SAGE_ACCESS_FUNCTIONS
  11154. if (p_attributeMechanism != NULL && attributeMechanism != NULL && p_attributeMechanism != attributeMechanism)
  11155. {
  11156. printf ("Warning: attributeMechanism = %p overwriting valid pointer p_attributeMechanism = %p \n",attributeMechanism,p_attributeMechanism);
  11157. #if DEBUG_SAGE_ACCESS_FUNCTIONS_ASSERTION
  11158. printf ("Error fails assertion (p_attributeMechanism != NULL && attributeMechanism != NULL && p_attributeMechanism != attributeMechanism) is false\n");
  11159. ROSE_ASSERT(false);
  11160. #endif
  11161. }
  11162. #endif
  11163. p_attributeMechanism = attributeMechanism;
  11164. }
  11165. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  11166. // End of memberFunctionString
  11167. // Start of memberFunctionString
  11168. #line 836 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Support.code"
  11169. #if 0
  11170. // DQ (4/10/2006): Removed in favor of implementation at SgNode using
  11171. // a pointer and the interface represented directly at the SgNode
  11172. AstAttributeMechanism &
  11173. SgProject::attribute()
  11174. {
  11175. // DQ (1/2/2006): This function preserves as much of
  11176. // the syntax of attribute being a public data member.
  11177. if (p_attribute == NULL)
  11178. {
  11179. printf ("Error: p_attribute == NULL (node = %s) \n",class_name().c_str());
  11180. ROSE_ASSERT(false);
  11181. }
  11182. return *p_attribute;
  11183. }
  11184. #endif
  11185. void
  11186. SgProject::addNewAttribute( std::string s, AstAttribute* a )
  11187. {
  11188. if (get_attributeMechanism() == NULL)
  11189. {
  11190. set_attributeMechanism( new AstAttributeMechanism() );
  11191. ROSE_ASSERT(get_attributeMechanism() != NULL);
  11192. }
  11193. get_attributeMechanism()->add(s,a);
  11194. }
  11195. void
  11196. SgProject::setAttribute( std::string s, AstAttribute* a )
  11197. {
  11198. if (get_attributeMechanism() == NULL)
  11199. {
  11200. set_attributeMechanism( new AstAttributeMechanism() );
  11201. ROSE_ASSERT(get_attributeMechanism() != NULL);
  11202. }
  11203. get_attributeMechanism()->set(s,a);
  11204. }
  11205. AstAttribute*
  11206. SgProject::getAttribute(std::string s) const
  11207. {
  11208. ROSE_ASSERT(get_attributeMechanism() != NULL);
  11209. AstAttribute* returnValue = get_attributeMechanism()->operator[](s);
  11210. ROSE_ASSERT(returnValue != NULL);
  11211. return returnValue;
  11212. }
  11213. void
  11214. SgProject::updateAttribute( std::string s, AstAttribute* a )
  11215. {
  11216. // formerly called: replace
  11217. ROSE_ASSERT(get_attributeMechanism() != NULL);
  11218. get_attributeMechanism()->replace(s,a);
  11219. }
  11220. void
  11221. SgProject::removeAttribute(std::string s)
  11222. {
  11223. ROSE_ASSERT(get_attributeMechanism() != NULL);
  11224. get_attributeMechanism()->remove(s);
  11225. // DQ (1/2/2006): If we have no more attributes then remove the attribute container
  11226. int remainingCount = numberOfAttributes();
  11227. // printf ("In AstTextAttributesHandling::visit(): remaining number of attributes = %d \n",remainingCount);
  11228. if (remainingCount == 0)
  11229. {
  11230. delete get_attributeMechanism();
  11231. set_attributeMechanism(NULL);
  11232. }
  11233. }
  11234. bool
  11235. SgProject::attributeExists(std::string s) const
  11236. {
  11237. bool returnValue = false;
  11238. if (get_attributeMechanism() != NULL)
  11239. returnValue = get_attributeMechanism()->exists(s);
  11240. return returnValue;
  11241. }
  11242. int
  11243. SgProject::numberOfAttributes() const
  11244. {
  11245. int returnValue = 0;
  11246. if (get_attributeMechanism() != NULL)
  11247. returnValue = get_attributeMechanism()->size();
  11248. return returnValue;
  11249. }
  11250. // End of memberFunctionString
  11251. // Start of memberFunctionString
  11252. #line 1 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/dataMemberAccessFunctions.macro"
  11253. // *** DATA ACCESS FUNCTION SECTION BEGINS HERE ***
  11254. std::string
  11255. SgProject::get_compilationPerformanceFile () const
  11256. {
  11257. assert (this != NULL);
  11258. return p_compilationPerformanceFile;
  11259. }
  11260. void
  11261. SgProject::set_compilationPerformanceFile ( std::string compilationPerformanceFile )
  11262. {
  11263. assert (this != NULL);
  11264. set_isModified(true);
  11265. p_compilationPerformanceFile = compilationPerformanceFile;
  11266. }
  11267. // *** DATA ACCESS FUNCTION SECTION ENDS HERE ***
  11268. // End of memberFunctionString
  11269. // Start of memberFunctionString
  11270. #line 12529 "/home/dquinlan/ROSE/NEW_ROSE/src/ROSETTA/Grammar/Support.code"
  11271. //! Declaration of space for static variables
  11272. //static int SgProject::p_defaultNumberOfCommandLineArguments = 0;
  11273. //static char** SgProject::p_defaultCommandLineArgumentList = NULL;
  11274. //! (static data) global concept of verbose level which controls useful output from the compiler
  11275. int SgProject::p_verbose = 0;
  11276. //! this can constructor can be used but parse(int argc, char** argv) needs to be called
  11277. SgProject::SgProject()
  11278. {
  11279. initialization();
  11280. }
  11281. SgProject::SgProject( const SgProject & project )
  11282. {
  11283. // This copy constructor is not supported, it is implemented with to return an error message!
  11284. initialization();
  11285. // What is the point of this code!
  11286. // p_numberOfCommandLineArguments(project.p_numberOfCommandLineArguments),
  11287. // p_commandLineArgumentList(project.p_commandLineArgumentList),
  11288. // p_defaultNumberOfCommandLineArguments(project.p_defaultNumberOfCommandLineArguments),
  11289. // p_defaultCommandLineArgumentList(project.p_defaultCommandLineArgumentList),
  11290. // Build the empty STL lists
  11291. p_fileList = new SgFilePtrList();
  11292. ROSE_ASSERT (p_fileList != NULL);
  11293. // print error message and quit
  11294. printf ("ERROR: this SgProject copy constructor is not supposed to be used \n");
  11295. printf (" use SgProject ( int & argc, char** & argv , int & errorCode ) OR copy member function instead \n");
  11296. ROSE_ABORT();
  11297. }
  11298. //! constructor invokes EDG front end and creates AST. Use frontend() instead.
  11299. SgProject::SgProject ( int argc, char** argv)
  11300. {
  11301. initialization();
  11302. std::vector<std::string> argvList(argv, argv + argc);
  11303. int errorCode = parse(argvList);
  11304. set_frontendErrorCode(errorCode);
  11305. }
  11306. //! constructor invokes EDG front end and creates AST. Use frontend() instead.
  11307. SgProject::SgProject ( const std::vector<std::string>& argv )
  11308. {
  11309. initialization();
  11310. int errorCode = parse(argv);
  11311. set_frontendErrorCode(errorCode);
  11312. }
  11313. #if 0
  11314. // DQ (10/16/2005): Depreicated a long time ago, removed it now!
  11315. //! Deprecated, do not use.
  11316. SgProject::SgProject ( int& argc, char** argv, int& refErrorCode)
  11317. {
  11318. printf ("This SgProject constructor is deprecated, do not use. \n");
  11319. initialization();
  11320. int errorCode;
  11321. errorCode = parse(argc,argv);
  11322. set_frontendErrorCode(errorCode);
  11323. refErrorCode = errorCode;
  11324. }
  11325. #endif
  11326. void
  11327. SgProject::initialization()
  11328. {
  11329. // DQ (10/16/2005): This function initializes default values (until we use an automatically generated version)
  11330. p_fileList = NULL;
  11331. // p_numberOfCommandLineArguments = 0;
  11332. // p_commandLineArgumentList = NULL;
  11333. // p_defaultNumberOfCommandLineArguments = 0;
  11334. // p_defaultCommandLineArgumentList = NULL;
  11335. p_frontendErrorCode = 0;
  11336. p_backendErrorCode = 0;
  11337. p_outputFileName = "";
  11338. p_compileOnly = false;
  11339. p_prelink = false;
  11340. p_template_instantiation_mode = e_unknown;
  11341. p_astMerge = false;
  11342. p_astMergeCommandFile = "";
  11343. p_compilationPerformanceFile = "";
  11344. p_C_PreprocessorOnly = false;
  11345. // DQ (5/2/2006): Added initialization to prevent valgrind warning.
  11346. p_attributeMechanism = NULL;
  11347. }
  11348. // DQ (2/1/2007): Added new operator so that w could depricate the inconsistant usage of
  11349. // SgFile& in get_file() member function. The get_file() member function is now depricated.
  11350. SgFile*
  11351. SgProject::operator[]( unsigned int i )
  11352. {
  11353. ROSE_ASSERT(i < get_fileList()->size());
  11354. // Since we use an STL vector internally we can use the vector::operator[] directly.
  11355. return p_fileList->operator[](i);
  11356. }
  11357. //! internal function to invoke the EDG frontend and generate the AST
  11358. int
  11359. SgProject::parse(const vector<string>& argv)
  11360. {
  11361. // Not sure that if we are just linking that we should call a function called "parse()"!!!
  11362. // DQ (7/6/2005): Introduce tracking of performance of ROSE.
  11363. TimingPerformance timer ("AST (SgProject::parse(argc,argv)):");
  11364. // builds file list (or none if this is a link line)
  11365. processCommandLine(argv);
  11366. #if 0
  11367. std::string outputFileName = get_outputFileName();
  11368. int outputFilenameLength = outputFileName.length();
  11369. if (outputFilenameLength <= 2)
  11370. {
  11371. printf ("Warning in SgProject::parse(): abnormally short output filename = %s \n",outputFileName.c_str());
  11372. }
  11373. ROSE_ASSERT (outputFilenameLength > 2);
  11374. // DQ (9/30/2006): This is a better way to get the suffix, but I don't think we really need this code here!
  11375. // std::string suffix = outputFileName.substr(outputFilenameLength-2,2);
  11376. std::string suffix;
  11377. size_t suffix_separator_location = filename.rfind('.');
  11378. if (suffix_separator_location == string::npos)
  11379. {
  11380. printf ("In SgProject::parse(): No suffix identified \n");
  11381. }
  11382. else
  11383. {
  11384. suffix = filename.substr(suffix_separator_location);
  11385. printf ("In SgProject::parse(): Suffix = %s \n",suffix.c_str());
  11386. }
  11387. #endif
  11388. int errorCode = 0;
  11389. // DQ (7/7/2005): Added support for AST Merge Mechanism
  11390. if (p_astMerge == true)
  11391. {
  11392. // If astMerge is specified, then the command file is accessed to execute all
  11393. // the commands from each of the associated working directories. Each new AST
  11394. // in merged with the previous AST.
  11395. if (p_astMergeCommandFile != "")
  11396. {
  11397. // If using astMerge mechanism we have to save the command line and
  11398. // working directories to a separate file. This permits a makefile to
  11399. // call a ROSE translator repeatedly and the command line for each
  11400. // file be saved.
  11401. errorCode = AstMergeSupport(this);
  11402. }
  11403. else
  11404. {
  11405. // DQ (5/26/2007): This case could make sense, if there were more than
  11406. // one file on the command line (or if we wanted to force a single file
  11407. // to share as much as possible in a merge with itself, there is a
  11408. // typical 20% reduction in memory useage for this case since the
  11409. // types are then better shared than is possible during initial construction
  11410. // of the AST).
  11411. #if 0
  11412. // error case
  11413. printf ("astMerge requires specification of a command file \n");
  11414. ROSE_ASSERT(false);
  11415. errorCode = -1;
  11416. #endif
  11417. errorCode = AstMergeSupport(this);
  11418. }
  11419. }
  11420. else
  11421. {
  11422. // DQ (7/7/2005): Specification of the AST merge command filename triggers accumulation
  11423. // of working directories and commandlines into the specified file (no other processing
  11424. // is done, the AST (beyond the SgProject) is not built).
  11425. if (p_astMergeCommandFile != "")
  11426. {
  11427. // If using astMerge mechanism we have to save the command line and
  11428. // working directories to a separate file.
  11429. // DQ (5/26/2007): This might be a problem where object files are required to be built
  11430. // and so we might have to call the backend compiler as a way of forcing the correct
  11431. // object files to be built so that, for example, libraries can be constructed when
  11432. // operating across multiple directories.
  11433. errorCode = buildAstMergeCommandFile(this);
  11434. }
  11435. else
  11436. {
  11437. // Normal case without AST Merge: Compiling ...
  11438. if (get_sourceFileNameList().size() > 0)
  11439. {
  11440. // This is a compile line
  11441. // printf ("Compiling project: outputFileName = %s \n",outputFileName.c_str());
  11442. errorCode = parse();
  11443. }
  11444. // DQ (5/26/2007): This is meaningless, so remove it!
  11445. // errorCode = errorCode;
  11446. }
  11447. }
  11448. return errorCode;
  11449. }
  11450. void
  11451. SgProject::processCommandLine(const vector<string>& input_argv)
  11452. {
  11453. // This functions only copies the command line and extracts information from the
  11454. // command line which is useful at the SgProject level (other information useful
  11455. // at the SgFile level is not extracted).
  11456. // Specifically:
  11457. // 1) --help is processed (along with -help, to be friendly)
  11458. // 2) -o <filename> is processed (since both the compilation and the linking
  11459. // phases must know the output file name and it makes sense to process that once).
  11460. // 3) Lists of files and libraries are processed (sense they too are required in
  11461. // both comilation and linking). (e.g. -l<libname>, -L <directory>, <libname>.a,
  11462. // <filename>.C, <filename>.c, -I<directory name>, <filename>.h
  11463. // NOTE: there is no side-effect to argc and argv. Thus the original ROSE translator can
  11464. // see all options. Any ROSE or EDG specific options can be striped by calling the
  11465. // appropriate functions to strip them out.
  11466. // This function now makes an internal copy of the command line parameters to
  11467. // allow the originals to remain unmodified (SLA modifies the command line).
  11468. // printf ("Inside of SgProject::processCommandLine() \n");
  11469. // local copies of argc and argv variables
  11470. // The purpose of building local copies is to avoid
  11471. // the modification of the command line by SLA (to save the original command line)
  11472. vector<string> local_commandLineArgumentList = input_argv;
  11473. // Save a deep copy fo the original command line input the the translator
  11474. // pass in out copies of the argc and argv to make clear that we don't modify argc and argv
  11475. set_originalCommandLineArgumentList( local_commandLineArgumentList );
  11476. // printf ("DONE with copy of command line in SgProject constructor! \n");
  11477. // Build the empty STL lists
  11478. p_fileList = new SgFilePtrList();
  11479. ROSE_ASSERT (p_fileList != NULL);
  11480. // return value for calls to SLA
  11481. int optionCount = 0;
  11482. //
  11483. // help option (allows alternative -h or -help instead of just -rose:help)
  11484. //
  11485. // Use 1 at end of argument list to SLA to force removal of option from argv and decrement of agrc
  11486. // optionCount = sla(&argc, argv, "-", "($)", "(h|help)",1);
  11487. optionCount = sla_none(local_commandLineArgumentList, "-", "($)", "(h|help)",1);
  11488. if( optionCount > 0 )
  11489. {
  11490. // printf ("option -help found \n");
  11491. printf ("\nROSE (pre-release alpha version: %s) \n",VERSION);
  11492. // ROSE::usage(0);
  11493. SgFile::usage(0);
  11494. exit(0);
  11495. }
  11496. // printf ("After SgProject processing -help option argc = %d \n",argc);
  11497. //
  11498. // help option (allows alternative --h or --help)
  11499. //
  11500. // Use 1 at end of argument list to SLA to force removal of option from argv and decrement of agrc
  11501. // optionCount = sla(&argc, argv, "--", "($)", "(h|help)",1);
  11502. optionCount = sla_none(local_commandLineArgumentList, "--", "($)", "(h|help)",1);
  11503. if( optionCount > 0 )
  11504. {
  11505. // printf ("option --help found \n");
  11506. printf ("\nROSE (pre-release alpha version: %s) \n",VERSION);
  11507. // ROSE::usage(0);
  11508. SgFile::usage(0);
  11509. exit(0);
  11510. }
  11511. //
  11512. // version option (allows alternative --version or --V)
  11513. //
  11514. // Use 1 at end of argument list to SLA to force removal of option from argv and decrement of agrc
  11515. // optionCount = sla(&argc, argv, "--", "($)", "(V|version)",1);
  11516. optionCount = sla_none(local_commandLineArgumentList, "--", "($)", "(V|version)",1);
  11517. if ( optionCount > 0 )
  11518. {
  11519. // printf ("SgProject::processCommandLine(): option --version found \n");
  11520. printf ("\nROSE (pre-release alpha version: %s) \n",VERSION);
  11521. exit(0);
  11522. }
  11523. // Use 1 at end of argument list to SLA to force removal of option from argv and decrement of agrc
  11524. // optionCount = sla(&argc, argv, "--", "($)", "(V|version)",1);
  11525. optionCount = sla_none(local_commandLineArgumentList, "-rose:", "($)", "(V|version)",1);
  11526. if ( optionCount > 0 )
  11527. {
  11528. // printf ("SgProject::processCommandLine(): option --version found \n");
  11529. printf ("\nROSE (pre-release alpha version: %s) \n",VERSION);
  11530. exit(0);
  11531. }
  11532. #if 0
  11533. // DQ (8/6/2006): Not sure that I want this here!
  11534. //
  11535. // version option (using -rose:version)
  11536. //
  11537. if ( CommandlineProcessing::isOption(argc,argv,"-rose:","(V|version)",true) == true )
  11538. {
  11539. // function in SAGE III to access version number of EDG
  11540. extern std::string edgVersionString();
  11541. printf ("\nROSE (pre-release alpha version: %s) \n",VERSION);
  11542. printf (" Using C++ and C frontend from EDG (version %s) internally \n",edgVersionString().c_str());