There is an article in the blog that describes how to add a debug header to a function. However, I think there is still a lot of work to be done. For example, the Code must be properly compiled, the file size cannot exceed buf_size for one-time reading, the function header is too simple, and multiple encoding format files are not supported. To address this huge workload, consider using existing open-source formatting tools similar to static code analysis to find a suitable solution.
To address this requirement, the code using the astyle formatting tool is improved based on version 2.03. The judgment condition is very simple: For C, except for extern "c" and struct, it is the start of the function, and extern "C" is generally used only in the header file; for C ++, apart from namespace, it is basically the beginning of the function (and namespace is generally used only in the header file -- this sentence is wrong, but when there is namespace, the {of the function is still formatted, so it is still available.) The struct and namespace still need to be manually deleted. Only a few lines of code are added, and the code section is added with // Add
By zqb down and // Add By zqb up comments, it indicates that the added code is used for debugging.
The added code contains three sections:
void ASConsole::formatFile(const string &fileName_)
Function.
Section 1:
//add by zqb downout << "#include \"debug.h\"\r\n";linesOut++;//add by zqb up
Add the header file of the debugging macro.
Section 2:
//add by zqb downif(nextLine == "{"){out << "\r\n"<<" \t"<<"DEBUG;\r\n";linesOut++;}//add by zqb up
The content of the debugging header.
Section 3:
//add by zqb downfilesAreIdentical = false;//add by zqb up
Update to a new file under any conditions.
[Note]
1. Compilation error: newline in constant: use Notepad ++ to open aslocalizer. cpp, format-> encode in UTF-8 format, save file re-Compilation
. I use free Microsoft
Visual c ++ 2008 express edition compiles vs2008. Here is the project download link.
3. Restrictions: the standard format of ANSI must be used (the command line option is-A1), which is to take the first '{' of the function as the top line.