Doxygen
clangparser.h
浏览该文件的文档.
1 #ifndef CLANGPARSER_H
2 #define CLANGPARSER_H
3 
4 #include "containers.h"
5 #include "types.h"
6 #include <memory>
7 #include <string>
8 
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  */
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 */
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);
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. */
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();
90 };
91 
92 #endif
StringVector
std::vector< std::string > StringVector
Definition: containers.h:32
ClangTUParser::switchToFile
void switchToFile(const FileDef *fd)
Switches to another file within the translation unit started with start().
Definition: clangparser.cpp:912
Definition
The common base class of all entity definitions found in the sources.
Definition: definition.h:76
ClangTUParser::linkMacro
void linkMacro(CodeOutputInterface &ol, const FileDef *fd, uint &line, uint &column, const char *text)
Private
@ Private
Definition: types.h:26
types.h
This file contains a number of basic enums and types.
ClangParser::ClangParser
ClangParser()
Definition: clangparser.cpp:929
ClangTUParser::writeMultiLineCodeLink
void writeMultiLineCodeLink(CodeOutputInterface &ol, const FileDef *fd, uint &line, uint &column, const Definition *d, const char *text)
ClangParser::s_instance
static ClangParser * s_instance
Definition: clangparser.h:89
ClangParser::database
const clang::tooling::CompilationDatabase * database() const
ClangTUParser::codifyLines
void codifyLines(CodeOutputInterface &ol, const FileDef *fd, const char *text, uint &line, uint &column, const char *fontClass=0)
ClangTUParser::lookup
std::string lookup(uint line, const char *symbol)
Looks for symbol which should be found at line.
Definition: clangparser.cpp:920
ClangParser::~ClangParser
virtual ~ClangParser()
Definition: clangparser.cpp:933
uint
unsigned uint
Definition: qcstring.h:40
ClangParser::instance
static ClangParser * instance()
Returns the one and only instance of the class
Definition: clangparser.cpp:29
ClangParser::p
std::unique_ptr< Private > p
Definition: clangparser.h:85
ClangTUParser::linkIdentifier
void linkIdentifier(CodeOutputInterface &ol, const FileDef *fd, uint &line, uint &column, const char *text, int tokenIndex)
ClangTUParser::writeSources
void writeSources(CodeOutputInterface &ol, const FileDef *fd)
writes the syntax highlighted source code for a file
ClangTUParser::p
std::unique_ptr< Private > p
Definition: clangparser.h:70
ClangTUParser::operator=
ClangTUParser & operator=(const ClangTUParser &)=delete
ClangTUParser::detectFunctionBody
void detectFunctionBody(const char *s)
ClangTUParser::writeLineNumber
void writeLineNumber(CodeOutputInterface &ol, const FileDef *fd, uint line, bool writeLineAnchor)
ClangTUParser::linkInclude
void linkInclude(CodeOutputInterface &ol, const FileDef *fd, uint &line, uint &column, const char *text)
ClangParser::createTUParser
std::unique_ptr< ClangTUParser > createTUParser(const FileDef *fd) const
Definition: clangparser.cpp:937
containers.h
ClangTUParser::parse
void parse()
Parse the file given at construction time as a translation unit This file should already be preproces...
Definition: clangparser.cpp:916
CodeOutputInterface
Output interface for code parser.
Definition: outputgen.h:61
clang
Definition: clangparser.h:14
ClangParser::Private
Definition: clangparser.cpp:925
ClangTUParser
Clang parser object for a single translation unit, which consists of a source file and the directly o...
Definition: clangparser.h:21
FileDef
A model of a file symbol.
Definition: filedef.h:73
ClangParser
Wrapper for to let libclang assisted parsing.
Definition: clangparser.h:75
ClangTUParser::filesInSameTU
StringVector filesInSameTU() const
Returns the list of files for this translation unit
ClangTUParser::~ClangTUParser
virtual ~ClangTUParser()
ClangTUParser::ClangTUParser
ClangTUParser(const ClangParser &parser, const FileDef *fd)