ISLEman
parserintf.h
1 /******************************************************************************
2  *
3  *
4  *
5  * Copyright (C) 1997-2015 by Dimitri van Heesch.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation under the terms of the GNU General Public License is hereby
9  * granted. No representations are made about the suitability of this software
10  * for any purpose. It is provided "as is" without express or implied warranty.
11  * See the GNU General Public License for more details.
12  *
13  * Documents produced by Doxygen are derivative works derived from the
14  * input used in their production; they are not affected by this license.
15  *
16  */
17 
18 #ifndef PARSERINTF_H
19 #define PARSERINTF_H
20 
21 #include <qdict.h>
22 #include <qstrlist.h>
23 
24 #include "types.h"
25 
26 class Entry;
27 class FileDef;
29 class MemberDef;
30 class Definition;
31 
39 {
40  public:
41  virtual ~ParserInterface() {}
42 
50  virtual void startTranslationUnit(const char *fileName) = 0;
51 
55  virtual void finishTranslationUnit() = 0;
56 
68  virtual void parseInput(const char *fileName,
69  const char *fileBuf,
70  Entry *root,
71  bool sameTranslationUnit,
72  QStrList &filesInSameTranslationUnit) = 0;
73 
79  virtual bool needsPreprocessing(const QCString &extension) = 0;
80 
103  virtual void parseCode(CodeOutputInterface &codeOutIntf,
104  const char *scopeName,
105  const QCString &input,
106  SrcLangExt lang,
107  bool isExampleBlock,
108  const char *exampleName=0,
109  FileDef *fileDef=0,
110  int startLine=-1,
111  int endLine=-1,
112  bool inlineFragment=FALSE,
113  MemberDef *memberDef=0,
114  bool showLineNumbers=TRUE,
115  Definition *searchCtx=0,
116  bool collectXRefs=TRUE
117  ) = 0;
118 
124  virtual void resetCodeParserState() = 0;
125 
132  virtual void parsePrototype(const char *text) = 0;
133 
134 };
135 
136 //-----------------------------------------------------------------------------
137 
144 {
145  public:
149  : m_defaultParser(0) { m_parsers.setAutoDelete(TRUE); }
150  ~ParserManager()
151  {
152  delete m_defaultParser;
153  }
154 
155  void registerDefaultParser(ParserInterface *parser)
156  {
157  m_defaultParser = parser;
158  }
159 
166  void registerParser(const char *name,ParserInterface *parser)
167  {
168  m_parsers.insert(name,parser);
169  }
170 
174  bool registerExtension(const char *extension, const char *parserName)
175  {
176  if (parserName==0 || extension==0) return FALSE;
177  ParserInterface *intf = m_parsers.find(parserName);
178  if (intf==0) return FALSE;
179  if (m_extensions.find(extension)!=0) // extension already exists
180  {
181  m_extensions.remove(extension); // remove it
182  }
183  m_extensions.insert(extension,intf); // add new mapping
184  return TRUE;
185  }
186 
191  ParserInterface *getParser(const char *extension)
192  {
193  QCString ext = QCString(extension).lower();
194  if (ext.isEmpty()) ext=".no_extension";
195  ParserInterface *intf = m_extensions.find(ext);
196  if (intf==0 && ext.length()>4)
197  {
198  intf = m_extensions.find(ext.left(4));
199  }
200  return intf ? intf : m_defaultParser;
201  }
202 
203  private:
204  QDict<ParserInterface> m_parsers;
205  QDict<ParserInterface> m_extensions;
206  ParserInterface *m_defaultParser;
207 };
208 
209 #endif
ParserInterface * getParser(const char *extension)
Gets the interface to the parser associated with given extension.
Definition: parserintf.h:191
Definition: qstrlist.h:57
virtual void startTranslationUnit(const char *fileName)=0
Starts processing a translation unit (source files + headers).
This file contains a number of basic enums and types.
The common base class of all entity definitions found in the sources.
Definition: definition.h:92
A model of a class/file/namespace member symbol.
Definition: memberdef.h:43
Represents an unstructured piece of information, about an entity found in the sources.
Definition: entry.h:63
Abstract interface for programming language parsers.
Definition: parserintf.h:38
A model of a file symbol.
Definition: filedef.h:64
void registerParser(const char *name, ParserInterface *parser)
Registers an additional parser.
Definition: parserintf.h:166
virtual void finishTranslationUnit()=0
Called after all files in a translation unit have been processed.
SrcLangExt
Language as given by extension.
Definition: types.h:41
uint length() const
Returns the length of the string, excluding the 0-terminator.
Definition: qcstring.h:195
virtual void parsePrototype(const char *text)=0
Callback function called by the comment block scanner.
virtual bool needsPreprocessing(const QCString &extension)=0
Returns TRUE if the language identified by extension needs the C preprocessor to be run before feed t...
Manages programming language parsers.
Definition: parserintf.h:143
bool registerExtension(const char *extension, const char *parserName)
Registers a file extension with a parser with name parserName.
Definition: parserintf.h:174
ParserManager()
Creates the parser manager object.
Definition: parserintf.h:148
virtual void parseInput(const char *fileName, const char *fileBuf, Entry *root, bool sameTranslationUnit, QStrList &filesInSameTranslationUnit)=0
Parses a single input file with the goal to build an Entry tree.
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition: qcstring.h:189
This is an alternative implementation of QCString.
Definition: qcstring.h:131
Output interface for code parser.
Definition: outputgen.h:59
virtual void parseCode(CodeOutputInterface &codeOutIntf, const char *scopeName, const QCString &input, SrcLangExt lang, bool isExampleBlock, const char *exampleName=0, FileDef *fileDef=0, int startLine=-1, int endLine=-1, bool inlineFragment=FALSE, MemberDef *memberDef=0, bool showLineNumbers=TRUE, Definition *searchCtx=0, bool collectXRefs=TRUE)=0
Parses a source file or fragment with the goal to produce highlighted and cross-referenced output...
virtual void resetCodeParserState()=0
Resets the state of the code parser.