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

#include <src/commentscan.h>

Classes

struct  Private

Public Member Functions

 CommentScanner ()
 ~CommentScanner ()
bool parseCommentBlock (OutlineParserInterface *parser, Entry *curEntry, const QCString &comment, const QCString &fileName, int &lineNr, bool isBrief, bool isJavadocStyle, bool isInbody, Protection &prot, int &position, bool &newEntryNeeded, bool markdownEnabled, GuardedSectionStack *guards)
 Invokes the comment block parser with the request to parse a single comment block.
void initGroupInfo (Entry *entry)
void enterFile (const QCString &fileName, int lineNr)
void leaveFile (const QCString &fileName, int lineNr)
void enterCompound (const QCString &fileName, int line, const QCString &name)
void leaveCompound (const QCString &fileName, int line, const QCString &name)
void open (Entry *e, const QCString &fileName, int line, bool implicit=false)
void close (Entry *e, const QCString &fileName, int line, bool foundInline, bool implicit=false)
void addDeprecatedDocs (Entry *current, const QCString &fileName, int line, OutlineParserInterface *parser)

Static Public Member Functions

static bool isCommand (const QCString &cmdName)

Private Attributes

std::unique_ptr< Privatep

Detailed Description

Definition at line 53 of file commentscan.h.

Constructor & Destructor Documentation

◆ CommentScanner()

CommentScanner::CommentScanner ( )

Definition at line 4965 of file commentscan.l.

4965 : p(std::make_unique<Private>())
4966{
4967 commentscanYYlex_init_extra(&p->extra,&p->yyscanner);
4968#ifdef FLEX_DEBUG
4969 commentscanYYset_debug(Debug::isFlagSet(Debug::Lex_commentscan)?1:0,p->yyscanner);
4970#endif
4971}
std::unique_ptr< Private > p
@ Lex_commentscan
Definition debug.h:55

References Debug::Lex_commentscan, and p.

◆ ~CommentScanner()

CommentScanner::~CommentScanner ( )

Definition at line 4973 of file commentscan.l.

4974{
4975 commentscanYYlex_destroy(p->yyscanner);
4976}

References p.

Member Function Documentation

◆ addDeprecatedDocs()

void CommentScanner::addDeprecatedDocs ( Entry * current,
const QCString & fileName,
int line,
OutlineParserInterface * parser )

Definition at line 5207 of file commentscan.l.

5208{
5209 static reg::Ex deprecated_re(R"(deprecated\s*(\‍(\s*\"([^\"]*)\"\s*\))?)");
5210 reg::Match match;
5211 std::string attr = current->attributes.str();
5212 if (reg::search(attr,match,deprecated_re))
5213 {
5214 QCString docs;
5215 if (match.size()==3) // deprecated attribute with documentation
5216 {
5217 Markdown markdown(fileName,line);
5218 QCString rawDoc = match[2].str();
5219 QCString processedDoc = Config_getBool(MARKDOWN_SUPPORT) ? markdown.process(rawDoc,line) : rawDoc;
5220 std::shared_ptr<Entry> docEntry = std::make_shared<Entry>();
5221 GuardedSectionStack guards;
5222 bool newEntryNeeded = false;
5223 Protection prot = Protection::Public;
5224 int position=0;
5225 parseCommentBlock(parser,
5226 docEntry.get(),
5227 processedDoc,
5228 fileName,
5229 line,
5230 false, // isBrief
5231 false, // isAutoBriefOn
5232 false, // isInbody
5233 prot,
5234 position,
5235 newEntryNeeded,
5236 Config_getBool(MARKDOWN_SUPPORT), // markdownSupport
5237 &guards);
5238 docs = docEntry->doc;
5239 //printf("rawDoc='%s' processedDoc='%s' docs='%s'\n",qPrint(rawDoc),qPrint(processedDoc),qPrint(docs));
5240 }
5241 else // deprecated attribute without documentation
5242 {
5243 current->spec.setDeprAttr(true);
5244 }
5245 if (!docs.isEmpty() || !current->spec.isDeprDoc()) // attribute has docs
5246 // or no @deprecated command found in comment yet
5247 {
5248 // add new deprecated xref item to the documentation of this entry
5249 addXRefItemToEntry(current,
5250 docs,
5251 "deprecated",
5254 false, // append
5255 false, // inBody
5256 line);
5257 }
5258 }
5259 else
5260 {
5261 //printf("no match in attributes='%s'\n",qPrint(attr));
5262 }
5263}
bool parseCommentBlock(OutlineParserInterface *parser, Entry *curEntry, const QCString &comment, const QCString &fileName, int &lineNr, bool isBrief, bool isJavadocStyle, bool isInbody, Protection &prot, int &position, bool &newEntryNeeded, bool markdownEnabled, GuardedSectionStack *guards)
Invokes the comment block parser with the request to parse a single comment block.
QCString attributes
member's attributes (e.g. [[nodiscard]])
Definition entry.h:195
TypeSpecifier spec
class/member specifiers
Definition entry.h:183
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:167
const std::string & str() const
Definition qcstring.h:556
virtual QCString trDeprecatedList()=0
virtual QCString trDeprecated()=0
std::stack< GuardedSection > GuardedSectionStack
Definition commentscan.h:48
static void addXRefItemToEntry(Entry *current, const QCString &docs, const QCString &listName, const QCString &itemTitle, const QCString &listTitle, bool append, bool inBody, int lineNr)
#define Config_getBool(name)
Definition config.h:33
Translator * theTranslator
Definition language.cpp:71
bool search(std::string_view str, Match &match, const Ex &re, size_t pos)
Search in a given string str starting at position pos for a match against regular expression re.
Definition regex.cpp:847
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:858
Protection
Definition types.h:32

References addXRefItemToEntry(), Entry::attributes, Config_getBool, QCString::isEmpty(), parseCommentBlock(), Markdown::process(), reg::search(), Entry::spec, QCString::str(), theTranslator, Translator::trDeprecated(), and Translator::trDeprecatedList().

◆ close()

void CommentScanner::close ( Entry * e,
const QCString & fileName,
int line,
bool foundInline,
bool implicit = false )

Definition at line 5196 of file commentscan.l.

5197{
5198 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5199 yyextra->docGroup.close(e,fileName,lineNr,foundInline,implicit);
5200}

References p.

◆ enterCompound()

void CommentScanner::enterCompound ( const QCString & fileName,
int line,
const QCString & name )

Definition at line 5178 of file commentscan.l.

5179{
5180 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5181 yyextra->docGroup.enterCompound(fileName,lineNr,name);
5182}

References p.

◆ enterFile()

void CommentScanner::enterFile ( const QCString & fileName,
int lineNr )

Definition at line 5166 of file commentscan.l.

5167{
5168 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5169 yyextra->docGroup.enterFile(fileName,lineNr);
5170}

References p.

Referenced by generateHtmlForComment().

◆ initGroupInfo()

void CommentScanner::initGroupInfo ( Entry * entry)

Definition at line 5160 of file commentscan.l.

5161{
5162 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5163 yyextra->docGroup.initGroupInfo(entry);
5164}

References p.

◆ isCommand()

bool CommentScanner::isCommand ( const QCString & cmdName)
static

Definition at line 5202 of file commentscan.l.

5203{
5204 return (docCmdMap.find(cmdName.str()) != docCmdMap.end());
5205}
static const std::unordered_map< std::string, DocCmdMap > docCmdMap

References docCmdMap, isCommand(), and QCString::str().

Referenced by isCommand().

◆ leaveCompound()

void CommentScanner::leaveCompound ( const QCString & fileName,
int line,
const QCString & name )

Definition at line 5184 of file commentscan.l.

5185{
5186 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5187 yyextra->docGroup.leaveCompound(fileName,lineNr,name);
5188}

References p.

◆ leaveFile()

void CommentScanner::leaveFile ( const QCString & fileName,
int lineNr )

Definition at line 5172 of file commentscan.l.

5173{
5174 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5175 yyextra->docGroup.leaveFile(fileName,lineNr);
5176}

References p.

Referenced by generateHtmlForComment().

◆ open()

void CommentScanner::open ( Entry * e,
const QCString & fileName,
int line,
bool implicit = false )

Definition at line 5190 of file commentscan.l.

5191{
5192 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5193 yyextra->docGroup.open(e,fileName,lineNr,implicit);
5194}

References p.

◆ parseCommentBlock()

bool CommentScanner::parseCommentBlock ( OutlineParserInterface * parser,
Entry * curEntry,
const QCString & comment,
const QCString & fileName,
int & lineNr,
bool isBrief,
bool isJavadocStyle,
bool isInbody,
Protection & prot,
int & position,
bool & newEntryNeeded,
bool markdownEnabled,
GuardedSectionStack * guards )

Invokes the comment block parser with the request to parse a single comment block.

Parameters
[in]parserThe language parse that invoked this function. The comment block parse may invoke ParserInterface::parsePrototype() in order to parse the argument of a @fn command.
[in]curEntryThe Entry to which the comment block belongs. Any information (like documentation) that is found in the comment block will be stored in this entry.
[in]commentA string representing the actual comment block. Note that leading *'s are already stripped from the comment block.
[in]fileNameThe name of the file in which the comment is found. Mainly used for producing warnings.
[in,out]lineNrThe line number at which the comment block was found. When the function returns it will be set to the last line parsed.
[in]isBriefTRUE iff this comment block represents a brief description.
[in]isJavadocStyleTRUE iff this comment block is in "Javadoc" style. This means that it starts as a brief description until the end of the sentences is found and then proceeds as a detailed description.
[in]isInbodyTRUE iff this comment block is located in the body of a function.
[in,out]protThe protection level in which this comment block was found. Commands in the comment block may override this.
[in,out]positionThe character position within comment where the comment block starts. Typically used in case the comment block contains multiple structural commands.
[out]newEntryNeededBoolean that is TRUE if the comment block parser finds that a the comment block finishes the entry and a new one needs to be started.
[in]markdownEnabledIndicates if markdown specific processing should be done.
[in,out]guardsTracks nested conditional sections (if,ifnot,..)
Returns
TRUE if the comment requires further processing. The parameter newEntryNeeded will typically be true in this case and position will indicate the offset inside the comment string where to proceed parsing. FALSE indicates no further processing is needed.

Definition at line 4978 of file commentscan.l.

4992{
4993 AUTO_TRACE("comment='{}' fileName={} lineNr={} isBrief={} isAutoBriefOn={} inInbody={}"
4994 " prot={} markdownSupport={}",Trace::trunc(comment),fileName,lineNr,isBrief,
4995 isAutoBriefOn,isInbody,prot,markdownSupport);
4996 yyscan_t yyscanner = p->yyscanner;
4997 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
4998
4999 initParser(yyscanner);
5000 yyextra->guards = guards;
5001 yyextra->langParser = parser;
5002 yyextra->current = curEntry;
5003 yyextra->current->docLine = (lineNr > 1 ? lineNr : 1);
5004 if (comment.isEmpty()) return FALSE; // avoid empty strings
5005 yyextra->inputString = comment;
5006 yyextra->inputString.append(" ");
5007 yyextra->inputPosition = position;
5008 yyextra->lineNr = lineNr;
5009 yyextra->fileName = fileName;
5010 yyextra->protection = prot;
5011 yyextra->needNewEntry = FALSE;
5012 yyextra->xrefKind = XRef_None;
5013 yyextra->xrefAppendFlag = FALSE;
5014 yyextra->insidePre = FALSE;
5015 yyextra->parseMore = FALSE;
5016 yyextra->inBody = isInbody;
5017 yyextra->markdownSupport= markdownSupport;
5018 yyextra->outputXRef.clear();
5019 if (!isBrief && !isAutoBriefOn && !yyextra->current->doc.isEmpty())
5020 { // add newline separator between detailed comment blocks
5021 yyextra->current->doc += '\n';
5022 }
5023 setOutput(yyscanner, isBrief || isAutoBriefOn ? OutputBrief : OutputDoc );
5024 yyextra->briefEndsAtDot = isAutoBriefOn;
5025 yyextra->condCount = 0;
5026 yyextra->sectionLevel = 0;
5027 yyextra->spaceBeforeCmd.clear();
5028 yyextra->spaceBeforeIf.clear();
5029 yyextra->htmlContextStack.clear();
5030
5031 DebugLex debugLex(Debug::Lex_commentscan, __FILE__, !fileName.isEmpty() ? qPrint(fileName): nullptr);
5032 if (!yyextra->current->inbodyDocs.isEmpty() && isInbody) // separate in body fragments
5033 {
5034 char cmd[30];
5035 qsnprintf(cmd,30,"\n\n\\iline %d \\ilinebr ",lineNr);
5036 yyextra->current->inbodyDocs+=cmd;
5037 }
5038
5039 Debug::print(Debug::CommentScan,0,"-----------\nCommentScanner: {}:{}\n"
5040 "input=[\n{}]\n",fileName,lineNr,yyextra->inputString
5041 );
5042
5043 commentscanYYrestart( nullptr, yyscanner );
5044 BEGIN( Comment );
5045 commentscanYYlex(yyscanner);
5046 setOutput(yyscanner, OutputDoc );
5047
5048 if (YY_START==OverloadParam) // comment ended with \overload
5049 {
5050 addOutput(yyscanner,getOverloadDocs());
5051 }
5052
5053 if (yyextra->insideParBlock)
5054 {
5055 warn(yyextra->fileName,yyextra->lineNr,
5056 "Documentation block ended while inside a \\parblock. Missing \\endparblock");
5057 }
5058
5059 yyextra->current->doc=stripLeadingAndTrailingEmptyLines(yyextra->current->doc,yyextra->current->docLine);
5060 yyextra->current->brief=stripLeadingAndTrailingEmptyLines(yyextra->current->brief,yyextra->current->docLine);
5061
5062 if (yyextra->current->section.isFileDoc() && yyextra->current->doc.isEmpty())
5063 {
5064 // to allow a comment block with just a @file command.
5065 yyextra->current->doc="\n\n";
5066 }
5067
5068 if (yyextra->current->section.isMemberGrp() &&
5069 yyextra->docGroup.isEmpty()) // @name section but no group started yet
5070 {
5071 yyextra->docGroup.open(yyextra->current,yyextra->fileName,yyextra->lineNr,true);
5072 }
5073
5074 Debug::print(Debug::CommentScan,0,"-----------\nCommentScanner: {}:{}\noutput=[\n"
5075 "brief=[line={}\n{}]\ndocs=[line={}\n{}]\ninbody=[line={}\n{}]\n]\n===========\n",
5076 fileName,lineNr,
5077 yyextra->current->briefLine,yyextra->current->brief,
5078 yyextra->current->docLine,yyextra->current->doc,
5079 yyextra->current->inbodyLine,yyextra->current->inbodyDocs
5080 );
5081
5082 checkFormula(yyscanner);
5083 prot = yyextra->protection;
5084
5085 yyextra->docGroup.addDocs(curEntry);
5086
5087 newEntryNeeded = yyextra->needNewEntry;
5088
5089 // if we did not proceed during this call, it does not make
5090 // sense to continue, since we get stuck. See bug 567346 for situations
5091 // were this happens
5092 if (yyextra->parseMore && position==yyextra->inputPosition) yyextra->parseMore=FALSE;
5093
5094 if (!yyextra->parseMore && !yyextra->guards->empty())
5095 {
5096 warn(yyextra->fileName,yyextra->lineNr,"Documentation block ended in the middle of a conditional section!");
5097 }
5098
5099 if (yyextra->parseMore) position=yyextra->inputPosition; else position=0;
5100
5101 lineNr = yyextra->lineNr;
5102 AUTO_TRACE_EXIT("position={} parseMore={} newEntryNeeded={}",
5103 position,yyextra->parseMore,newEntryNeeded);
5104
5105 return yyextra->parseMore;
5106}
@ CommentScan
Definition debug.h:32
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:77
int docLine
line number at which the documentation was found
Definition entry.h:203
QCString & append(char c)
Definition qcstring.h:400
void clear()
Definition qcstring.h:186
yyguts_t * yyscan_t
Definition code.l:24
@ XRef_None
static void setOutput(yyscan_t yyscanner, OutputContext ctx)
static void initParser(yyscan_t yyscanner)
static void addOutput(yyscan_t yyscanner, const char *s)
@ OutputDoc
@ OutputBrief
static void checkFormula(yyscan_t yyscanner)
#define AUTO_TRACE(...)
Definition docnode.cpp:48
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:50
#define warn(file, line, fmt,...)
Definition message.h:97
QCString trunc(const QCString &s, size_t numChars=15)
Definition trace.h:56
#define qsnprintf
Definition qcstring.h:49
const char * qPrint(const char *s)
Definition qcstring.h:691
#define FALSE
Definition qcstring.h:34
QCString stripLeadingAndTrailingEmptyLines(const QCString &s, int &docLine)
Special version of QCString::stripWhiteSpace() that only strips completely blank lines.
Definition util.cpp:5072
QCString getOverloadDocs()
Definition util.cpp:4132

References addOutput(), QCString::append(), AUTO_TRACE, AUTO_TRACE_EXIT, checkFormula(), Debug::CommentScan, Entry::docLine, FALSE, getOverloadDocs(), initParser(), QCString::isEmpty(), Debug::Lex_commentscan, OutputBrief, OutputDoc, p, qPrint(), qsnprintf, setOutput(), stripLeadingAndTrailingEmptyLines(), Trace::trunc(), warn, and XRef_None.

Referenced by addDeprecatedDocs(), generateHtmlForComment(), and CitationManager::generatePage().

Member Data Documentation

◆ p

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

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