1
1
#include " TrackMacro.hpp"
2
+ #include " debug.h"
2
3
3
4
std::ostream& operator <<(std::ostream& os, const CollectedMacroInfo& cmi)
4
5
{
@@ -15,22 +16,22 @@ std::ostream& operator<<(std::ostream& os, const CollectedMacroInfo& cmi)
15
16
return os;
16
17
}
17
18
18
- // #define CLANG_AST_DEBUG
19
-
20
19
namespace clang {
21
20
22
21
void TrackMacro::MacroExpands (const Token &MacroNameTok, const MacroInfo* MI,
23
22
SourceRange Range)
24
23
{
25
- // std::cout<<"Macro "<<tok::getTokenName(MacroNameTok.getKind())<< " has expanded here\n\t";
24
+ CLANG_AST_DEBUG (dbgs () << " Macro "
25
+ << tok::getTokenName (MacroNameTok.getKind ())
26
+ << " has expanded here\n\t " ;);
27
+
26
28
// / Testing if the macro is defined in the same file
27
29
// / so that global macros can be skipped
28
30
if (sm->isInMainFile (MI->getDefinitionLoc ())) {
29
31
PresumedLoc presumed = sm->getPresumedLoc (Range.getBegin ());
30
- #ifdef CLANG_AST_DEBUG
31
- std::cout<<" \n Macro " <<MacroNameTok.getIdentifierInfo ()->getNameStart ()
32
- <<" has expanded at line# " <<presumed.getLine ();
33
- #endif
32
+ CLANG_AST_DEBUG (dbgs () << " \n Macro "
33
+ << MacroNameTok.getIdentifierInfo ()->getNameStart ()
34
+ << " has expanded at line# " << presumed.getLine (););
34
35
35
36
// NOTE PresumedLoc can be modified by the LINE directive
36
37
@@ -41,13 +42,10 @@ void TrackMacro::MacroExpands(const Token &MacroNameTok, const MacroInfo* MI,
41
42
// i think it is not useful anymore
42
43
m_istat->insert (presumed.getLine ());
43
44
44
- #ifdef CLANG_AST_DEBUG
45
- std::cout<<" arguments are:" ;
46
- auto arg_it = MI->arg_begin ();
47
- for (; arg_it != MI->arg_end (); ++arg_it){
48
- std::cout<<(*arg_it)->getNameStart ()<<" \t " ;
49
- }
50
- #endif
45
+ CLANG_AST_DEBUG (dbgs () << " arguments are:" ;
46
+ for (auto arg_it = MI->arg_begin ();
47
+ arg_it != MI->arg_end (); ++arg_it)
48
+ dbgs () << (*arg_it)->getNameStart () << " \t " ;);
51
49
52
50
// if(MacroIsLocal(Range.getBegin())) {
53
51
if (MI->isFunctionLike ()){
@@ -72,12 +70,10 @@ void TrackMacro::MacroDefined(const Token &MacroNameTok, const MacroInfo* MI)
72
70
if (sm->isInMainFile (MI->getDefinitionLoc ())) {
73
71
PresumedLoc presumed = sm->getPresumedLoc (MI->getDefinitionLoc ());
74
72
75
- #ifdef CLANG_AST_DEBUG
76
- std::cout<<" Macro "
77
- <<MacroNameTok.getIdentifierInfo ()->getNameStart ()
78
- <<" is defined at line number: "
79
- <<presumed.getLine ()<<" \n " ;
80
- #endif
73
+ CLANG_AST_DEBUG (dbgs () << " Macro "
74
+ << MacroNameTok.getIdentifierInfo ()->getNameStart ()
75
+ << " is defined at line number: "
76
+ << presumed.getLine () << " \n " ;);
81
77
82
78
cmi.defined_line = presumed.getLine ();
83
79
// std::cout<<"Macro "<<tok::getTokenName(MacroNameTok.getKind())<<" is defined here\n\t";
@@ -176,12 +172,11 @@ void TrackMacro::VerifyMacroScopeFast(std::map<std::string, ParsedDeclInfo>const
176
172
const int start = 0 ;
177
173
const int end = 1 ;
178
174
// / collect all the start line numbers of function, and sort them
179
- for ( ; fi_iter != FunctionInfo.end (); ++fi_iter)
180
- {
181
- #ifdef CLANG_AST_DEBUG
182
- std::cout<<" Function: " <<fi_iter->first <<" definition range is: ("
183
- <<(fi_iter->second ).start_line <<" ," <<(fi_iter->second ).end_line <<" )\n " ;
184
- #endif
175
+ for ( ; fi_iter != FunctionInfo.end (); ++fi_iter) {
176
+ CLANG_AST_DEBUG (dbgs () << " Function: " << fi_iter->first
177
+ << " definition range is: ("
178
+ <<(fi_iter->second ).start_line << " ,"
179
+ << (fi_iter->second ).end_line << " )\n " ;);
185
180
FunctionDefinitionRange[(fi_iter->second ).start_line ] = start;
186
181
FunctionDefinitionRange[(fi_iter->second ).end_line ] = end;
187
182
}
@@ -196,35 +191,33 @@ void TrackMacro::VerifyMacroScopeFast(std::map<std::string, ParsedDeclInfo>const
196
191
// no need to check if fdr_iter is FunctionDefinitionRange.end() or not
197
192
// because of an extra entry
198
193
199
- # ifdef CLANG_AST_DEBUG
200
- std::cout<< " For macro : " << ms->first
201
- << " Defined line is: " <<(ms-> second ). defined_line
202
- << " , the range returned is: ( "
203
- << fdr_iter->first << " , " <<fdr_iter-> second << " )\n " ;
204
- # endif
194
+ CLANG_AST_DEBUG ( dbgs () << " For macro: " << ms-> first
195
+ << " Defined line is : " << ( ms->second ). defined_line
196
+ << " , the range returned is: ( "
197
+ << fdr_iter-> first << " , "
198
+ << fdr_iter->second << " )\n " ;) ;
199
+
205
200
if (fdr_iter->second == end) {
206
201
(ms->second ).s_cat .inside_function = true ;
207
- #ifdef CLANG_AST_DEBUG
208
- std::cout<<" Macro: " <<ms->first <<" is inside function\n " ;
209
- #endif
202
+ CLANG_AST_DEBUG (dbgs () << " Macro: " << ms->first
203
+ << " is inside function\n " ;);
210
204
}
211
205
}
212
206
}
213
207
214
- void TrackMacro::VerifyMacroScope (std::map<std::string, ParsedDeclInfo>const & FunctionInfo)
208
+ void TrackMacro::
209
+ VerifyMacroScope (std::map<std::string, ParsedDeclInfo>const & FunctionInfo)
215
210
{
216
211
std::map<std::string, ParsedDeclInfo>::const_iterator fi = FunctionInfo.begin ();
217
212
std::map<std::string, CollectedMacroInfo>::iterator ms;
218
- for ( ; fi != FunctionInfo.end (); ++fi)
219
- {
213
+ for ( ; fi != FunctionInfo.end (); ++fi) {
220
214
ms = ASTMacroStat.begin ();
221
- for ( ; ms != ASTMacroStat.end (); ++ms){
215
+ for ( ; ms != ASTMacroStat.end (); ++ms) {
222
216
if ((ms->second ).defined_line > (fi->second ).start_line
223
- && (ms->second ).defined_line < (fi->second ).end_line ){
217
+ && (ms->second ).defined_line < (fi->second ).end_line ) {
224
218
(ms->second ).s_cat .inside_function = true ;
225
- #ifdef CLANG_AST_DEBUG
226
- std::cout<<" Macro: " <<ms->first <<" is inside function " <<fi->first <<" \n " ;
227
- #endif
219
+ CLANG_AST_DEBUG (dbgs () << " Macro: " << ms->first
220
+ << " is inside function " << fi->first << " \n " ;);
228
221
}
229
222
}
230
223
}
0 commit comments