Doxygen
Loading...
Searching...
No Matches
CodeFragmentManager Class Reference

#include <src/codefragment.h>

Classes

struct  Private

Public Member Functions

void parseCodeFragment (OutputCodeList &codeOutList, const QCString &fileName, const QCString &blockId, const QCString &scopeName, bool showLineNumbers, bool trimLeft, bool stripCodeComments)

Static Public Member Functions

static CodeFragmentManagerinstance ()

Private Member Functions

 CodeFragmentManager ()
 ~CodeFragmentManager ()

Private Attributes

std::unique_ptr< Privatep

Detailed Description

Definition at line 29 of file codefragment.h.

Constructor & Destructor Documentation

◆ CodeFragmentManager()

CodeFragmentManager::CodeFragmentManager ( )
private

Definition at line 183 of file codefragment.cpp.

183 : p(std::make_unique<Private>())
184{
185}
std::unique_ptr< Private > p

References p.

Referenced by instance(), and ~CodeFragmentManager().

◆ ~CodeFragmentManager()

CodeFragmentManager::~CodeFragmentManager ( )
privatedefault

References CodeFragmentManager().

Member Function Documentation

◆ instance()

◆ parseCodeFragment()

void CodeFragmentManager::parseCodeFragment ( OutputCodeList & codeOutList,
const QCString & fileName,
const QCString & blockId,
const QCString & scopeName,
bool showLineNumbers,
bool trimLeft,
bool stripCodeComments )

Definition at line 241 of file codefragment.cpp.

249{
250 AUTO_TRACE("CodeFragmentManager::parseCodeFragment({},blockId={},scopeName={},showLineNumber={},trimLeft={},stripCodeComments={}",
251 fileName, blockId, scopeName, showLineNumbers, trimLeft, stripCodeComments);
252 std::string fragmentKey=fileName.str()+":"+scopeName.str();
253 std::unordered_map< std::string,std::unique_ptr<Private::FragmentInfo> >::iterator it;
254 bool inserted = false;
255 {
256 // create new entry if it is not yet in the map
257 std::lock_guard lock(p->mutex);
258 it = p->fragments.find(fragmentKey);
259 if (it == p->fragments.end())
260 {
261 it = p->fragments.emplace(fragmentKey, std::make_unique<Private::FragmentInfo>()).first;
262 inserted = true;
263 AUTO_TRACE_ADD("new fragment");
264 }
265 }
266 // only lock the one item we are working with
267 auto &codeFragment = it->second;
268 std::lock_guard lock(codeFragment->mutex);
269 if (inserted) // new entry, need to parse the file and record the output and cache it
270 {
271 SrcLangExt langExt = getLanguageFromFileName(fileName);
272 FileInfo cfi( fileName.str() );
273 auto fd = createFileDef( cfi.dirPath(), cfi.fileName() );
275 intf->resetCodeParserState();
276 bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
277 bool needs2PassParsing =
278 Doxygen::parseSourcesNeeded && // we need to parse (filtered) sources for cross-references
279 !filterSourceFiles && // but user wants to show sources as-is
280 !getFileFilter(fileName,TRUE).isEmpty(); // and there is a filter used while parsing
281 codeFragment->fileContents = readTextFileByName(fileName);
282 //printf("fileContents=[%s]\n",qPrint(codeFragment->fileContents));
283 if (needs2PassParsing)
284 {
285 OutputCodeList devNullList;
286 devNullList.add<DevNullCodeGenerator>();
287 intf->parseCode(devNullList,
288 scopeName,
289 codeFragment->fileContents,
290 langExt,
291 stripCodeComments, // actually not important here
292 CodeParserOptions()
293 );
294 }
295 codeFragment->findBlockMarkers();
296 if (codeFragment->fileContents.length()>0) // parse the normal version
297 {
298 intf->parseCode(codeFragment->recorderCodeList,
299 scopeName,
300 codeFragment->fileContents,
301 langExt, // lang
302 false, // strip code comments (overruled before replaying)
303 CodeParserOptions()
304 .setFileDef(fd.get())
305 .setInlineFragment(true)
306 .setCollectXRefs(false)
307 );
308 }
309 }
310 // use the recorded OutputCodeList from the cache to output a pre-recorded fragment
311 auto blockKv = codeFragment->blocksById.find(blockId.str());
312 if (blockKv != codeFragment->blocksById.end())
313 {
314 const auto &marker = blockKv->second;
315 int startLine = marker->lines[0];
316 int endLine = marker->lines[1];
317 int indent = marker->indent;
318 AUTO_TRACE_ADD("replay(start={},end={},indent={}) fileContentsTrimLeft.empty()={}",
319 startLine,endLine,indent,codeFragment->fileContentsTrimLeft.isEmpty());
320 auto recorder = codeFragment->recorderCodeList.get<OutputCodeRecorder>(OutputType::Recorder);
321 recorder->replay(codeOutList,
322 startLine+1,
323 endLine,
324 showLineNumbers,
325 stripCodeComments,
326 trimLeft ? static_cast<size_t>(indent) : 0
327 );
328 }
329 else
330 {
331 AUTO_TRACE_ADD("block not found!");
332 }
333}
static bool parseSourcesNeeded
Definition doxygen.h:122
static ParserManager * parserManager
Definition doxygen.h:130
void add(OutputCodeIntfPtr &&p)
Definition outputlist.h:195
std::unique_ptr< CodeParserInterface > getCodeParser(const QCString &extension)
Gets the interface to the parser associated with a given extension.
Definition parserintf.h:254
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
const std::string & str() const
Definition qcstring.h:552
static QCString readTextFileByName(const QCString &file)
#define Config_getBool(name)
Definition config.h:33
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:48
#define AUTO_TRACE(...)
Definition docnode.cpp:47
std::unique_ptr< FileDef > createFileDef(const QCString &p, const QCString &n, const QCString &ref, const QCString &dn)
Definition filedef.cpp:269
#define TRUE
Definition qcstring.h:37
SrcLangExt
Definition types.h:207
SrcLangExt getLanguageFromFileName(const QCString &fileName, SrcLangExt defLang)
Definition util.cpp:5194
QCString getFileFilter(const QCString &name, bool isSourceCode)
Definition util.cpp:1402
QCString getFileNameExtension(const QCString &fn)
Definition util.cpp:5236

References OutputCodeList::add(), AUTO_TRACE, AUTO_TRACE_ADD, Config_getBool, createFileDef(), FileInfo::dirPath(), FileInfo::fileName(), getFileFilter(), getFileNameExtension(), getLanguageFromFileName(), QCString::isEmpty(), p, Doxygen::parserManager, Doxygen::parseSourcesNeeded, readTextFileByName(), Recorder, OutputCodeRecorder::replay(), CodeParserOptions::setCollectXRefs(), CodeParserOptions::setInlineFragment(), QCString::str(), and TRUE.

Referenced by DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), ManDocVisitor::operator()(), RTFDocVisitor::operator()(), and XmlDocVisitor::operator()().

Member Data Documentation

◆ p

std::unique_ptr<Private> CodeFragmentManager::p
private

Definition at line 47 of file codefragment.h.

Referenced by CodeFragmentManager(), and parseCodeFragment().


The documentation for this class was generated from the following files: