Created
February 8, 2011 07:50
-
-
Save vazexqi/816056 to your computer and use it in GitHub Desktop.
Example illustrating assertion failed: (fileNameCounter == 1), function buildCommandLineToSubstituteTransformationFile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
daigo:ROSE_Experiments vazexqi$ build/Rewrite_ROSE.out examples/simple.cpp | |
"/usr/include/sys/cdefs.h", line 140: warning: incompatible redefinition of | |
macro "__dead2" (declared at line 148 of | |
"/usr/local/rose/include/g++_HEADERS/rose_edg_required_macros_and_fun | |
ctions.h") | |
#define __dead2 __attribute__((__noreturn__)) | |
^ | |
"/usr/include/sys/cdefs.h", line 141: warning: incompatible redefinition of | |
macro "__pure2" (declared at line 149 of | |
"/usr/local/rose/include/g++_HEADERS/rose_edg_required_macros_and_fun | |
ctions.h") | |
#define __pure2 __attribute__((__const__)) | |
^ | |
"/Users/vazexqi/Development/ROSE/rose_eclipse/ROSE_Experiments/examples/simple.cpp", line 6: warning: | |
variable "x" was declared but never referenced | |
int x; | |
^ | |
Calling transformation | |
Project = /* TOP:/Users/vazexqi/Development/ROSE/rose_eclipse/ROSE_Experiments/examples/simple.cpp */ | |
int main(){for(int i = 0;i < 1;i++) {int x;}return 0;} | |
/* BOTTOM:/Users/vazexqi/Development/ROSE/rose_eclipse/ROSE_Experiments/examples/simple.cpp */ | |
inheritedAttribute.newCodeString = -->int y_$SCOPE_NAME_$POSITION_IN_SCOPE_NAME_$NEW_SCOPE_TEST;<-- | |
In testPermutation(): scope = SurroundingScope location = BeforeCurrentPosition buildInNewScope = true | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgFunctionParameterList) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgIntVal) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgAssignInitializer) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgInitializedName) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgVariableDeclaration) | |
Found a declaration: currentDeclarationStatement = int i = 0; | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgForInitStatement) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgVarRefExp) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgIntVal) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgLessThanOp) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgExprStatement) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgVarRefExp) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgPlusPlusOp) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgInitializedName) | |
In MyTraversal::evaluateRewriteSynthesizedAttribute (SgVariableDeclaration) | |
Found a declaration: currentDeclarationStatement = int x; | |
Matching current statement = 0x1284d9ec0 = int x; (parent = 0x12863b220) | |
Found a matching target statement (insert newSourceString = int y_SurroundingScope_BeforeCurrentPosition_BuildInNewScope_true;) | |
In AbstractInterfaceNodeCollection<T>::display(display called after addTransformationString() | |
): | |
Collection of Input Transformation Strings: | |
Input Transformation String Collection: | |
string (0) = | |
int y_SurroundingScope_BeforeCurrentPosition_BuildInNewScope_true; | |
Collection of Sorted Transformation Strings: | |
String Collection (unknownPositionInScope): | |
String Collection (GlobalScopePreamble): | |
String Collection (GlobalScopeTopOfScope): | |
String Collection (GlobalScopeTopOfIncludeRegion): | |
String Collection (GlobalScopeBottomOfIncludeRegion): | |
String Collection (GlobalScopeBeforeCurrentPosition): | |
String Collection (GlobalScopeReplaceCurrentPosition): | |
String Collection (FunctionScopePreamble): | |
String Collection (FunctionScopeTopOfScope): | |
String Collection (FunctionScopeBeforeCurrentPosition): | |
String Collection (FunctionScopeReplaceCurrentPosition): | |
String Collection (FunctionScopeAfterCurrentPosition): | |
String Collection (FunctionScopeBottomOfScope): | |
String Collection (GlobalScopeAfterCurrentPosition): | |
String Collection (GlobalScopeBottomOfScope): | |
Collection of AST Nodes (converted from strings): | |
Node Collection statements (unknownPositionInScope): | |
Node Collection statements (GlobalScopePreamble): | |
Node Collection statements (GlobalScopeTopOfScope): | |
Node Collection statements (GlobalScopeTopOfIncludeRegion): | |
Node Collection statements (GlobalScopeBottomOfIncludeRegion): | |
Node Collection statements (GlobalScopeBeforeCurrentPosition): | |
Node Collection statements (GlobalScopeReplaceCurrentPosition): | |
Node Collection statements (FunctionScopePreamble): | |
Node Collection statements (FunctionScopeTopOfScope): | |
Node Collection statements (FunctionScopeBeforeCurrentPosition): | |
Node Collection statements (FunctionScopeReplaceCurrentPosition): | |
Node Collection statements (FunctionScopeAfterCurrentPosition): | |
Node Collection statements (FunctionScopeBottomOfScope): | |
Node Collection statements (GlobalScopeAfterCurrentPosition): | |
Node Collection statements (GlobalScopeBottomOfScope): | |
In DeclarationOrCommentListElement::generateString(): | |
openingIfCounter = 0 | |
closingEndifCounter = 0 | |
generateIncludeDirectives = true | |
skipTrailingDirectives = true | |
unparseAsDeclaration = false | |
prefixStatement = SgFunctionDeclaration | |
After prefix statement processing: returnString = int main() | |
declarationCounter = 0 declarationString = #include <stdio.h> | |
int main() | |
In DeclarationOrCommentListElement::generateString(): | |
openingIfCounter = 0 | |
closingEndifCounter = 0 | |
generateIncludeDirectives = true | |
skipTrailingDirectives = true | |
unparseAsDeclaration = false | |
prefixStatement = SgForStatement | |
After prefix statement processing: returnString = for (int i = 0; i < 1; i++) | |
declarationCounter = 0 declarationString = for (int i = 0; i < 1; i++) | |
In DeclarationOrCommentListElement::generateString(): | |
openingIfCounter = 0 | |
closingEndifCounter = 0 | |
generateIncludeDirectives = true | |
skipTrailingDirectives = false | |
unparseAsDeclaration = true | |
prefixStatement = SgVariableDeclaration | |
After prefix statement processing: returnString = int x; | |
declarationCounter = 0 declarationString = int x; | |
newOpeningGlobalDeclarationString (length = 33) = | |
#include <stdio.h> | |
int main() | |
; | |
newOpeningLocalDeclarationString (length = 89) = | |
{ /* local stack #0 */ | |
for (int i = 0; i < 1; i++) | |
{ /* local stack #1 */ | |
int x; | |
newClosingString (length = 14) = | |
}; }; | |
Assertion failed: (fileNameCounter == 1), function buildCommandLineToSubstituteTransformationFile, file Cxx_Grammar.C, line 1298. | |
Abort trap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Rewrite_ROSE.cpp | |
* | |
* Created on: Feb 7, 2011 | |
*/ | |
#include "rose.h" | |
#include "rewriteTemplateImpl.h" | |
using namespace std; | |
class MyInheritedAttributeType { | |
public: | |
MyInheritedAttributeType(); | |
HighLevelRewrite::ScopeIdentifierEnum scope; | |
HighLevelInterfaceNodeCollection::PlacementPositionEnum location; | |
bool buildInNewScope; | |
string targetCodeString; | |
string newCodeString; | |
bool removeTargetCode; | |
}; | |
// Build a synthesized attribute for the tree traversal to test the rewrite mechanism | |
class MySynthesizedAttributeType: public HighLevelRewrite::SynthesizedAttribute { | |
public: | |
MySynthesizedAttributeType(); | |
}; | |
// tree traversal to test the rewrite mechanism | |
class MyTraversal: public HighLevelRewrite::RewriteTreeTraversal< | |
MyInheritedAttributeType, MySynthesizedAttributeType> { | |
public: | |
~MyTraversal(); | |
MyTraversal(); | |
// Functions required by the global tree traversal mechanism | |
MyInheritedAttributeType evaluateRewriteInheritedAttribute(SgNode* astNode, | |
MyInheritedAttributeType inheritedAttribute); | |
MySynthesizedAttributeType evaluateRewriteSynthesizedAttribute( | |
SgNode* astNode, MyInheritedAttributeType inheritedAttribute, | |
SubTreeSynthesizedAttributes synthesizedAttributeList); | |
}; | |
MyInheritedAttributeType::MyInheritedAttributeType() { | |
// default values | |
scope = HighLevelInterfaceNodeCollection::unknownScope; | |
location = HighLevelInterfaceNodeCollection::unknownPositionInScope; | |
removeTargetCode = false; | |
} | |
MySynthesizedAttributeType::MySynthesizedAttributeType() { | |
// Nothing to do here | |
} | |
MyTraversal::~MyTraversal() { | |
// Nothing to do here | |
} | |
MyTraversal::MyTraversal() { | |
// Nothing to do here | |
} | |
MyInheritedAttributeType MyTraversal::evaluateRewriteInheritedAttribute( | |
SgNode* astNode, MyInheritedAttributeType inheritedAttribute) { | |
return inheritedAttribute; | |
} | |
MySynthesizedAttributeType MyTraversal::evaluateRewriteSynthesizedAttribute( | |
SgNode* astNode, MyInheritedAttributeType inheritedAttribute, | |
SubTreeSynthesizedAttributes synthesizedAttributeList) { | |
MySynthesizedAttributeType returnAttribute; | |
printf("In MyTraversal::evaluateRewriteSynthesizedAttribute (%s) \n", | |
astNode->sage_class_name()); | |
if (astNode->variantT() == V_SgVariableDeclaration) { | |
SgStatement* statement = isSgStatement(astNode); | |
ROSE_ASSERT (statement != NULL); | |
// Look for a target statement ("int x;") so that we avoid adding more than one string | |
string currentDeclarationStatement = astNode->unparseToString(); | |
printf("Found a declaration: currentDeclarationStatement = %s \n", | |
currentDeclarationStatement.c_str()); | |
if (currentDeclarationStatement == inheritedAttribute.targetCodeString) { | |
printf("Matching current statement = %p = %s (parent = %p) \n", | |
astNode, currentDeclarationStatement.c_str(), | |
astNode->get_parent()); | |
string newSourceString = inheritedAttribute.newCodeString; | |
printf( | |
"Found a matching target statement (insert newSourceString = %s) \n", | |
newSourceString.c_str()); | |
ROSE_ASSERT (inheritedAttribute.removeTargetCode == false); | |
returnAttribute.insert(statement, newSourceString, | |
inheritedAttribute.scope, inheritedAttribute.location); | |
returnAttribute.display( | |
"display called after addTransformationString() \n"); | |
} | |
} | |
return returnAttribute; | |
} | |
void testPermutation(SgProject* project, | |
MyInheritedAttributeType & inheritedAttribute) { | |
HighLevelInterfaceNodeCollection::ScopeIdentifierEnum scope = | |
inheritedAttribute.scope; | |
HighLevelInterfaceNodeCollection::PlacementPositionEnum positionInScope = | |
inheritedAttribute.location; | |
bool buildInNewScope = inheritedAttribute.buildInNewScope; | |
printf( | |
"In testPermutation(): scope = %s location = %s buildInNewScope = %s \n", | |
HighLevelInterfaceNodeCollection::getRelativeScopeString( | |
HighLevelRewrite::ScopeIdentifierEnum(scope)).c_str(), | |
HighLevelInterfaceNodeCollection::getRelativeLocationString( | |
HighLevelInterfaceNodeCollection::PlacementPositionEnum( | |
positionInScope)).c_str(), | |
(buildInNewScope == true) ? "true" : "false"); | |
ROSE_ASSERT (scope != HighLevelInterfaceNodeCollection::unknownScope); | |
ROSE_ASSERT (positionInScope != HighLevelInterfaceNodeCollection::unknownPositionInScope); | |
// Template used to construct new strings based on their scope and location in scope | |
// string newCodeTemplateString = "/* int y_$SCOPE_NAME_$POSITION_IN_SCOPE_NAME_$NEW_SCOPE_TEST; */"; | |
string newCodeTemplateString = inheritedAttribute.newCodeString; | |
// Build and edit the new code string (if the new code string contains $SCOPE_NAME, | |
// $POSITION_IN_SCOPE_NAME, and $NEW_SCOPE_TEST string substitution variables. | |
string tempString = newCodeTemplateString; | |
tempString | |
= StringUtility::copyEdit( | |
tempString, | |
"$SCOPE_NAME", | |
HighLevelInterfaceNodeCollection::getRelativeScopeString( | |
HighLevelInterfaceNodeCollection::ScopeIdentifierEnum( | |
scope))); | |
tempString = StringUtility::copyEdit(tempString, "$POSITION_IN_SCOPE_NAME", | |
HighLevelInterfaceNodeCollection::getRelativeLocationString( | |
HighLevelInterfaceNodeCollection::PlacementPositionEnum( | |
positionInScope))); | |
tempString = StringUtility::copyEdit(tempString, "$NEW_SCOPE_TEST", | |
(buildInNewScope == true) ? "BuildInNewScope_true" | |
: "BuildInNewScope_false"); | |
// Set the new source code string | |
inheritedAttribute.newCodeString = tempString; | |
// ROSE_ASSERT (inheritedAttribute.projectPointer != NULL); | |
// The traversal uses the AST rewrite mechanism which requires the SgProject object to retrive the | |
// command line for compilation of the intermeditate files (from strings to AST fragments) before | |
// patching them into the application's AST. | |
// MyTraversal myTraversal(*(inheritedAttribute.projectPointer)); | |
MyTraversal myTraversal; | |
// Error checking | |
// printf ("inheritedAttribute.newCodeString = %s \n",inheritedAttribute.newCodeString.c_str()); | |
// Clear the flags after modifying the tree processing the tree | |
// AstClearVisitFlags cleanTreeFlags; | |
// printf ("In testRewriteReplacementPermutations (test code): clear internal visit flags \n"); | |
// cleanTreeFlags.traverse(project); | |
myTraversal.traverseInputFiles(project, inheritedAttribute); | |
// printf ("In testRewriteReplacementPermutations (test code): clear internal visit flags \n"); | |
// cleanTreeFlags.traverse(project); | |
} | |
void transformation(SgProject* project) { | |
printf("Project = %s \n", project->unparseToString().c_str()); | |
// Build the inherited attribute | |
// MyInheritedAttributeType inheritedAttribute (&sageProject); | |
MyInheritedAttributeType inheritedAttribute; | |
// default setting for debugging AST rewrite mechanism | |
inheritedAttribute.targetCodeString = "int x;"; | |
string newCodeTemplateString = | |
"int y_$SCOPE_NAME_$POSITION_IN_SCOPE_NAME_$NEW_SCOPE_TEST;"; | |
// Test the the use of strings inserted into newScopes and not inserted into new scopes | |
int trueFalseIndex = 1; | |
// First insert the new string | |
inheritedAttribute.removeTargetCode = false; | |
inheritedAttribute.scope | |
= HighLevelInterfaceNodeCollection::SurroundingScope; | |
inheritedAttribute.location | |
= HighLevelInterfaceNodeCollection::AfterCurrentPosition; | |
// inheritedAttribute.newCodeString = "/* comment only */"; | |
inheritedAttribute.newCodeString = newCodeTemplateString; | |
printf("inheritedAttribute.newCodeString = -->%s<-- \n", | |
inheritedAttribute.newCodeString.c_str()); | |
// Control the creation of strings in a new scope or not | |
inheritedAttribute.buildInNewScope = (trueFalseIndex != 0); | |
testPermutation(project, inheritedAttribute); | |
string projectString = project->unparseToString(); | |
string newCodeString = inheritedAttribute.newCodeString; | |
printf( | |
"################################################################### \n"); | |
printf("newCodeString = -->%s<-- \n", newCodeString.c_str()); | |
printf("project->unparseToString() = \n%s\n", projectString.c_str()); | |
printf( | |
"################################################################### \n"); | |
// Transformations inserted into the preamble don't appear in the final AST | |
// (only in the intermediate file generated to compile the transformation | |
// strings and generate the AST fragements that are edited into place in | |
// the application's AST. | |
// printf ("\n\n At base of transformation() \n\n\n"); | |
} | |
int main(int argc, char * argv[]) { | |
// Build the AST used by ROSE | |
SgProject* project = frontend(argc, argv); | |
// Run internal consistency tests on AST | |
AstTests::runAllTests(project); | |
printf("Calling transformation \n"); | |
transformation(project); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int GlobalScopePreambleStart = 0; | |
int GlobalScopePreambleEnd = 0; | |
int GlobalScopeTopOfScopeStart = 0; | |
int GlobalScopeTopOfScopeEnd = 0; | |
int GlobalScopeTopOfIncludeRegionStart = 0; | |
int GlobalScopeTopOfIncludeRegionEnd = 0; | |
#include <stdio.h> | |
int main() | |
; | |
int GlobalScopeBottomOfIncludeRegionStart = 0; | |
int GlobalScopeBottomOfIncludeRegionEnd = 0; | |
int GlobalScopeBeforeCurrentPositionStart = 0; | |
int GlobalScopeBeforeCurrentPositionEnd = 0; | |
int GlobalScopeReplaceCurrentPositionStart = 0; | |
int GlobalScopeReplaceCurrentPositionEnd = 0; | |
void functionName_1 ( int need_this_to_force_generation_of_synthesized_attribute_for_arguments_in_list ) | |
{ /* local stack #0 */ | |
for (int i = 0; i < 1; i++) | |
{ /* local stack #1 */ | |
int x; | |
int FunctionScopePreambleStart = 0; | |
int FunctionScopePreambleEnd = 0; | |
int FunctionScopeTopOfScopeStart = 0; | |
int FunctionScopeTopOfScopeEnd = 0; | |
int FunctionScopeBeforeCurrentPositionStart = 0; | |
int y_SurroundingScope_BeforeCurrentPosition_BuildInNewScope_true; | |
int FunctionScopeBeforeCurrentPositionEnd = 0; | |
int FunctionScopeReplaceCurrentPositionStart = 0; | |
int FunctionScopeReplaceCurrentPositionEnd = 0; | |
int FunctionScopeAfterCurrentPositionStart = 0; | |
int FunctionScopeAfterCurrentPositionEnd = 0; | |
int FunctionScopeBottomOfScopeStart = 0; | |
int FunctionScopeBottomOfScopeEnd = 0; | |
// Use (reference) marker variables to avoid compiler warnings | |
FunctionScopePreambleStart++; | |
FunctionScopePreambleEnd++; | |
FunctionScopeTopOfScopeStart++; | |
FunctionScopeTopOfScopeEnd++; | |
FunctionScopeBeforeCurrentPositionStart++; | |
FunctionScopeBeforeCurrentPositionEnd++; | |
FunctionScopeReplaceCurrentPositionStart++; | |
FunctionScopeReplaceCurrentPositionEnd++; | |
FunctionScopeAfterCurrentPositionStart++; | |
FunctionScopeAfterCurrentPositionEnd++; | |
FunctionScopeBottomOfScopeStart++; | |
FunctionScopeBottomOfScopeEnd++; | |
}; }; | |
int GlobalScopeAfterCurrentPositionStart; | |
int GlobalScopeAfterCurrentPositionEnd; | |
int GlobalScopeBottomOfScopeStart; | |
int GlobalScopeBottomOfScopeEnd; | |
void avoidCompilerWarnings() | |
{ | |
GlobalScopePreambleStart++; | |
GlobalScopePreambleEnd++; | |
GlobalScopeTopOfScopeStart++; | |
GlobalScopeTopOfScopeEnd++; | |
GlobalScopeTopOfIncludeRegionStart++; | |
GlobalScopeTopOfIncludeRegionEnd++; | |
GlobalScopeBottomOfIncludeRegionStart++; | |
GlobalScopeBottomOfIncludeRegionEnd++; | |
GlobalScopeBeforeCurrentPositionStart++; | |
GlobalScopeBeforeCurrentPositionEnd++; | |
GlobalScopeReplaceCurrentPositionStart++; | |
GlobalScopeReplaceCurrentPositionEnd++; | |
GlobalScopeAfterCurrentPositionStart++; | |
GlobalScopeAfterCurrentPositionEnd++; | |
GlobalScopeBottomOfScopeStart++; | |
GlobalScopeBottomOfScopeEnd++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment