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 DString &comment, const DString &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 DString &fileName, int lineNr)
void leaveFile (const DString &fileName, int lineNr)
void enterCompound (const DString &fileName, int line, const DString &name)
void leaveCompound (const DString &fileName, int line, const DString &name)
void open (Entry *e, const DString &fileName, int line, bool implicit=false)
void close (Entry *e, const DString &fileName, int line, bool foundInline, bool implicit=false)
void addDeprecatedDocs (Entry *current, const DString &fileName, int line, OutlineParserInterface *parser)

Static Public Member Functions

static bool isCommand (const DString &cmdName)

Private Attributes

std::unique_ptr< Private > p

Detailed Description

Definition at line 53 of file commentscan.h.

Constructor & Destructor Documentation

◆ CommentScanner()

CommentScanner::CommentScanner ( )

Definition at line 5013 of file commentscan.l.

5013 : p(std::make_unique<Private>())
5014{
5015 commentscanYYlex_init_extra(&p->extra,&p->yyscanner);
5016#ifdef FLEX_DEBUG
5017 commentscanYYset_debug(Debug::isFlagSet(Debug::Lex_commentscan)?1:0,p->yyscanner);
5018#endif
5019}
std::unique_ptr< Private > p
@ Lex_commentscan
Definition debug.h:56
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132

References Debug::isFlagSet(), Debug::Lex_commentscan, and p.

◆ ~CommentScanner()

CommentScanner::~CommentScanner ( )

Definition at line 5021 of file commentscan.l.

5022{
5023 commentscanYYlex_destroy(p->yyscanner);
5024}

References p.

Member Function Documentation

◆ addDeprecatedDocs()

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

Definition at line 5255 of file commentscan.l.

5256{
5257 static reg::Ex deprecated_re(R"(deprecated\s*(\‍(\s*\"([^\"]*)\"\s*\))?)");
5258 reg::Match match;
5259 std::string attr = current->attributes.str();
5260 if (reg::search(attr,match,deprecated_re))
5261 {
5262 DString docs;
5263 if (match.size()==3) // deprecated attribute with documentation
5264 {
5265 Markdown markdown(fileName,line);
5266 DString rawDoc = match[2].str();
5267 DString processedDoc = Config_getBool(MARKDOWN_SUPPORT) ? markdown.process(rawDoc,line) : rawDoc;
5268 std::shared_ptr<Entry> docEntry = std::make_shared<Entry>();
5269 GuardedSectionStack guards;
5270 bool newEntryNeeded = false;
5271 Protection prot = Protection::Public;
5272 int position=0;
5273 parseCommentBlock(parser,
5274 docEntry.get(),
5275 processedDoc,
5276 fileName,
5277 line,
5278 false, // isBrief
5279 false, // isAutoBriefOn
5280 false, // isInbody
5281 prot,
5282 position,
5283 newEntryNeeded,
5284 Config_getBool(MARKDOWN_SUPPORT), // markdownSupport
5285 &guards);
5286 docs = docEntry->doc;
5287 //printf("rawDoc='%s' processedDoc='%s' docs='%s'\n",qPrint(rawDoc),qPrint(processedDoc),qPrint(docs));
5288 }
5289 else // deprecated attribute without documentation
5290 {
5291 current->spec.setDeprAttr(true);
5292 }
5293 if (!docs.empty() || !current->spec.isDeprDoc()) // attribute has docs
5294 // or no @deprecated command found in comment yet
5295 {
5296 // add new deprecated xref item to the documentation of this entry
5297 addXRefItemToEntry(current,
5298 docs,
5299 "deprecated",
5302 false, // append
5303 false, // inBody
5304 line);
5305 }
5306 }
5307 else
5308 {
5309 //printf("no match in attributes='%s'\n",qPrint(attr));
5310 }
5311}
bool parseCommentBlock(OutlineParserInterface *parser, Entry *curEntry, const DString &comment, const DString &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.
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
const std::string & str() const
Definition dstring.h:645
DString attributes
member's attributes (e.g. [[nodiscard]])
Definition entry.h:201
TypeSpecifier spec
class/member specifiers
Definition entry.h:189
virtual DString trDeprecatedList()=0
virtual DString trDeprecated()=0
std::stack< GuardedSection > GuardedSectionStack
Definition commentscan.h:48
static void addXRefItemToEntry(Entry *current, const DString &docs, const DString &baseName, const DString &itemTitle, const DString &listTitle, bool append, bool inBody, int lineNr)
#define Config_getBool(name)
Definition config.h:33
Translator * theTranslator
Definition language.cpp:76
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:850
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:861
Protection
Definition types.h:32

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

◆ close()

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

Definition at line 5244 of file commentscan.l.

5245{
5246 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5247 yyextra->docGroup.close(e,fileName,lineNr,foundInline,implicit);
5248}
#define yyguts_t
Definition code.l:23

References p, and yyguts_t.

◆ enterCompound()

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

Definition at line 5226 of file commentscan.l.

5227{
5228 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5229 yyextra->docGroup.enterCompound(fileName,lineNr,name);
5230}

References p, and yyguts_t.

◆ enterFile()

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

Definition at line 5214 of file commentscan.l.

5215{
5216 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5217 yyextra->docGroup.enterFile(fileName,lineNr);
5218}

References p, and yyguts_t.

Referenced by generateHtmlForComment().

◆ initGroupInfo()

void CommentScanner::initGroupInfo ( Entry * entry)

Definition at line 5208 of file commentscan.l.

5209{
5210 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5211 yyextra->docGroup.initGroupInfo(entry);
5212}

References p, and yyguts_t.

◆ isCommand()

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

Definition at line 5250 of file commentscan.l.

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

References docCmdMap, and DString::str().

Referenced by Markdown::Private::processLink().

◆ leaveCompound()

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

Definition at line 5232 of file commentscan.l.

5233{
5234 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5235 yyextra->docGroup.leaveCompound(fileName,lineNr,name);
5236}

References p, and yyguts_t.

◆ leaveFile()

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

Definition at line 5220 of file commentscan.l.

5221{
5222 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5223 yyextra->docGroup.leaveFile(fileName,lineNr);
5224}

References p, and yyguts_t.

Referenced by generateHtmlForComment().

◆ open()

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

Definition at line 5238 of file commentscan.l.

5239{
5240 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5241 yyextra->docGroup.open(e,fileName,lineNr,implicit);
5242}

References p, and yyguts_t.

◆ parseCommentBlock()

bool CommentScanner::parseCommentBlock ( OutlineParserInterface * parser,
Entry * curEntry,
const DString & comment,
const DString & 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 5026 of file commentscan.l.

5040{
5041 AUTO_TRACE("comment='{}' fileName={} lineNr={} isBrief={} isAutoBriefOn={} inInbody={}"
5042 " prot={} markdownSupport={}",Trace::trunc(comment),fileName,lineNr,isBrief,
5043 isAutoBriefOn,isInbody,prot,markdownSupport);
5044 yyscan_t yyscanner = p->yyscanner;
5045 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
5046
5047 initParser(yyscanner);
5048 yyextra->guards = guards;
5049 yyextra->langParser = parser;
5050 yyextra->current = curEntry;
5051 yyextra->current->docLine = (lineNr > 1 ? lineNr : 1);
5052 if (comment.empty()) return false; // avoid empty strings
5053 yyextra->inputString = comment;
5054 yyextra->inputString.append(" ");
5055 yyextra->inputPosition = position;
5056 yyextra->lineNr = lineNr;
5057 yyextra->fileName = fileName;
5058 yyextra->protection = prot;
5059 yyextra->needNewEntry = false;
5060 yyextra->xrefKind = XRef_None;
5061 yyextra->xrefAppendFlag = false;
5062 yyextra->insidePre = false;
5063 yyextra->parseMore = false;
5064 yyextra->inBody = isInbody;
5065 yyextra->markdownSupport= markdownSupport;
5066 yyextra->outputXRef.clear();
5067 if (!isBrief && !isAutoBriefOn && !yyextra->current->doc.empty())
5068 { // add newline separator between detailed comment blocks
5069 yyextra->current->doc += '\n';
5070 }
5071 setOutput(yyscanner, isBrief || isAutoBriefOn ? OutputBrief : OutputDoc );
5072 yyextra->briefEndsAtDot = isAutoBriefOn;
5073 yyextra->condCount = 0;
5074 yyextra->sectionLevel = 0;
5075 yyextra->spaceBeforeCmd.clear();
5076 yyextra->spaceBeforeIf.clear();
5077 yyextra->htmlContextStack.clear();
5078
5079 DebugLex debugLex(Debug::Lex_commentscan, __FILE__, !fileName.empty() ? qPrint(fileName): nullptr);
5080 if (!yyextra->current->inbodyDocs.empty() && isInbody) // separate in body fragments
5081 {
5082 char cmd[30];
5083 snprintf(cmd,30,"\n\n\\iline %d \\ilinebr ",lineNr);
5084 yyextra->current->inbodyDocs+=cmd;
5085 }
5086
5087 Debug::print(Debug::CommentScan,0,"-----------\nCommentScanner: {}:{}\n"
5088 "input=[\n{}]\n",fileName,lineNr,yyextra->inputString
5089 );
5090
5091 commentscanYYrestart( nullptr, yyscanner );
5092 BEGIN( Comment );
5093 commentscanYYlex(yyscanner);
5094 setOutput(yyscanner, OutputDoc );
5095
5096 if (YY_START==OverloadParam) // comment ended with \overload
5097 {
5099 }
5100
5101 if (yyextra->insideParBlock)
5102 {
5103 warn(yyextra->fileName,yyextra->lineNr,
5104 "Documentation block ended while inside a \\parblock. Missing \\endparblock");
5105 }
5106
5107 yyextra->current->doc=stripLeadingAndTrailingEmptyLines(yyextra->current->doc,yyextra->current->docLine);
5108 yyextra->current->brief=stripLeadingAndTrailingEmptyLines(yyextra->current->brief,yyextra->current->docLine);
5109
5110 if (yyextra->current->section.isFileDoc() && yyextra->current->doc.empty())
5111 {
5112 // to allow a comment block with just a @file command.
5113 yyextra->current->doc="\n\n";
5114 }
5115
5116 if (yyextra->current->section.isMemberGrp() &&
5117 yyextra->docGroup.empty()) // @name section but no group started yet
5118 {
5119 yyextra->docGroup.open(yyextra->current,yyextra->fileName,yyextra->lineNr,true);
5120 }
5121
5122 Debug::print(Debug::CommentScan,0,"-----------\nCommentScanner: {}:{}\noutput=[\n"
5123 "brief=[line={}\n{}]\ndocs=[line={}\n{}]\ninbody=[line={}\n{}]\n]\n===========\n",
5124 fileName,lineNr,
5125 yyextra->current->briefLine,yyextra->current->brief,
5126 yyextra->current->docLine,yyextra->current->doc,
5127 yyextra->current->inbodyLine,yyextra->current->inbodyDocs
5128 );
5129
5130 checkFormula(yyscanner);
5131 prot = yyextra->protection;
5132
5133 yyextra->docGroup.addDocs(curEntry);
5134
5135 newEntryNeeded = yyextra->needNewEntry;
5136
5137 // if we did not proceed during this call, it does not make
5138 // sense to continue, since we get stuck. See bug 567346 for situations
5139 // were this happens
5140 if (yyextra->parseMore && position==yyextra->inputPosition) yyextra->parseMore=false;
5141
5142 if (!yyextra->parseMore && !yyextra->guards->empty())
5143 {
5144 warn(yyextra->fileName,yyextra->lineNr,"Documentation block ended in the middle of a conditional section!");
5145 }
5146
5147 if (yyextra->parseMore) position=yyextra->inputPosition; else position=0;
5148
5149 lineNr = yyextra->lineNr;
5150 AUTO_TRACE_EXIT("position={} parseMore={} newEntryNeeded={}",
5151 position,yyextra->parseMore,newEntryNeeded);
5152
5153 return yyextra->parseMore;
5154}
void clear()
Definition dstring.h:214
DString & append(char c)
Definition dstring.h:489
@ CommentScan
Definition debug.h:33
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:78
int docLine
line number at which the documentation was found
Definition entry.h:210
virtual DString trOverloadText()=0
yyguts_t * yyscan_t
Definition code.l:25
@ 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:53
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:55
const char * qPrint(const char *s)
Definition dstring.h:783
#define warn(file, line, fmt,...)
Definition message.h:97
DString trunc(const DString &s, size_t numChars=15)
Definition trace.h:56
DString stripLeadingAndTrailingEmptyLines(const DString &s, int &docLine)
Special version of DString::stripWhiteSpace() that only strips completely blank lines.
Definition util.cpp:4119

References addOutput(), DString::append(), AUTO_TRACE, AUTO_TRACE_EXIT, checkFormula(), Debug::CommentScan, Entry::docLine, DString::empty(), initParser(), Debug::Lex_commentscan, OutputBrief, OutputDoc, p, Debug::print(), qPrint(), setOutput(), stripLeadingAndTrailingEmptyLines(), theTranslator, Translator::trOverloadText(), Trace::trunc(), warn, XRef_None, and yyguts_t.

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: