Code comment formatting

Source: Internet
Author: User

Recently, due to project requirements, QT code has been compiled. Many annotation formats do not meet doxygen requirements.


Requirements:

Find the function implementation in the source code, parse the previous comments, and regenerate the code comments.


The next two requirements are well solved. It is difficult to implement the first requirement.


The first thought was the parser. The first thought was YACC. Unfortunately, after half a day, the production formula of C ++ was not found. It is estimated that C ++ is too complicated.

However, I found the following document to understand how to make an interpreter.

Http://www.nobugs.org/developer/parsingcpp/


Clang is the most powerful open-source tool. However, as a C ++ interpreter, the workload is obviously more than one week.

Learning, researching, and using tools that can be solved in one day.


Next, let's change your mind to see if Perl/Python has a ready-made library.

Python found the library that encapsulates clang, but unfortunately, it tried twice, compilation failed, and installation failed. In the short term, it seems that it cannot be solved, but it can only be abandoned.

Http://eli.thegreenplace.net/2011/07/03/parsing-c-in-python-with-clang/


Pycparser does not support C ++

Cppheaderparser supports the header file explanation format to meet the requirements. Unfortunately, it does not support source code.


Gcc-XML meets requirements


After finding the tool, the next task is simple.


The core issue of the entire implementation is how to know how many classes are defined in a file, how many functions are implemented, and how many lines are implemented in the file.

This information can be obtained, followed by the regular data formatting problem.


CTAG can also solve this problem, but it is inconvenient that CTAG generates a regular expression of the function, which is a little troublesome to use and is not convenient to use without a row number.



Code comment formatting

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.