1 #ifndef CLANGPARSER_H 2 #define CLANGPARSER_H 3 4 #include "containers.h" 5 #include "types.h" 6 #include <memory> 7 #include <string> 8 9 class CodeOutputInterface; 10 class FileDef; 11 class ClangParser; 12 class Definition; 13 14 namespace clang { namespace tooling { 15 class CompilationDatabase; 16 } } 17 18 /** @brief Clang parser object for a single translation unit, which consists of a source file 19 * and the directly or indirectly included headers 20 */ 21 class ClangTUParser 22 { 23 public: 24 ClangTUParser(const ClangParser &parser,const FileDef *fd); 25 virtual ~ClangTUParser(); 26 27 /** Parse the file given at construction time as a translation unit 28 * This file should already be preprocessed by doxygen preprocessor at the time of calling. 29 */ 30 void parse(); 31 32 /** Switches to another file within the translation unit started with start(). 33 * @param[in] fd The file definition with the name of the file to switch to. 34 */ 35 void switchToFile(const FileDef *fd); 36 37 /** Returns the list of files for this translation unit */ 38 StringVector filesInSameTU() const; 39 40 /** Looks for \a symbol which should be found at \a line. 41 * returns a clang unique reference to the symbol. 42 */ 43 std::string lookup(uint line,const char *symbol); 44 45 /** writes the syntax highlighted source code for a file 46 * @param[out] ol The output generator list to write to. 47 * @param[in] fd The file to write sources for. 48 */ 49 void writeSources(CodeOutputInterface &ol,const FileDef *fd); 50 51 private: 52 void detectFunctionBody(const char *s); 53 void writeLineNumber(CodeOutputInterface &ol,const FileDef *fd,uint line,bool writeLineAnchor); 54 void codifyLines(CodeOutputInterface &ol,const FileDef *fd,const char *text, 55 uint &line,uint &column,const char *fontClass=0); 56 void writeMultiLineCodeLink(CodeOutputInterface &ol, 57 const FileDef *fd,uint &line,uint &column, 58 const Definition *d, const char *text); 59 void linkIdentifier(CodeOutputInterface &ol,const FileDef *fd, 60 uint &line,uint &column, 61 const char *text,int tokenIndex); 62 void linkMacro(CodeOutputInterface &ol,const FileDef *fd, 63 uint &line,uint &column, 64 const char *text); 65 void linkInclude(CodeOutputInterface &ol,const FileDef *fd, 66 uint &line,uint &column, 67 const char *text); 68 ClangTUParser(const ClangTUParser &) = delete; 69 ClangTUParser &operator=(const ClangTUParser &) = delete; 70 class Private; 71 std::unique_ptr<Private> p; 72 }; 73 74 /** @brief Wrapper for to let libclang assisted parsing. */ 75 class ClangParser 76 { 77 friend class ClangTUParser; 78 public: 79 /** Returns the one and only instance of the class */ 80 static ClangParser *instance(); 81 std::unique_ptr<ClangTUParser> createTUParser(const FileDef *fd) const; 82 83 private: 84 const clang::tooling::CompilationDatabase *database() const; 85 class Private; 86 std::unique_ptr<Private> p; 87 ClangParser(); 88 virtual ~ClangParser(); 89 static ClangParser *s_instance; 90 }; 91 92 #endif 93