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 added code is surrounded by // add by zqb down and // add by zqb up annotations, respectively, indicating that the added code is used for debugging. The added code contains three sections:

Void ASConsole: formatFile (const string & fileName _) function. Section 1: [cpp] view plaincopyprint? // Add by zqb down out <"# include \" debug. h \ "\ r \ n"; linesOut ++; // add by zqb up // add by zqb downout <"# include \" debug. h \ "\ r \ n"; linesOut ++; // add by zqb up indicates the header file where the debugging macro is added.

 

Section 2:
// Add by zqb down if (nextLine = "{") {out <"\ r \ n" <"\ t" <"DEBUG; \ r \ n "; linesOut ++;} // add by zqb up // add by zqb downif (nextLine = "{") {out <"\ r \ n" <"\ t" <"DEBUG; \ r \ n"; linesOut ++ ;} // add by zqb up indicates the specific content of the debugging header.

 

Section 3:
// Add by zqb down filesAreIdentical = false; // add by zqb up // add by zqb downfilesAreIdentical = false; // add by zqb up no matter what conditions, are updated to new files.

 

[Note] 1. Compile the error: newline in constant: use notepad ++ to open ASLocalizer. cpp, format-> encode in UTF-8 format, save the file re-compile. The author uses the free Microsoft Visual C ++ 2008 Express Edition to compile the vs2008 version. Here is the download link for the project. 3. Restrictions: the standard format of ansi is required (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.