Add the debug header to the function (extension 1)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.