Skip to content

Commit faa94bb

Browse files
committed
Fix issue with splitting global declarations. Add the ability to split initializations of global variables
1 parent 7ddd390 commit faa94bb

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/Transform/Clang/SplitDecls.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct notSingleDecl {
9797
std::deque<SourceLocation> ends;
9898
std::deque<std::string> names;
9999
std::string varDeclType;
100+
bool typeFlag = false;
100101
};
101102

102103

@@ -171,6 +172,7 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
171172

172173
std::map<clang::SourceLocation, notSingleDecl>::iterator it;
173174
for (it = globalVarDeclsMap.begin(); it != globalVarDeclsMap.end(); it++) {
175+
std::cout << "GLOBAL INSERT\n";
174176
if (it->second.isNotSingleFlag) {
175177
// SourceRange toInsert(it->second.notSingleDeclStart, it->second.ends.back());
176178
SourceRange toInsert(it->second.notSingleDeclStart, it->second.ends.back());
@@ -208,7 +210,9 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
208210
return RecursiveASTVisitor::TraverseTypeLoc(Loc);
209211
}
210212
for (it = globalVarDeclsMap.begin(); it != globalVarDeclsMap.end(); it++) {
211-
if (it->second.varDeclsNum == 1) {
213+
if (it->second.isNotSingleFlag && !it->second.typeFlag) {
214+
// if (it->second.varDeclsNum == 1) {
215+
it->second.typeFlag = true;
212216
it->second.varDeclType = getType(it->first, Loc.getEndLoc());
213217
return RecursiveASTVisitor::TraverseTypeLoc(Loc);
214218
}
@@ -279,17 +283,17 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
279283
std::map<clang::SourceLocation, notSingleDecl>::iterator it;
280284
for (it = globalVarDeclsMap.begin(); it != globalVarDeclsMap.end(); it++) {
281285
if (it->first != S->getBeginLoc()) {
282-
//it->second.starts.clear();
283-
//it->second.ends.clear();
284-
//it->second.names.clear();
285-
//globalVarDeclsMap.erase(it->first);
286+
// it->second.starts.clear();
287+
// it->second.ends.clear();
288+
// it->second.names.clear();
289+
// globalVarDeclsMap.erase(it->first);
286290
}
287291
}
288292
}
289-
if (globalVarDeclsMap[S->getBeginLoc()].varDeclsNum == 1) {
293+
globalVarDeclsMap[S->getBeginLoc()].varDeclsNum++;
294+
if (globalVarDeclsMap[S->getBeginLoc()].varDeclsNum == 2) {
290295
globalVarDeclsMap[S->getBeginLoc()].isNotSingleFlag = true;
291296
}
292-
globalVarDeclsMap[S->getBeginLoc()].varDeclsNum++;
293297
SourceRange toInsert(S->getBeginLoc(), S->getEndLoc());
294298
ProcessGlobalDeclaration(S, toInsert);
295299
}

0 commit comments

Comments
 (0)