什么库可用于解析c

什么库可用于解析c

本文介绍了什么库可用于解析c ++提取类型信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在寻找一种方法来解析c ++代码来检索一些关于类的基本信息。我实际上不需要来自代码本身的很多信息,但我需要它来处理宏和模板。总之,我想提取代码的结构,你会在UML图中显示什么。



对于每个类/ struct / union / enum / typedef在代码库中,我需要的(处理模板和宏后)是:




  • 他们的名字

  • 它们所在的命名空间

  • (类型名称,字段名称和访问限制,例如private / mutable / etc)中包含的字段


  • 声明文件

  • 行号/列号

    实际的指令在代码中与我的目的无关。



    我预计很多人说我应该使用正则表达式(或甚至Flex和Bison),但这些都不是真的有效,因为我需要预处理器和模板东西正确处理。

    解决方案

    听起来像一个工作与您选择的c ++ xml库或xml友好的脚本语言相结合。


    I'm looking for a way to parse c++ code to retrieve some basic information about classes. I don't actually need much information from the code itself, but I do need it to handle things like macros and templates. In short, I want to extract the "structure" of the code, what you would show in a UML diagram.

    For each class/struct/union/enum/typedef in the code base, all I need (after templates & macros have been handled) is:

    • Their name
    • The namespace in which they live
    • The fields contained within (name of type, name of field and access restrictions, such as private/mutable/etc)
    • Functions contained within (return type, name, parameters)
    • The declaring file
    • Line/column numbers (or byte offset in file) where the definition of this data begins

    The actual instructions in the code are irrelevant for my purposes.

    I'm anticipating a lot of people saying I should just use a regex for this (or even Flex & Bison), but these aren't really valid, as I do need the preprocessor and template stuff handled properly.

    解决方案

    Sounds like a job for gcc-xml in combination with the c++ xml-library or xml-friendly scripting language of your choice.

    这篇关于什么库可用于解析c ++提取类型信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    1403页,肝出来的..

09-07 02:37