On 02/16/2018 01:56 PM, Stanislav Sinyagin wrote:
But many variables don't have #define statements and are used as literal strings in the code.
To clarify, the strings are the first thing I did. The regex is pretty simple, although it will need some verification to make sure it's matching everything: var_expr = r'(switch_channel_get_variable\w*\(\w+[\-*\>*\w*]*\,\s*(?P<variable>\"*\w+\"*))' Then for the #define: cpp_expr = r'#define (?P<const>.+) (?P<val>.+)' First we pass over the whole source, headers and c source files included, looking for defines to create a "database" with the constants. Then we do a second pass matching on var_expr. It finds about ~1400 matches. If the variable is a string literal (we check for the presence of '"'), it gets stored in a "variable database" with references to the source file and line. If it's not surrounded by quotes, then we try to check if it's a constant. If that's the case, then we add that variable to our variable database (also with source file and line). Finally, the left overs... about 50 are marked as needing review. I have to investigate those.