"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "projects/CodeThorn/src/VariableIdMappingExtended.C" between
rose-0.11.49.0.tar.gz and rose-0.11.50.0.tar.gz

About: ROSE is a compiler infrastructure to build source-to-source program transformation and analysis tools for large-scale C, C++, UPC, Fortran, OpenMP, Java, Python and PHP applications.

VariableIdMappingExtended.C  (rose-0.11.49.0):VariableIdMappingExtended.C  (rose-0.11.50.0)
#include "sage3basic.h" #include "sage3basic.h"
#include "VariableIdMappingExtended.h" #include "VariableIdMappingExtended.h"
#include "CodeThornLib.h" #include "CodeThornLib.h"
#include "AstTerm.h" #include "AstTerm.h"
#include "CppStdUtilities.h"
using namespace Sawyer::Message; using namespace Sawyer::Message;
using namespace std; using namespace std;
namespace CodeThorn { namespace CodeThorn {
void VariableIdMappingExtended::createTypeLists() { void VariableIdMappingExtended::createTypeLists() {
_memPoolTraversal.traverseMemoryPool(); _memPoolTraversal.traverseMemoryPool();
} }
skipping to change at line 49 skipping to change at line 50
} }
void VariableIdMappingExtended::dumpTypeSizes() { void VariableIdMappingExtended::dumpTypeSizes() {
cout<<"Type sizes:"<<endl; cout<<"Type sizes:"<<endl;
for(auto tPair:_typeSize) { for(auto tPair:_typeSize) {
cout<<tPair.first->unparseToString()<<" : "<<tPair.second<<endl; cout<<tPair.first->unparseToString()<<" : "<<tPair.second<<endl;
} }
} }
bool VariableIdMappingExtended::isDataMemberAccess(SgVarRefExp* varRefExp) { bool VariableIdMappingExtended::isDataMemberAccess(SgVarRefExp* varRefExp) {
return (varRefExp!=nullptr) && (isSgDotExp(varRefExp->get_parent())||isSgArr if(varRefExp==nullptr) {
owExp(varRefExp->get_parent())) && (isSgBinaryOp(varRefExp->get_parent())->get_r this->appendErrorReportLine(string("isDataMemberAccess::varRefExp == 0"));
hs_operand()==varRefExp); return false;
}
if(SgNode* p=varRefExp->get_parent()) {
return (isSgDotExp(p)||isSgArrowExp(p)) && (isSgBinaryOp(p)->get_rhs_opera
nd()==varRefExp);
} else {
appendErrorReportLine(SgNodeHelper::locationToString(varRefExp)+" varRefEx
p->get_parent() == 0 (isDataMemberAccess)");
return false;
}
} }
bool VariableIdMappingExtended::isGlobalOrLocalVariableAccess(SgVarRefExp* var RefExp) { bool VariableIdMappingExtended::isGlobalOrLocalVariableAccess(SgVarRefExp* var RefExp) {
return (varRefExp!=nullptr) && !isDataMemberAccess(varRefExp); return (varRefExp!=nullptr) && !isDataMemberAccess(varRefExp);
} }
list<SgVarRefExp*> VariableIdMappingExtended::structAccessesInsideFunctions(Sg Project* project) { list<SgVarRefExp*> VariableIdMappingExtended::structAccessesInsideFunctions(Sg Project* project) {
list<SgVarRefExp*> varRefExpList; list<SgVarRefExp*> varRefExpList;
list<SgFunctionDefinition*> funDefList=SgNodeHelper::listOfFunctionDefinitio ns(project); list<SgFunctionDefinition*> funDefList=SgNodeHelper::listOfFunctionDefinitio ns(project);
for(list<SgFunctionDefinition*>::iterator i=funDefList.begin();i!=funDefList .end();++i) { for(list<SgFunctionDefinition*>::iterator i=funDefList.begin();i!=funDefList .end();++i) {
skipping to change at line 72 skipping to change at line 82
if(SgVarRefExp* varRefExp=isSgVarRefExp(*j)) { if(SgVarRefExp* varRefExp=isSgVarRefExp(*j)) {
if(isDataMemberAccess(varRefExp)) { if(isDataMemberAccess(varRefExp)) {
varRefExpList.push_back(varRefExp); varRefExpList.push_back(varRefExp);
} }
} }
} }
} }
return varRefExpList; return varRefExpList;
} }
list<SgVarRefExp*> VariableIdMappingExtended::variableAccessesInsideFunctions( SgProject* project) { std::list<SgVarRefExp*> VariableIdMappingExtended::variableAccessesInsideFunct ions(SgProject* project) {
list<SgVarRefExp*> varRefExpList; list<SgVarRefExp*> varRefExpList;
list<SgFunctionDefinition*> funDefList=SgNodeHelper::listOfFunctionDefinitio ns(project); list<SgFunctionDefinition*> funDefList=SgNodeHelper::listOfFunctionDefinitio ns(project);
for(list<SgFunctionDefinition*>::iterator i=funDefList.begin();i!=funDefList .end();++i) { for(list<SgFunctionDefinition*>::iterator i=funDefList.begin();i!=funDefList .end();++i) {
RoseAst ast(*i); RoseAst ast(*i);
for(RoseAst::iterator j=ast.begin();j!=ast.end();++j) { for(RoseAst::iterator j=ast.begin();j!=ast.end();++j) {
if(SgVarRefExp* varRefExp=isSgVarRefExp(*j)) { if(SgVarRefExp* varRefExp=isSgVarRefExp(*j)) {
if(!(isDataMemberAccess(varRefExp))) { if(!(isDataMemberAccess(varRefExp))) {
varRefExpList.push_back(varRefExp); varRefExpList.push_back(varRefExp);
} }
} }
} }
} }
return varRefExpList; return varRefExpList;
} }
// workaround function, no longer necessary SgStatement* VariableIdMappingExtended::correspondingStmtOfExpression(SgExpres
int32_t VariableIdMappingExtended::repairVarRefExpAccessList(list<SgVarRefExp* sion* exp) {
>& accesses, string accessName) { // traverse upwards until a stmt node is found
int32_t numErrors=0; SgNode* node=exp;
// check if all symbols of VarRefExp in structure accesses are represented i while(!isSgStatement(node)) {
n gathered class data members' symbols node=node->get_parent();
if(node==nullptr)
return 0;
}
return isSgStatement(node);
}
std::list<std::pair<SgStatement*,SgVarRefExp*>> VariableIdMappingExtended::com
puteCorrespondingStmtsOfBrokenExpressions(list<SgVarRefExp*>& accesses) {
std::list<std::pair<SgStatement*,SgVarRefExp*>> list;
for(auto v:accesses) { for(auto v:accesses) {
VariableId varId=variableId(v); VariableId varId=variableId(v);
if(!varId.isValid()) { if(!varId.isValid()) {
// report error, and record error SgStatement* stmt=correspondingStmtOfExpression(v);
numErrors++; // node can be 0, this indicates that the AST has broken parent pointers
SgVariableSymbol* varSym=v->get_symbol(); list.push_back(make_pair(stmt,v));
SgInitializedName* initName=varSym->get_declaration();
SgVariableDeclaration* decl=isSgVariableDeclaration(initName->get_declar
ation());
if(decl && isMemberVariableDeclaration(decl)) {
if(SgClassDefinition* cdef=isSgClassDefinition(decl->get_parent())) {
//cout<<"Repairing AST symbol inconsistency #"<<numErrors<<": found
class of unregistered symbol:"<<cdef->get_qualified_name ()<<" defined in:"<<SgN
odeHelper::sourceFilenameLineColumnToString(cdef)<<endl;
SgClassDeclaration* classDecl=cdef->get_declaration();
ROSE_ASSERT(classDecl);
SgClassType* classType=classDecl->get_type();
ROSE_ASSERT(classType);
//cout<<": registering class members. of unregistered symbol:"<<cdef
->get_qualified_name ()<<" defined in:"<<SgNodeHelper::sourceFilenameLineColumnT
oString(cdef)<<endl;
// register class members based on definition (not SgType)
std::list<SgVariableDeclaration*> memberList;
auto classMemberList=cdef->get_members();
for( auto classMember : classMemberList) {
if(SgVariableDeclaration* varDecl=isSgVariableDeclaration(classMem
ber)) {
memberList.push_back(varDecl);
}
}
bool repairMode=true;
registerClassMembers(classType, memberList , 0, repairMode); // this
is *not* the classType through which this definition can be found (BUG), but an
equivalent one
} else {
//cout<<": could not find class of unregistered symbol!";
}
}
} }
} }
return numErrors; return list;
} }
int32_t VariableIdMappingExtended::checkVarRefExpAccessList(list<SgVarRefExp*> & accesses, string accessName) { int32_t VariableIdMappingExtended::checkVarRefExpAccessList(list<SgVarRefExp*> & accesses, string accessName) {
int32_t numErrors=0; int32_t numErrors=0;
// check if all symbols of VarRefExp in structure accesses are represented i n gathered class data members' symbols // check if all symbols of VarRefExp in structure accesses are represented i n gathered class data members' symbols
for(auto v:accesses) { for(auto v:accesses) {
VariableId varId=variableId(v); VariableId varId=variableId(v);
if(!varId.isValid()) { if(!varId.isValid()) {
// report error, and record error // report error, and record error
numErrors++; numErrors++;
SgVariableSymbol* varSym=v->get_symbol(); SgVariableSymbol* varSym=v->get_symbol();
cout<<"Error #"<<numErrors<<": "<<accessName<<" with unregistered symbol if(varSym==0) {
:"<<varSym<<": "<<varSym->get_name(); appendErrorReportLine("Ast symbol check error#"+std::to_string(numError
s)+": VarRefExp:get_symbol() == 0."+SgNodeHelper::locationToString(varSym));
continue;
}
stringstream ss;
ss<<"Ast symbol check error #"<<numErrors<<": "<<accessName<<" with unre
gistered symbol:"<<varSym<<": "<<varSym->get_name();
// print expression // print expression
SgExpression* eroot=v; SgExpression* eroot=v;
while(SgExpression* p=isSgExpression(eroot->get_parent())) ROSE_ASSERT(eroot);
while(SgExpression* p=isSgExpression(eroot->get_parent())) {
eroot=p; eroot=p;
cout<<":"<<SgNodeHelper::sourceFilenameLineColumnToString(eroot)<<":"<<e }
root->unparseToString(); ROSE_ASSERT(eroot);
ss<<":"<<SgNodeHelper::locationToString(eroot)<<":"<<eroot->unparseToStr
ing();
SgInitializedName* initName=varSym->get_declaration(); SgInitializedName* initName=varSym->get_declaration();
if(initName==0) {
appendErrorReportLine(ss.str()+" initName=varSym->get_declaration()==0"
);
continue;
}
SgVariableDeclaration* decl=isSgVariableDeclaration(initName->get_declar ation()); SgVariableDeclaration* decl=isSgVariableDeclaration(initName->get_declar ation());
if(decl && isMemberVariableDeclaration(decl)) { if(decl && isMemberVariableDeclaration(decl)) {
if(SgClassDefinition* cdef=isSgClassDefinition(decl->get_parent())) { if(SgClassDefinition* cdef=isSgClassDefinition(decl->get_parent())) {
cout<<": found class of unregistered symbol:"<<cdef->get_qualified_n ame ()<<" defined in:"<<SgNodeHelper::sourceFilenameLineColumnToString(cdef); cout<<": found class of unregistered symbol:"<<cdef->get_qualified_n ame ()<<" defined in:"<<SgNodeHelper::sourceFilenameLineColumnToString(cdef);
//SgClassDeclaration* classDecl=cdef->get_declaration(); //SgClassDeclaration* classDecl=cdef->get_declaration();
//ROSE_ASSERT(classDecl); //ROSE_ASSERT(classDecl);
//SgClassType* classType=classDecl->get_type(); //SgClassType* classType=classDecl->get_type();
//ROSE_ASSERT(classType); //ROSE_ASSERT(classType);
} else { } else {
cout<<": could not find class of unregistered symbol!"; ss<<": could not find class of unregistered symbol!";
} }
} }
cout<<endl; appendErrorReportLine(ss.str());
} }
} }
return numErrors; return numErrors;
} }
bool VariableIdMappingExtended::consistencyCheck(SgProject* project) { bool VariableIdMappingExtended::astSymbolCheck(SgProject* project) {
list<SgVarRefExp*> varAccesses=variableAccessesInsideFunctions(project); list<SgVarRefExp*> varAccesses=variableAccessesInsideFunctions(project);
int32_t numVarErrors=checkVarRefExpAccessList(varAccesses,"var access"); int32_t numVarErrors=checkVarRefExpAccessList(varAccesses,"var access");
list<SgVarRefExp*> structAccesses=structAccessesInsideFunctions(project); list<SgVarRefExp*> structAccesses=structAccessesInsideFunctions(project);
int32_t numStructErrors=checkVarRefExpAccessList(structAccesses,"struct acce ss"); int32_t numStructErrors=checkVarRefExpAccessList(structAccesses,"struct acce ss");
if(numVarErrors>0||numStructErrors) { if(numVarErrors>0||numStructErrors) {
cout<<"\nINFO: ROSE AST Symbol Consistency check FAILED (var access errors string line="Ast symbol check: FAIL (var access errors:"+std::to_string(nu
:"<<numVarErrors<<", struct access errors:"<<numStructErrors<<")"<<endl; mVarErrors)+", struct access errors:"+std::to_string(numStructErrors)+")";
cout<<"\nINFO: "<<line<<endl;
appendErrorReportLine(line);
} else { } else {
//cout<<"INFO: ROSE AST Symbol consistency check PASSED."<<endl; //cout<<"INFO: ROSE AST Symbol check PASSED."<<endl;
} }
return numVarErrors==0 && numStructErrors==0; return numVarErrors==0 && numStructErrors==0;
} }
bool VariableIdMappingExtended::isUnion(SgClassType* type) { bool VariableIdMappingExtended::isUnion(SgClassType* type) {
if(SgClassDeclaration* classDecl=getClassDeclarationOfClassType(type)) { if(SgClassDeclaration* classDecl=getClassDeclarationOfClassType(type)) {
SgClassDeclaration::class_types classType=classDecl->get_class_type(); SgClassDeclaration::class_types classType=classDecl->get_class_type();
return classType==SgClassDeclaration::e_union; return classType==SgClassDeclaration::e_union;
} }
return false; return false;
skipping to change at line 229 skipping to change at line 238
void VariableIdMappingExtended::removeDataMembersOfClass(SgClassType* classTyp e) { void VariableIdMappingExtended::removeDataMembersOfClass(SgClassType* classTyp e) {
auto iter=classMembers.find(classType); auto iter=classMembers.find(classType);
//cout<<"Removing data members of class:"<<classType->unparseToString()<<" : "<<(*iter).second.size()<<endl; //cout<<"Removing data members of class:"<<classType->unparseToString()<<" : "<<(*iter).second.size()<<endl;
if(iter!=classMembers.end()) { if(iter!=classMembers.end()) {
// TODO: mark varids as invalidated // TODO: mark varids as invalidated
(*iter).second.clear(); (*iter).second.clear();
} }
} }
CodeThorn::TypeSize VariableIdMappingExtended::registerClassMembers(SgClassTyp e* classType, CodeThorn::TypeSize offset, bool repairMode) { CodeThorn::TypeSize VariableIdMappingExtended::registerClassMembers(SgClassTyp e* classType, CodeThorn::TypeSize offset, bool replaceClassDataMembersMode) {
ROSE_ASSERT(offset==0); // this parameter can be removed ROSE_ASSERT(offset==0); // this parameter can be removed
//cout<<"DEBUG: register class members/2:"<<endl; //cout<<"DEBUG: register class members/2:"<<endl;
auto result=memberVariableDeclarationsList(classType); auto result=memberVariableDeclarationsList(classType);
// if member variables of class cannot be determined, return // if member variables of class cannot be determined, return
// unknown size. The number of class members can also be 0, // unknown size. The number of class members can also be 0,
// therefore the additional parameter is used to cover all other // therefore the additional parameter is used to cover all other
// cases. // cases.
//cout<<"DEBUG: register class members/2 (2):"<<endl; //cout<<"DEBUG: register class members/2 (2):"<<endl;
if(result.first==false) if(result.first==false)
return unknownSizeValue(); return unknownSizeValue();
else else
return registerClassMembers(classType,result.second,offset,repairMode); return registerClassMembers(classType,result.second,offset,replaceClassDat aMembersMode);
} }
CodeThorn::TypeSize VariableIdMappingExtended::registerClassMembers(SgClassTyp e* classType, std::list<SgVariableDeclaration*>& memberList, CodeThorn::TypeSize offset, bool repairMode) { CodeThorn::TypeSize VariableIdMappingExtended::registerClassMembers(SgClassTyp e* classType, std::list<SgVariableDeclaration*>& memberList, CodeThorn::TypeSize offset, bool replaceClassDataMembersMode) {
ROSE_ASSERT(offset==0); // this parameter can be removed and turned into a l ocal variable ROSE_ASSERT(offset==0); // this parameter can be removed and turned into a l ocal variable
ROSE_ASSERT(classType!=nullptr); ROSE_ASSERT(classType!=nullptr);
CodeThorn::TypeSize totalSize=0; CodeThorn::TypeSize totalSize=0;
//cout<<"DEBUG: Class members of: "<<classType->unparseToString()<<":"<<memb erList.size()<<endl; //cout<<"DEBUG: Class members of: "<<classType->unparseToString()<<":"<<memb erList.size()<<endl;
if(repairMode) { if(replaceClassDataMembersMode) {
// remove current entries of classType (will be replaced with new ones) // remove current entries of classType (will be replaced with new ones)
removeDataMembersOfClass(classType); removeDataMembersOfClass(classType);
} }
for(auto memberVarDecl : memberList) { for(auto memberVarDecl : memberList) {
SgSymbol* sym=SgNodeHelper::getSymbolOfVariableDeclaration(memberVarDecl); SgSymbol* sym=SgNodeHelper::getSymbolOfVariableDeclaration(memberVarDecl);
if(sym->get_symbol_basis()!=0) { if(sym->get_symbol_basis()!=0) {
//cout<<"DEBUG: Register member decl:"<<memberVarDecl->unparseToString() <<endl; //cout<<"DEBUG: Register member decl:"<<memberVarDecl->unparseToString() <<endl;
registerNewSymbol(sym); registerNewSymbol(sym);
SgType* type=sym->get_type(); SgType* type=sym->get_type();
VariableId varId=variableId(sym); VariableId varId=variableId(sym);
registerClassMemberVar(classType,varId); registerClassMemberVar(classType,varId);
getVariableIdInfoPtr(varId)->variableScope=VS_MEMBER; getVariableIdInfoPtr(varId)->variableScope=VS_MEMBER;
setOffset(varId,offset); setOffset(varId,offset);
ROSE_ASSERT(varId.isValid()); ROSE_ASSERT(varId.isValid());
//cout<<"DEBUG: Type:"<<type->unparseToString()<<endl; //cout<<"DEBUG: Type:"<<type->unparseToString()<<endl;
CodeThorn::TypeSize typeSize=unknownSizeValue(); CodeThorn::TypeSize typeSize=unknownSizeValue();
if(SgClassType* memberClassType=isSgClassType(type)) { if(SgClassType* memberClassType=isSgClassType(type)) {
getVariableIdInfoPtr(varId)->aggregateType=AT_STRUCT; getVariableIdInfoPtr(varId)->aggregateType=AT_STRUCT;
typeSize=registerClassMembers(memberClassType,0,repairMode); // start with 0 for each nested type typeSize=registerClassMembers(memberClassType,0,replaceClassDataMember sMode); // start with 0 for each nested type
setTypeSize(type,typeSize); setTypeSize(type,typeSize);
setNumberOfElements(varId,classMembers[type].size()); setNumberOfElements(varId,classMembers[type].size());
setTotalSize(varId,typeSize); setTotalSize(varId,typeSize);
} else if(SgArrayType* arrayType=isSgArrayType(type)) { } else if(SgArrayType* arrayType=isSgArrayType(type)) {
getVariableIdInfoPtr(varId)->aggregateType=AT_ARRAY; getVariableIdInfoPtr(varId)->aggregateType=AT_ARRAY;
typeSize=determineTypeSize(type); typeSize=determineTypeSize(type);
setTypeSize(type,typeSize); setTypeSize(type,typeSize);
auto numElements=determineNumberOfArrayElements(arrayType); auto numElements=determineNumberOfArrayElements(arrayType);
//cout<<"DEBUG: registerClassMembers: set numElements: "<<numElements< <endl; //cout<<"DEBUG: registerClassMembers: set numElements: "<<numElements< <endl;
setNumberOfElements(varId,numElements); setNumberOfElements(varId,numElements);
skipping to change at line 345 skipping to change at line 354
_typeSize[type]=newTypeSize; _typeSize[type]=newTypeSize;
} else { } else {
if((*typeIter).second==unknownSizeValue()) { if((*typeIter).second==unknownSizeValue()) {
// entry with exists with UnknownTypeSize, set new type size // entry with exists with UnknownTypeSize, set new type size
_typeSize[type]=newTypeSize; _typeSize[type]=newTypeSize;
} else { } else {
if((*typeIter).second==newTypeSize) { if((*typeIter).second==newTypeSize) {
// nothing to do, same value different to UnknownSize already exists // nothing to do, same value different to UnknownSize already exists
} else { } else {
stringstream ss; stringstream ss;
ss<<"type size mismatch: "<<type->unparseToString()<<": "<<_typeSize[t ss<<"type size mismatch: "<<type->unparseToString()<<": known size: "<
ype]<<" != "<<newTypeSize; <_typeSize[type]<<", new size: "<<newTypeSize<<" (ignored)";
recordWarning(ss.str()); appendErrorReportLine(ss.str());
} }
} }
} }
} }
CodeThorn::TypeSize VariableIdMappingExtended::computeTypeSize(SgType* type) { CodeThorn::TypeSize VariableIdMappingExtended::computeTypeSize(SgType* type) {
return unknownSizeValue(); return unknownSizeValue();
} }
// not used // not used
skipping to change at line 390 skipping to change at line 399
//cout<<"DEBUBG: unknown size"<<endl; //cout<<"DEBUBG: unknown size"<<endl;
return unknownSizeValue(); return unknownSizeValue();
} }
} }
} }
CodeThorn::TypeSize VariableIdMappingExtended::getBuiltInTypeSize(enum CodeTho rn::BuiltInType biType) { CodeThorn::TypeSize VariableIdMappingExtended::getBuiltInTypeSize(enum CodeTho rn::BuiltInType biType) {
return typeSizeMapping.getBuiltInTypeSize(biType); return typeSizeMapping.getBuiltInTypeSize(biType);
} }
void VariableIdMappingExtended::recordWarning(std::string warningText) {
_warnings.push_back(warningText);
}
void VariableIdMappingExtended::computeVariableSymbolMapping(SgProject* projec t, int maxWarningsCount) { void VariableIdMappingExtended::computeVariableSymbolMapping(SgProject* projec t, int maxWarningsCount) {
computeVariableSymbolMapping2(project,maxWarningsCount); computeVariableSymbolMapping2(project,maxWarningsCount);
if(getAstConsistencySymbolCheckFlag()) { bool symbolCheckOk=astSymbolCheck(project);
//cout<<"INFO: running AST symbol check."<<endl; if(!symbolCheckOk) {
bool checkOk=consistencyCheck(project); #if 0
if(!checkOk)
exit(1);
} else {
// use temporary workaround (would make check pass, but creates more than
one entry per data member of same struct)
// repair struct access symbols if necessary
list<SgVarRefExp*> structAccesses=structAccessesInsideFunctions(project); list<SgVarRefExp*> structAccesses=structAccessesInsideFunctions(project);
int32_t numStructErrorsDetected=repairVarRefExpAccessList(structAccesses," BrokenExprStmtList list=computeCorrespondingStmtsOfBrokenExpressions(struc
struct access"); tAccesses);
if(list.size()>0) {
appendErrorReportLine("Structure accesses with invalid varid: "+std::to_s
tring(list.size()));
uint32_t saErrNr=1;
for (auto p : list) {
if(p.first) {
appendErrorReportLine("struct access error #"+std::to_string(saErrNr)
+": "+SgNodeHelper::locationToString(p.first));
} else {
appendErrorReportLine("struct access error #"+std::to_string(saErrNr)
+": "+"unknown stmt location");
}
}
}
#endif
} }
generateErrorReport(symbolCheckOk);
if(getAstSymbolCheckFlag()) {
if(symbolCheckOk) {
if(_status) cout<<"STATUS: Ast symbol check passed."<<endl;
} else {
cerr<<"Error: Ast symbol check failed (see file "<<errorReportFileName<<"
)"<<endl;
exit(1);
}
}
if(getArrayAbstractionIndex()>=0) { if(getArrayAbstractionIndex()>=0) {
computeMemOffsetRemap(); computeMemOffsetRemap();
} }
} }
bool VariableIdMappingExtended::symbolExists(SgSymbol* sym) { bool VariableIdMappingExtended::symbolExists(SgSymbol* sym) {
return mappingSymToVarId.find(sym)!=mappingSymToVarId.end(); return mappingSymToVarId.find(sym)!=mappingSymToVarId.end();
} }
// returns nullptr for string-literal varIds // returns nullptr for string-literal varIds
skipping to change at line 573 skipping to change at line 596
for each param decl: setVarIdInfoFromType(param=varId->sym->type) for each param decl: setVarIdInfoFromType(param=varId->sym->type)
registerStringLiterals(project); registerStringLiterals(project);
*/ */
void VariableIdMappingExtended::registerClassMembersNew() { void VariableIdMappingExtended::registerClassMembersNew() {
for(auto classType:_memPoolTraversal.classTypes) { for(auto classType:_memPoolTraversal.classTypes) {
registerClassMembers(classType, 0); registerClassMembers(classType, 0);
//cout<<"REGISTER CLASS MEMBERS OF:"<<classType->get_name()<<endl; //cout<<"REGISTER CLASS MEMBERS OF:"<<classType->get_name()<<endl;
} }
} }
void VariableIdMappingExtended::setErrorReportFileName(std::string name) {
errorReportFileName=name;
}
void VariableIdMappingExtended::generateErrorReport(bool astSymbolCheckResult)
{
stringstream ss;
if(astSymbolCheckResult) {
ss<<"Ast symbol check: PASS"<<endl;
} else {
ss<<"Ast symbol check: FAIL"<<endl;
}
if(errorReport.size()==0) {
ss<<"VIM check: PASS"<<endl;
} else {
ss<<"VIM check: WARN"<<endl;
uint32_t errorNr=1;
for(auto s : errorReport) {
ss<<"Error "<<std::to_string(errorNr)<<": "<<s<<endl;
errorNr++;
}
ss<<"Total errors: "<<errorReport.size()<<endl;
}
if(errorReportFileName.size()>0) {
if(!CppStdUtilities::writeFile(errorReportFileName, ss.str())) {
cerr<<"Error: could not generate variable-id-mapping report file: "<<erro
rReportFileName<<endl;
} else {
if(_status) cout<<"STATUS: generated variable-id-mapping report file: "<<
errorReportFileName<<endl;
}
}
}
void VariableIdMappingExtended::appendErrorReportLine(string s) {
errorReport.push_back(s);
}
// SgInitializedName: SgName get_qualified_name(); SgSymbol* search_for_symbol _from_symbol_table(); // SgInitializedName: SgName get_qualified_name(); SgSymbol* search_for_symbol _from_symbol_table();
// SgSymbol: SgName get_mangled_name(); SgDeclarationStatement* get_declaratio n(); // SgSymbol: SgName get_mangled_name(); SgDeclarationStatement* get_declaratio n();
// SgDeclarationStatement->SgVariableDeclaration: SgInitializedName * get_decl _item(); // SgDeclarationStatement->SgVariableDeclaration: SgInitializedName * get_decl _item();
// VarRefExp: SgVariableSymbol* get_symbol(); SgInitializedName * get_declarat ion() // VarRefExp: SgVariableSymbol* get_symbol(); SgInitializedName * get_declarat ion()
void VariableIdMappingExtended::computeVariableSymbolMapping2(SgProject* proje ct, int maxWarningsCount) { void VariableIdMappingExtended::computeVariableSymbolMapping2(SgProject* proje ct, int maxWarningsCount) {
createTypeLists(); createTypeLists();
initTypeSizes(); initTypeSizes();
computeTypeSizes(); // currently does not compute any typesizes computeTypeSizes(); // currently does not compute any typesizes
registerClassMembersNew(); registerClassMembersNew();
int ct=0; int ct=0;
for(auto classDef:_memPoolTraversal.classDefinitions) { for(auto classDef:_memPoolTraversal.classDefinitions) {
SgClassDeclaration* classDecl=classDef->get_declaration(); SgClassDeclaration* classDecl=classDef->get_declaration();
if(classDecl==nullptr) {
appendErrorReportLine(SgNodeHelper::locationToString(classDef)+": class d
efinition in memory pool: get_declaration() == 0.");
continue;
}
SgClassType* classType=classDecl->get_type(); SgClassType* classType=classDecl->get_type();
if(classType==nullptr) {
appendErrorReportLine(SgNodeHelper::locationToString(classDecl)+": class
declaration (from definition) in memory pool: get_type() == 0.");
continue;
}
registerClassMembers(classType, 0); registerClassMembers(classType, 0);
ct++; ct++;
} }
list<SgGlobal*> globList=SgNodeHelper::listOfSgGlobal(project); list<SgGlobal*> globList=SgNodeHelper::listOfSgGlobal(project);
int numVarDecls=0; int numVarDecls=0;
int numSymbolExists=0; int numSymbolExists=0;
int numFunctionParams=0; int numFunctionParams=0;
for(list<SgGlobal*>::iterator k=globList.begin();k!=globList.end();++k) { for(list<SgGlobal*>::iterator k=globList.begin();k!=globList.end();++k) {
RoseAst ast(*k); RoseAst ast(*k);
ast.setWithTemplates(true); ast.setWithTemplates(true);
for(RoseAst::iterator i=ast.begin();i!=ast.end();++i) { for(RoseAst::iterator i=ast.begin();i!=ast.end();++i) {
CodeThorn::TypeSize totalSize=0; CodeThorn::TypeSize totalSize=0;
if(SgVariableDeclaration* varDecl=isSgVariableDeclaration(*i)) { if(SgVariableDeclaration* varDecl=isSgVariableDeclaration(*i)) {
if(isMemberVariableDeclaration(varDecl)) if(isMemberVariableDeclaration(varDecl))
continue; continue;
if(varDecl->unparseToString() == "... ;") // there are invalid symbols if(varDecl->unparseToString() == "... ;") {
// there are invalid symbols
appendErrorReportLine(SgNodeHelper::locationToString(varDecl)+": ther
e are invalid symbols.");
continue; continue;
//~ std::cerr << varDecl->unparseToString() << std::flush; }
addVariableDeclaration(varDecl); addVariableDeclaration(varDecl);
//~ std::cerr << '!' << std::endl;
//cout<<"DEBUG: registering var decl: "<<numVarDecls++<<":"<<SgNodeHel per::sourceFilenameLineColumnToString(*i)<<":"<<varDecl->unparseToString()<<endl ; //cout<<"DEBUG: registering var decl: "<<numVarDecls++<<":"<<SgNodeHel per::sourceFilenameLineColumnToString(*i)<<":"<<varDecl->unparseToString()<<endl ;
} }
if(SgFunctionDefinition* funDef=isSgFunctionDefinition(*i)) { if(SgFunctionDefinition* funDef=isSgFunctionDefinition(*i)) {
//cout<<"DEBUG: fun def : "<<SgNodeHelper::sourceFilenameLineColumnToS tring(*i)<<":"<<funDef->unparseToString()<<endl; //cout<<"DEBUG: fun def : "<<SgNodeHelper::sourceFilenameLineColumnToS tring(*i)<<":"<<funDef->unparseToString()<<endl;
std::vector<SgInitializedName *> & funFormalParams=SgNodeHelper::getFu nctionDefinitionFormalParameterList(*i); std::vector<SgInitializedName *> & funFormalParams=SgNodeHelper::getFu nctionDefinitionFormalParameterList(*i);
int paramNr=0;
for(auto initName : funFormalParams) { for(auto initName : funFormalParams) {
paramNr++;
//cout<<"DEBUG: registering param: "<<initName->unparseToString()<<e ndl; //cout<<"DEBUG: registering param: "<<initName->unparseToString()<<e ndl;
SgSymbol* sym=SgNodeHelper::getSymbolOfInitializedName(initName); SgSymbol* sym=SgNodeHelper::getSymbolOfInitializedName(initName);
if(symbolExists(sym)) { if(symbolExists(sym)) {
cout<<"WARNING: found formal parameter with same symbol again: "<< stringstream ss;
sym->unparseToString()<<" (skipping)."<<endl; ss<<sym;
appendErrorReportLine(SgNodeHelper::locationToString(funDef)+": fo
und formal parameter with same symbol (in SgInitializedName) again: "+ss.str()+"
(skipping).");
numSymbolExists++; numSymbolExists++;
continue; continue;
} }
if(sym->get_symbol_basis()!=0) { if(sym->get_symbol_basis()!=0) {
registerNewSymbol(sym); registerNewSymbol(sym);
VariableId varId=variableId(sym); VariableId varId=variableId(sym);
getVariableIdInfoPtr(varId)->variableScope=VS_FUNPARAM; // formal parameter declaration getVariableIdInfoPtr(varId)->variableScope=VS_FUNPARAM; // formal parameter declaration
setVarIdInfoFromType(varId); setVarIdInfoFromType(varId);
numFunctionParams++; numFunctionParams++;
} else { } else {
cout<<"Warning: no symbol basis found for function parameter: "<<i nitName->unparseToString()<<endl; appendErrorReportLine(SgNodeHelper::locationToString(funDef)+": no symbol basis found for function parameter nr "+std::to_string(paramNr)+" (start ing at 1)");
} }
} }
} }
} }
// 2nd pass over all variable declarations, to ensure all settings are bas ed on the variable declaration with an initializer (if available) // 2nd pass over all variable declarations, to ensure all settings are bas ed on the variable declaration with an initializer (if available)
for (auto pair: mappingVarIdToInfo) { for (auto pair: mappingVarIdToInfo) {
setVarIdInfoFromType(pair.first); setVarIdInfoFromType(pair.first);
} }
skipping to change at line 669 skipping to change at line 739
//cout<<"DEBUG: VID: found symbol again: "<<sym->unparseToString(); //cout<<"DEBUG: VID: found symbol again: "<<sym->unparseToString();
} else { } else {
registerNewSymbol(sym); registerNewSymbol(sym);
vidInfo=getVariableIdInfoPtr(variableId(sym)); vidInfo=getVariableIdInfoPtr(variableId(sym));
} }
ROSE_ASSERT(vidInfo); ROSE_ASSERT(vidInfo);
vidInfo->addVariableDeclaration(varDecl); // record all variable declarat ions that map to the same symbol vidInfo->addVariableDeclaration(varDecl); // record all variable declarat ions that map to the same symbol
} else { } else {
stringstream ss; stringstream ss;
ss<<sym; ss<<sym;
recordWarning("no symbol basis for sym:"+ss.str()); appendErrorReportLine(SgNodeHelper::locationToString(varDecl)+": no symbo l basis for symbol:"+ss.str());
} }
} else { } else {
cerr<<"Warning: VariableIdMappingExtended: variable declaration without sy appendErrorReportLine(SgNodeHelper::locationToString(varDecl)+": variable
mbol:"; declaration with no symbol");
cerr<<varDecl->unparseToString()<<endl;
} }
} }
// class members handling // class members handling
std::vector<VariableId> VariableIdMappingExtended::getRegisteredClassMemberVar s(SgType* type) { std::vector<VariableId> VariableIdMappingExtended::getRegisteredClassMemberVar s(SgType* type) {
return classMembers[type]; return classMembers[type];
} }
bool VariableIdMappingExtended::isRegisteredClassMemberVar(SgType* type,Variab leId varId) { bool VariableIdMappingExtended::isRegisteredClassMemberVar(SgType* type,Variab leId varId) {
std::vector<VariableId>& v=classMembers[type]; std::vector<VariableId>& v=classMembers[type];
skipping to change at line 1025 skipping to change at line 1094
} else if(SgSymbol* sym=getSymbol(varId)) { } else if(SgSymbol* sym=getSymbol(varId)) {
ss<<","<<variableName(varId); ss<<","<<variableName(varId);
ss<<",type:"<<getType(varId)->unparseToString(); ss<<",type:"<<getType(varId)->unparseToString();
} else { } else {
ss<<","<<"<missing-symbol>"; ss<<","<<"<missing-symbol>";
} }
return ss.str(); return ss.str();
} }
void VariableIdMappingExtended::setAstSymbolCheckFlag(bool flag) { void VariableIdMappingExtended::setAstSymbolCheckFlag(bool flag) {
_astConsistencySymbolCheckFlag=flag; _astSymbolCheckFlag=flag;
} }
bool VariableIdMappingExtended::getAstConsistencySymbolCheckFlag() { bool VariableIdMappingExtended::getAstSymbolCheckFlag() {
return _astConsistencySymbolCheckFlag; return _astSymbolCheckFlag;
} }
std::vector<VariableId> VariableIdMappingExtended::getClassMembers(SgType* typ e) { std::vector<VariableId> VariableIdMappingExtended::getClassMembers(SgType* typ e) {
return classMembers[type]; return classMembers[type];
} }
void VariableIdMappingExtended::MemPoolTraversal::visit(SgNode* node) { void VariableIdMappingExtended::MemPoolTraversal::visit(SgNode* node) {
if(SgClassType* ctype=isSgClassType(node)) { if(SgClassType* ctype=isSgClassType(node)) {
classTypes.insert(ctype); classTypes.insert(ctype);
} else if(SgArrayType* atype=isSgArrayType(node)) { } else if(SgArrayType* atype=isSgArrayType(node)) {
skipping to change at line 1051 skipping to change at line 1120
} else if(SgType* btype=isSgType(node)) { } else if(SgType* btype=isSgType(node)) {
builtInTypes.insert(btype); builtInTypes.insert(btype);
} else if(SgClassDefinition* cdef=isSgClassDefinition(node)) { } else if(SgClassDefinition* cdef=isSgClassDefinition(node)) {
classDefinitions.insert(cdef); classDefinitions.insert(cdef);
} }
} }
void VariableIdMappingExtended::MemPoolTraversal::dumpClassTypes() { void VariableIdMappingExtended::MemPoolTraversal::dumpClassTypes() {
int i=0; int i=0;
for(auto t:classTypes) { for(auto t:classTypes) {
auto mList=VariableIdMappingExtended::memberVariableDeclarationsList(t); auto mList=memberVariableDeclarationsList(t);
std::cout<<i++<<": class Type ("; std::cout<<i++<<": class Type (";
if(mList.first) if(mList.first)
std::cout<<mList.second.size(); std::cout<<mList.second.size();
else else
std::cout<<"unknown"; std::cout<<"unknown";
std::cout<<") :"<<t->unparseToString()<<std::endl; std::cout<<") :"<<t->unparseToString()<<std::endl;
} }
} }
void VariableIdMappingExtended::MemPoolTraversal::dumpArrayTypes() { void VariableIdMappingExtended::MemPoolTraversal::dumpArrayTypes() {
skipping to change at line 1075 skipping to change at line 1144
} }
} }
std::string VariableIdMappingExtended::typeSizeMappingToString() { std::string VariableIdMappingExtended::typeSizeMappingToString() {
stringstream ss; stringstream ss;
for(auto p: _typeSize) { for(auto p: _typeSize) {
ss<<p.first->unparseToString()<<": "<<AstTerm::astTermWithNullValuesToStri ng(p.first)<<": "<<p.second<<endl; ss<<p.first->unparseToString()<<": "<<AstTerm::astTermWithNullValuesToStri ng(p.first)<<": "<<p.second<<endl;
} }
return ss.str(); return ss.str();
} }
void VariableIdMappingExtended::setStatusFlag(bool flag) {
_status=flag;
}
} }
 End of changes. 41 change blocks. 
94 lines changed or deleted 170 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)