Parsing / reading C-Header files using Java

前端 未结 4 1354
后悔当初
后悔当初 2020-12-05 09:07

I have a C-Header file defining a couple of stucts, containing multiple char arrays.

I\'d like to parse these files using Java. Is there a library for reading C-Hea

4条回答
  •  孤城傲影
    2020-12-05 09:32

    As mentioned already, CDT is perfect for this task. But unlike described above I used it from within a plugin and was able to use IFiles. Then everything is so mouch easier. To get the "ITranslationUnit" just do:

    ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(myIFile);
    IASTTranslationUnit ias = tu.getAST();
    

    I was i.e. looking for a special #define, so I could just:

    ppc = ias.getAllPreprocessorStatements();
    

    To get all the preprocessed code statements, each statement in array-element. Perfectly easy.

提交回复
热议问题