Now I'm working on a problem, its operator will generate a text file with a list of all declared global variables in the .CPP file.
I came up with a few ideas, the first one:
Try using ctags, so I wrote a few short scripts:
while read line do echo $line printf "%s" $line >> report.txt ctags -x --c++-kinds=v --file-scope=no "{$line}" | sort | sed "/const/d" | awk '{printf " %s", $1}' >> report.txt printf "\n" >> report.txt done < cpp_source_file_list.txt
This piece of code gets the name of the .cpp file of the source file from cpp_source_file_list.txt, scans it for global variables (ignoring const) and writes the report "filename [variable list]. The main problem I encountered is that ctags is very strange ignores in some cases STL types.
For example, it may exclude the string vike "vector v;" but includes "std :: vector v;".
Is there any way to fix this problem? An attempt to use the additional key ctags -I./id.txt and manually enumerate the list of identifiers, but it also leads to incorrect results.
The second way:
Use the nm command, for example:
nm builtsource.o | grep '[0-9A-Fa-f]* [BCDGRS]'
But in this case, I get unnecessary information, for example:
0000000000603528 BM 0000000000603548 BN 0000000000603578 B _ZSt3cin@ @GLIBCXX_3.4 <- (!) 0000000000603579 B _ZSt4cout@ @GLIBCXX_3.4 <- (!) 0000000000603748 B t
And now I have no idea how to implement one of these methods to get the correct information about the list of declared global variables from an arbitrary .cpp source file. I would be glad to hear any suggestion on this issue.