Skip to content

Commit 4883ce9

Browse files
committed
SplitDecls with initialization
1 parent 4bd18d8 commit 4883ce9

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

lib/Transform/Clang/SplitDecls.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
141141
varDeclsNames.pop_back();
142142
}
143143
}
144-
varDeclsStarts.clear();
145-
varDeclsEnds.clear();
146-
varDeclsNames.clear();
144+
147145
if (mClauses.empty() || !isa<CompoundStmt>(S) &&
148146
!isa<ForStmt>(S) && !isa<DoStmt>(S) && !isa<WhileStmt>(S))
149147
return RecursiveASTVisitor::TraverseStmt(S);
@@ -177,7 +175,6 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
177175
bool TraverseTypeLoc(TypeLoc Loc) {
178176
if (isNotSingleFlag && varDeclsNum == 1) {
179177
SourceRange varDeclRange(start, Loc.getEndLoc());
180-
// TypeRange = Loc.getSourceRange();
181178
std::string type = mRewriter.getRewrittenText(varDeclRange);
182179
std::cout << "type = " << type << std::endl;
183180
varDeclType = type;
@@ -198,25 +195,20 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
198195
SourceRange varDeclRange(S->getBeginLoc(), S->getEndLoc());
199196
if (varDeclsNum == 1) {
200197
isFirstVar = true;
201-
SourceRange toInsert2(Range.getBegin(), S->getEndLoc());
202198
txtStr = Canvas.getRewrittenText(varDeclRange).str();
203199
std::cout << "first varDeclsNum = " << varDeclsNum << " " << txtStr << std::endl;
204200
}
205201
if (varDeclsNum > 1) {
206202
SourceRange prevVarDeclRange(varDeclsStarts.back(), varDeclsEnds.back());
207203
varDeclsStarts.pop_back();
208204
varDeclsEnds.pop_back();
209-
std::cout << Canvas.getRewrittenText(prevVarDeclRange).str() << std::endl;
210205
Canvas.ReplaceText(prevVarDeclRange, "");
211206
txtStr = Canvas.getRewrittenText(varDeclRange).str();
212207
auto it = std::remove(txtStr.begin(), txtStr.end(), ',');
213208
txtStr.erase(it, txtStr.end());
214209
size_t foundIndex = txtStr.find("\n");
215210
if (foundIndex != std::string::npos)
216-
{
217-
txtStr.erase(foundIndex, 2);
218-
}
219-
//txtStr.erase(txtStr.find(","),1);
211+
txtStr.erase(foundIndex, 2);
220212
std::cout << "varDeclsNum = " << varDeclsNum << " " << txtStr << std::endl;
221213
}
222214
varDeclsNames.push_front(txtStr + ";\n");
@@ -228,9 +220,11 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
228220
if(!(S->isSingleDecl())) {
229221
start = S->getBeginLoc();
230222
//if (!isNotSingleFlag) {
231-
std::cout << "hi\n";
232223
varDeclsNum = 0;
233224
//}
225+
varDeclsStarts.clear();
226+
varDeclsEnds.clear();
227+
varDeclsNames.clear();
234228
isNotSingleFlag = true;
235229
notSingleDeclStart = S->getBeginLoc();
236230
notSingleDeclEnd = S->getEndLoc();
@@ -270,12 +264,12 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
270264
DenseSet<DeclStmt*> mMultipleDecls;
271265
std::deque<SourceLocation> varDeclsStarts;
272266
std::deque<SourceLocation> varDeclsEnds;
267+
std::deque<SourceRange> Ranges;
273268
std::deque<std::string> varDeclsNames;
274269
int varDeclsNum = 0;
275270
SourceLocation notSingleDeclStart;
276271
SourceLocation notSingleDeclEnd;
277272
SourceRange TypeRange;
278-
bool isArrayTypeFlag = false;
279273
bool SplitDeclarationFlag = false;
280274
bool isNotSingleFlag = false;
281275
bool isAfterNotSingleFlag = false;

0 commit comments

Comments
 (0)