|
Packit |
1c1d7e |
/******************************************************************************
|
|
Packit |
1c1d7e |
*
|
|
Packit |
1c1d7e |
*
|
|
Packit |
1c1d7e |
*
|
|
Packit |
1c1d7e |
* Copyright (C) 1997-2015 by Dimitri van Heesch.
|
|
Packit |
1c1d7e |
*
|
|
Packit |
1c1d7e |
* Permission to use, copy, modify, and distribute this software and its
|
|
Packit |
1c1d7e |
* documentation under the terms of the GNU General Public License is hereby
|
|
Packit |
1c1d7e |
* granted. No representations are made about the suitability of this software
|
|
Packit |
1c1d7e |
* for any purpose. It is provided "as is" without express or implied warranty.
|
|
Packit |
1c1d7e |
* See the GNU General Public License for more details.
|
|
Packit |
1c1d7e |
*
|
|
Packit |
1c1d7e |
* Documents produced by Doxygen are derivative works derived from the
|
|
Packit |
1c1d7e |
* input used in their production; they are not affected by this license.
|
|
Packit |
1c1d7e |
*
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#ifndef PARSERINTF_H
|
|
Packit |
1c1d7e |
#define PARSERINTF_H
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#include <qdict.h>
|
|
Packit |
1c1d7e |
#include <qstrlist.h>
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#include "types.h"
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
class Entry;
|
|
Packit |
1c1d7e |
class FileDef;
|
|
Packit |
1c1d7e |
class CodeOutputInterface;
|
|
Packit |
1c1d7e |
class MemberDef;
|
|
Packit |
1c1d7e |
class Definition;
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** \brief Abstract interface for programming language parsers.
|
|
Packit |
1c1d7e |
*
|
|
Packit |
1c1d7e |
* By implementing the methods of this interface one can add
|
|
Packit |
1c1d7e |
* a new language parser to doxygen. The parser can make use of the
|
|
Packit |
1c1d7e |
* comment block parser to parse the contents of special comment blocks.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
class ParserInterface
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
public:
|
|
Packit |
1c1d7e |
virtual ~ParserInterface() {}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** Starts processing a translation unit (source files + headers).
|
|
Packit |
1c1d7e |
* After this call parseInput() is called with sameTranslationUnit
|
|
Packit |
1c1d7e |
* set to FALSE. If parseInput() returns additional include files,
|
|
Packit |
1c1d7e |
* these are also processed using parseInput() with
|
|
Packit |
1c1d7e |
* sameTranslationUnit set to TRUE. After that
|
|
Packit |
1c1d7e |
* finishTranslationUnit() is called.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual void startTranslationUnit(const char *fileName) = 0;
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** Called after all files in a translation unit have been
|
|
Packit |
1c1d7e |
* processed.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual void finishTranslationUnit() = 0;
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** Parses a single input file with the goal to build an Entry tree.
|
|
Packit |
1c1d7e |
* @param[in] fileName The full name of the file.
|
|
Packit |
1c1d7e |
* @param[in] fileBuf The contents of the file (zero terminated).
|
|
Packit |
1c1d7e |
* @param[in,out] root The root of the tree of Entry *nodes
|
|
Packit |
1c1d7e |
* representing the information extracted from the file.
|
|
Packit |
1c1d7e |
* @param[in] sameTranslationUnit TRUE if this file was found in the same
|
|
Packit |
1c1d7e |
* translation unit (in the filesInSameTranslationUnit list
|
|
Packit |
1c1d7e |
* returned for another file).
|
|
Packit |
1c1d7e |
* @param[in,out] filesInSameTranslationUnit other files expected to be
|
|
Packit |
1c1d7e |
* found in the same translation unit (used for libclang)
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual void parseInput(const char *fileName,
|
|
Packit |
1c1d7e |
const char *fileBuf,
|
|
Packit |
1c1d7e |
Entry *root,
|
|
Packit |
1c1d7e |
bool sameTranslationUnit,
|
|
Packit |
1c1d7e |
QStrList &filesInSameTranslationUnit) = 0;
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** Returns TRUE if the language identified by \a extension needs
|
|
Packit |
1c1d7e |
* the C preprocessor to be run before feed the result to the input
|
|
Packit |
1c1d7e |
* parser.
|
|
Packit |
1c1d7e |
* @see parseInput()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual bool needsPreprocessing(const QCString &extension) = 0;
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** Parses a source file or fragment with the goal to produce
|
|
Packit |
1c1d7e |
* highlighted and cross-referenced output.
|
|
Packit |
1c1d7e |
* @param[in] codeOutIntf Abstract interface for writing the result.
|
|
Packit |
1c1d7e |
* @param[in] lang The programming language of the code fragment.
|
|
Packit |
1c1d7e |
* @param[in] scopeName Name of scope to which the code belongs.
|
|
Packit |
1c1d7e |
* @param[in] input Actual code in the form of a string
|
|
Packit |
1c1d7e |
* @param[in] isExampleBlock TRUE iff the code is part of an example.
|
|
Packit |
1c1d7e |
* @param[in] exampleName Name of the example.
|
|
Packit |
1c1d7e |
* @param[in] fileDef File definition to which the code
|
|
Packit |
1c1d7e |
* is associated.
|
|
Packit |
1c1d7e |
* @param[in] startLine Starting line in case of a code fragment.
|
|
Packit |
1c1d7e |
* @param[in] endLine Ending line of the code fragment.
|
|
Packit |
1c1d7e |
* @param[in] inlineFragment Code fragment that is to be shown inline
|
|
Packit |
1c1d7e |
* as part of the documentation.
|
|
Packit |
1c1d7e |
* @param[in] memberDef Member definition to which the code
|
|
Packit |
1c1d7e |
* is associated (non null in case of an inline fragment
|
|
Packit |
1c1d7e |
* for a member).
|
|
Packit |
1c1d7e |
* @param[in] showLineNumbers if set to TRUE and also fileDef is not 0,
|
|
Packit |
1c1d7e |
* line numbers will be added to the source fragment
|
|
Packit |
1c1d7e |
* @param[in] searchCtx context under which search data has to be stored.
|
|
Packit |
1c1d7e |
* @param[in] collectXRefs collect cross-reference relations.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual void parseCode(CodeOutputInterface &codeOutIntf,
|
|
Packit |
1c1d7e |
const char *scopeName,
|
|
Packit |
1c1d7e |
const QCString &input,
|
|
Packit |
1c1d7e |
SrcLangExt lang,
|
|
Packit |
1c1d7e |
bool isExampleBlock,
|
|
Packit |
1c1d7e |
const char *exampleName=0,
|
|
Packit |
1c1d7e |
FileDef *fileDef=0,
|
|
Packit |
1c1d7e |
int startLine=-1,
|
|
Packit |
1c1d7e |
int endLine=-1,
|
|
Packit |
1c1d7e |
bool inlineFragment=FALSE,
|
|
Packit |
1c1d7e |
MemberDef *memberDef=0,
|
|
Packit |
1c1d7e |
bool showLineNumbers=TRUE,
|
|
Packit |
1c1d7e |
Definition *searchCtx=0,
|
|
Packit |
1c1d7e |
bool collectXRefs=TRUE
|
|
Packit |
1c1d7e |
) = 0;
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** Resets the state of the code parser.
|
|
Packit |
1c1d7e |
* Since multiple code fragments can together form a single example, an
|
|
Packit |
1c1d7e |
* explicit function is used to reset the code parser state.
|
|
Packit |
1c1d7e |
* @see parseCode()
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual void resetCodeParserState() = 0;
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** Callback function called by the comment block scanner.
|
|
Packit |
1c1d7e |
* It provides a string \a text containing the prototype of a function
|
|
Packit |
1c1d7e |
* or variable. The parser should parse this and store the information
|
|
Packit |
1c1d7e |
* in the Entry node that corresponds with the node for which the
|
|
Packit |
1c1d7e |
* comment block parser was invoked.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
virtual void parsePrototype(const char *text) = 0;
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
};
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
//-----------------------------------------------------------------------------
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** \brief Manages programming language parsers.
|
|
Packit |
1c1d7e |
*
|
|
Packit |
1c1d7e |
* This class manages the language parsers in the system. One can
|
|
Packit |
1c1d7e |
* register parsers, and obtain a parser given a file extension.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
class ParserManager
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
public:
|
|
Packit |
1c1d7e |
/** Creates the parser manager object.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
ParserManager()
|
|
Packit |
1c1d7e |
: m_defaultParser(0) { m_parsers.setAutoDelete(TRUE); }
|
|
Packit |
1c1d7e |
~ParserManager()
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
delete m_defaultParser;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
void registerDefaultParser(ParserInterface *parser)
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
m_defaultParser = parser;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** Registers an additional parser.
|
|
Packit |
1c1d7e |
* @param[in] name A symbolic name of the parser, i.e. "c",
|
|
Packit |
1c1d7e |
* "python", "fortran", "vhdl", ...
|
|
Packit |
1c1d7e |
* @param[in] parser The parser that is to be used for the
|
|
Packit |
1c1d7e |
* given name.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
void registerParser(const char *name,ParserInterface *parser)
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
m_parsers.insert(name,parser);
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** Registers a file \a extension with a parser with name \a parserName.
|
|
Packit |
1c1d7e |
* Returns TRUE if the extension was successfully registered.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
bool registerExtension(const char *extension, const char *parserName)
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
if (parserName==0 || extension==0) return FALSE;
|
|
Packit |
1c1d7e |
ParserInterface *intf = m_parsers.find(parserName);
|
|
Packit |
1c1d7e |
if (intf==0) return FALSE;
|
|
Packit |
1c1d7e |
if (m_extensions.find(extension)!=0) // extension already exists
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
m_extensions.remove(extension); // remove it
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
m_extensions.insert(extension,intf); // add new mapping
|
|
Packit |
1c1d7e |
return TRUE;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
/** Gets the interface to the parser associated with given \a extension.
|
|
Packit |
1c1d7e |
* If there is no parser explicitly registered for the supplied extension,
|
|
Packit |
1c1d7e |
* the interface to the default parser will be returned.
|
|
Packit |
1c1d7e |
*/
|
|
Packit |
1c1d7e |
ParserInterface *getParser(const char *extension)
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
QCString ext = QCString(extension).lower();
|
|
Packit |
1c1d7e |
if (ext.isEmpty()) ext=".no_extension";
|
|
Packit |
1c1d7e |
ParserInterface *intf = m_extensions.find(ext);
|
|
Packit |
1c1d7e |
if (intf==0 && ext.length()>4)
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
intf = m_extensions.find(ext.left(4));
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
return intf ? intf : m_defaultParser;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
private:
|
|
Packit |
1c1d7e |
QDict<ParserInterface> m_parsers;
|
|
Packit |
1c1d7e |
QDict<ParserInterface> m_extensions;
|
|
Packit |
1c1d7e |
ParserInterface *m_defaultParser;
|
|
Packit |
1c1d7e |
};
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#endif
|