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 181 of file codefragment.cpp.

181 : p(std::make_unique<Private>())
182{
183}
std::unique_ptr< Private > 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 236 of file codefragment.cpp.

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

References OutputCodeList::add(), AUTO_TRACE, AUTO_TRACE_ADD, Config_getBool, createFileDef(), FileInfo::dirPath(), FileInfo::fileName(), ParserManager::getCodeParser(), getFileFilter(), getFileNameExtension(), getLanguageFromFileName(), QCString::isEmpty(), p, Doxygen::parserManager, Doxygen::parseSourcesNeeded, readTextFileByName(), Recorder, 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 parseCodeFragment().


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