Recently, I worked with the ROSE compiler, and I managed to apply several code attachments to the C source code and get a successful output. However, when I visited SgAssignOps, I was unable to insert an assignment operator. This is a simplified version of my code to show the problem:
#include "rose.h"
#include <iostream>
#include <transformationSupport.h>
using namespace SageInterface;
using namespace SageBuilder;
using namespace std;
int main (int argc, char *argv[])
{
SgProject *project = frontend (argc, argv);
std::vector<SgNode* > assignOpList = NodeQuery::querySubTree (project, V_SgAssignOp);
std::vector<SgNode*>::iterator iter;
for (iter = assignOpList.begin(); iter!= assignOpList.end(); iter++) {
SgNode * node = (*iter);
SgStatement * asmStmt = TransformationSupport::getStatement(node);
ostringstream osPragma;
osPragma << "example statement";
SgPragmaDeclaration* pragmaDecl = buildPragmaDeclaration(osPragma.str());
insertStatementBefore(asmStmt, pragmaDecl);
SgExprStatement* newAsmt = buildAssignStatement(buildVarRefExp("a"),buildIntVal(9));
insertStatementAfter(asmStmt,newAsmt);
}
AstTests::runAllTests(project);
project->unparse();
}
Simple input code:
int main(int argc, char* argv[])
{
int a;
a = 3;
return a;
}
The code is compiling. However..
When applied to the input code, I get a segmentation error, no error messages.
If I delete the insertion of an assignment statement, pragmatic insertion works.
If I remove the call to runAllTests (), I get the following error message when disclosing:
test: /mnt/DATA/rose/src/backend/unparser/nameQualificationSupport.C:4986: virtual NameQualificationInheritedAttribute NameQualificationTraversal::evaluateInheritedAttribute(SgNode*, NameQualificationInheritedAttribute): Assertion `initializedName->get_parent() != __null' failed.
Aborted (core dumped)
Notice that I use "a" in this example and in the input code, so the variable is already declared.
What would be the correct way to insert such an assignment?
, , . Scope node ScopeStack? , ? -.