@@ -97,7 +97,6 @@ struct notSingleDecl {
9797 std::deque<SourceLocation> ends;
9898 std::deque<std::string> names;
9999 std::string varDeclType;
100- bool typeFlag = false ;
101100};
102101
103102
@@ -209,18 +208,18 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
209208 localVarDecls.varDeclType = getType (start, Loc.getEndLoc ());
210209 return RecursiveASTVisitor::TraverseTypeLoc (Loc);
211210 }
212- for (it = globalVarDeclsMap.begin (); it != globalVarDeclsMap.end (); it++) {
213- if (it->second .isNotSingleFlag && !it->second .typeFlag ) {
214- // if (it->second.varDeclsNum == 1) {
215- it->second .typeFlag = true ;
216- it->second .varDeclType = getType (it->first , Loc.getEndLoc ());
211+ if (globalVarDeclsMap.count (currentSL)) {
212+ if (globalVarDeclsMap[currentSL].varDeclsNum == 1 ) {
213+ std::cout << " CURRENT = " << globalVarDeclsMap.count (currentSL) << std::endl;
214+ globalVarDeclsMap[currentSL].varDeclType = getType (currentSL, Loc.getEndLoc ());
217215 return RecursiveASTVisitor::TraverseTypeLoc (Loc);
218216 }
219217 }
220218 return true ;
221219 }
222220
223221 void ProcessLocalDeclaration (VarDecl *S, SourceRange toInsert) {
222+ std::string txtStr;
224223 ExternalRewriter Canvas (toInsert, mSrcMgr , mLangOpts );
225224 SourceRange Range (S->getLocation ());
226225 std::cout << " Range: " << Canvas.getRewrittenText (Range).str () << std::endl;
@@ -247,6 +246,7 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
247246 }
248247
249248 void ProcessGlobalDeclaration (VarDecl *S, SourceRange toInsert) {
249+ std::string txtStr;
250250 ExternalRewriter Canvas (toInsert, mSrcMgr , mLangOpts );
251251 SourceRange Range (S->getLocation ());
252252 std::cout << " Range: " << Canvas.getRewrittenText (Range).str () << std::endl;
@@ -278,6 +278,7 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
278278 }
279279
280280 bool VisitVarDecl (VarDecl *S) { // to traverse the parse tree and visit each statement
281+ currentSL = S->getBeginLoc ();
281282 if (mGlobalInfo .findOutermostDecl (S)) {
282283 if (globalVarDeclsMap[S->getBeginLoc ()].varDeclsNum == 0 ) {
283284 std::map<clang::SourceLocation, notSingleDecl>::iterator it;
@@ -365,9 +366,8 @@ class ClangSplitter : public RecursiveASTVisitor<ClangSplitter> {
365366 std::map<SourceLocation, notSingleDecl> globalVarDeclsMap;
366367 std::map<SourceLocation, SourceLocation> varPositions;
367368 notSingleDecl localVarDecls;
368- notSingleDecl tmpVarDecl;
369- std::string txtStr;
370369 SourceLocation start;
370+ SourceLocation currentSL;
371371};
372372}
373373
0 commit comments