clangparser.h 2.17 KB
Newer Older
1 2 3 4
#ifndef CLANGPARSER_H
#define CLANGPARSER_H

#include <qcstring.h>
5
#include <qstrlist.h>
6

7
class CodeOutputInterface;
8 9
class FileDef;

10
/** @brief Wrapper for to let libclang assisted parsing. */
11 12 13
class ClangParser
{
  public:
14
    /** Returns the one and only instance of the class */
15
    static ClangParser *instance();
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
    
    /** Start parsing a file.
     *  @param[in] fileName The name of the file to parse.
     *  @param[in,out] filesInTanslationUnit Other files that are
     *                 part of the input and included by the file.
     *                 The function will return a subset of the files,
     *                 only including the onces that were actually found 
     *                 during parsing.
     */
    void start(const char *fileName,QStrList &filesInTranslationUnit);

    /** Switches to another file within the translation unit started
     *  with start().
     *  @param[in] The name of the file to switch to.
     */
    void switchToFile(const char *fileName);

    /** Finishes parsing a translation unit. Free any resources that
     *  were needed for parsing.
     */
36
    void finish();
37 38 39 40

    /** Looks for \a symbol which should be found at \a line and
     *  returns a clang unique reference to the symbol.
     */
41
    QCString lookup(uint line,const char *symbol);
42 43 44 45 46 47

    /** writes the syntax highlighted source code for a file
     *  @param[out] ol The output generator list to write to.
     *  @param[in]  fd The file to write sources for.
     */
    void writeSources(CodeOutputInterface &ol,FileDef *fd);
48 49

  private:
50
    void linkIdentifier(CodeOutputInterface &ol,FileDef *fd,
51 52
                        uint &line,uint &column,
                        const char *text,int tokenIndex);
53
    void linkMacro(CodeOutputInterface &ol,FileDef *fd,
54 55
                   uint &line,uint &column,
                   const char *text);
56
    void linkInclude(CodeOutputInterface &ol,FileDef *fd,
57 58
                   uint &line,uint &column,
                   const char *text);
59
    void determineInputFilesInSameTu(QStrList &filesInTranslationUnit);
60 61 62 63 64 65 66 67
    class Private;
    Private *p;
    ClangParser();
    virtual ~ClangParser();
    static ClangParser *s_instance;
};

#endif