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< Privatep

Detailed Description

Definition at line 53 of file commentscan.h.

Constructor & Destructor Documentation

◆ CommentScanner()

CommentScanner::CommentScanner ( )

Definition at line 4969 of file commentscan.l.

4969 : p(std::make_unique<Private>())
4970{
4971 commentscanYYlex_init_extra(&p->extra,&p->yyscanner);
4972#ifdef FLEX_DEBUG
4973 commentscanYYset_debug(Debug::isFlagSet(Debug::Lex_commentscan)?1:0,p->yyscanner);
4974#endif
4975}
std::unique_ptr< Private > p
@ Lex_commentscan
Definition debug.h:55
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:133

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

◆ ~CommentScanner()

CommentScanner::~CommentScanner ( )

Definition at line 4977 of file commentscan.l.

4978{
4979 commentscanYYlex_destroy(p->yyscanner);
4980}

References p.

Member Function Documentation

◆ addDeprecatedDocs()

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

Definition at line 5211 of file commentscan.l.

5212{
5213 static reg::Ex deprecated_re(R"(deprecated\s*(\‍(\s*\"([^\"]*)\"\s*\))?)");
5214 reg::Match match;
5215 std::string attr = current->attributes.str();
5216 if (reg::search(attr,match,deprecated_re))
5217 {
5218 DString docs;
5219 if (match.size()==3) // deprecated attribute with documentation
5220 {
5221 Markdown markdown(fileName,line);
5222 DString rawDoc = match[2].str();
5223 DString processedDoc = Config_getBool(MARKDOWN_SUPPORT) ? markdown.process(rawDoc,line) : rawDoc;
5224 std::shared_ptr<Entry> docEntry = std::make_shared<Entry>();
5225 GuardedSectionStack guards;
5226 bool newEntryNeeded = false;
5227 Protection prot = Protection::Public;
5228 int position=0;
5229 parseCommentBlock(parser,
5230 docEntry.get(),
5231 processedDoc,
5232 fileName,
5233 line,
5234 false, // isBrief
5235 false, // isAutoBriefOn
5236 false, // isInbody
5237 prot,
5238 position,
5239 newEntryNeeded,
5240 Config_getBool(MARKDOWN_SUPPORT), // markdownSupport
5241 &guards);
5242 docs = docEntry->doc;
5243 //printf("rawDoc='%s' processedDoc='%s' docs='%s'\n",qPrint(rawDoc),qPrint(processedDoc),qPrint(docs));
5244 }
5245 else // deprecated attribute without documentation
5246 {
5247 current->spec.setDeprAttr(true);
5248 }
5249 if (!docs.empty() || !current->spec.isDeprDoc()) // attribute has docs
5250 // or no @deprecated command found in comment yet
5251 {
5252 // add new deprecated xref item to the documentation of this entry
5253 addXRefItemToEntry(current,
5254 docs,
5255 "deprecated",
5258 false, // append
5259 false, // inBody
5260 line);
5261 }
5262 }
5263 else
5264 {
5265 //printf("no match in attributes='%s'\n",qPrint(attr));
5266 }
5267}
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:153
const std::string & str() const
Definition dstring.h:634
DString attributes
member's attributes (e.g. [[nodiscard]])
Definition entry.h:195
TypeSpecifier spec
class/member specifiers
Definition entry.h:183
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 &listName, 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: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, 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 5200 of file commentscan.l.

5201{
5202 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5203 yyextra->docGroup.close(e,fileName,lineNr,foundInline,implicit);
5204}

References p.

◆ enterCompound()

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

Definition at line 5182 of file commentscan.l.

5183{
5184 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5185 yyextra->docGroup.enterCompound(fileName,lineNr,name);
5186}

References p.

◆ enterFile()

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

Definition at line 5170 of file commentscan.l.

5171{
5172 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5173 yyextra->docGroup.enterFile(fileName,lineNr);
5174}

References p.

Referenced by generateHtmlForComment().

◆ initGroupInfo()

void CommentScanner::initGroupInfo ( Entry * entry)

Definition at line 5164 of file commentscan.l.

5165{
5166 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5167 yyextra->docGroup.initGroupInfo(entry);
5168}

References p.

◆ isCommand()

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

Definition at line 5206 of file commentscan.l.

5207{
5208 return (docCmdMap.find(cmdName.str()) != docCmdMap.end());
5209}
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 5188 of file commentscan.l.

5189{
5190 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5191 yyextra->docGroup.leaveCompound(fileName,lineNr,name);
5192}

References p.

◆ leaveFile()

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

Definition at line 5176 of file commentscan.l.

5177{
5178 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5179 yyextra->docGroup.leaveFile(fileName,lineNr);
5180}

References p.

Referenced by generateHtmlForComment().

◆ open()

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

Definition at line 5194 of file commentscan.l.

5195{
5196 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
5197 yyextra->docGroup.open(e,fileName,lineNr,implicit);
5198}

References p.

◆ 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 4982 of file commentscan.l.

4996{
4997 AUTO_TRACE("comment='{}' fileName={} lineNr={} isBrief={} isAutoBriefOn={} inInbody={}"
4998 " prot={} markdownSupport={}",Trace::trunc(comment),fileName,lineNr,isBrief,
4999 isAutoBriefOn,isInbody,prot,markdownSupport);
5000 yyscan_t yyscanner = p->yyscanner;
5001 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
5002
5003 initParser(yyscanner);
5004 yyextra->guards = guards;
5005 yyextra->langParser = parser;
5006 yyextra->current = curEntry;
5007 yyextra->current->docLine = (lineNr > 1 ? lineNr : 1);
5008 if (comment.empty()) return false; // avoid empty strings
5009 yyextra->inputString = comment;
5010 yyextra->inputString.append(" ");
5011 yyextra->inputPosition = position;
5012 yyextra->lineNr = lineNr;
5013 yyextra->fileName = fileName;
5014 yyextra->protection = prot;
5015 yyextra->needNewEntry = false;
5016 yyextra->xrefKind = XRef_None;
5017 yyextra->xrefAppendFlag = false;
5018 yyextra->insidePre = false;
5019 yyextra->parseMore = false;
5020 yyextra->inBody = isInbody;
5021 yyextra->markdownSupport= markdownSupport;
5022 yyextra->outputXRef.clear();
5023 if (!isBrief && !isAutoBriefOn && !yyextra->current->doc.empty())
5024 { // add newline separator between detailed comment blocks
5025 yyextra->current->doc += '\n';
5026 }
5027 setOutput(yyscanner, isBrief || isAutoBriefOn ? OutputBrief : OutputDoc );
5028 yyextra->briefEndsAtDot = isAutoBriefOn;
5029 yyextra->condCount = 0;
5030 yyextra->sectionLevel = 0;
5031 yyextra->spaceBeforeCmd.clear();
5032 yyextra->spaceBeforeIf.clear();
5033 yyextra->htmlContextStack.clear();
5034
5035 DebugLex debugLex(Debug::Lex_commentscan, __FILE__, !fileName.empty() ? qPrint(fileName): nullptr);
5036 if (!yyextra->current->inbodyDocs.empty() && isInbody) // separate in body fragments
5037 {
5038 char cmd[30];
5039 snprintf(cmd,30,"\n\n\\iline %d \\ilinebr ",lineNr);
5040 yyextra->current->inbodyDocs+=cmd;
5041 }
5042
5043 Debug::print(Debug::CommentScan,0,"-----------\nCommentScanner: {}:{}\n"
5044 "input=[\n{}]\n",fileName,lineNr,yyextra->inputString
5045 );
5046
5047 commentscanYYrestart( nullptr, yyscanner );
5048 BEGIN( Comment );
5049 commentscanYYlex(yyscanner);
5050 setOutput(yyscanner, OutputDoc );
5051
5052 if (YY_START==OverloadParam) // comment ended with \overload
5053 {
5055 }
5056
5057 if (yyextra->insideParBlock)
5058 {
5059 warn(yyextra->fileName,yyextra->lineNr,
5060 "Documentation block ended while inside a \\parblock. Missing \\endparblock");
5061 }
5062
5063 yyextra->current->doc=stripLeadingAndTrailingEmptyLines(yyextra->current->doc,yyextra->current->docLine);
5064 yyextra->current->brief=stripLeadingAndTrailingEmptyLines(yyextra->current->brief,yyextra->current->docLine);
5065
5066 if (yyextra->current->section.isFileDoc() && yyextra->current->doc.empty())
5067 {
5068 // to allow a comment block with just a @file command.
5069 yyextra->current->doc="\n\n";
5070 }
5071
5072 if (yyextra->current->section.isMemberGrp() &&
5073 yyextra->docGroup.empty()) // @name section but no group started yet
5074 {
5075 yyextra->docGroup.open(yyextra->current,yyextra->fileName,yyextra->lineNr,true);
5076 }
5077
5078 Debug::print(Debug::CommentScan,0,"-----------\nCommentScanner: {}:{}\noutput=[\n"
5079 "brief=[line={}\n{}]\ndocs=[line={}\n{}]\ninbody=[line={}\n{}]\n]\n===========\n",
5080 fileName,lineNr,
5081 yyextra->current->briefLine,yyextra->current->brief,
5082 yyextra->current->docLine,yyextra->current->doc,
5083 yyextra->current->inbodyLine,yyextra->current->inbodyDocs
5084 );
5085
5086 checkFormula(yyscanner);
5087 prot = yyextra->protection;
5088
5089 yyextra->docGroup.addDocs(curEntry);
5090
5091 newEntryNeeded = yyextra->needNewEntry;
5092
5093 // if we did not proceed during this call, it does not make
5094 // sense to continue, since we get stuck. See bug 567346 for situations
5095 // were this happens
5096 if (yyextra->parseMore && position==yyextra->inputPosition) yyextra->parseMore=false;
5097
5098 if (!yyextra->parseMore && !yyextra->guards->empty())
5099 {
5100 warn(yyextra->fileName,yyextra->lineNr,"Documentation block ended in the middle of a conditional section!");
5101 }
5102
5103 if (yyextra->parseMore) position=yyextra->inputPosition; else position=0;
5104
5105 lineNr = yyextra->lineNr;
5106 AUTO_TRACE_EXIT("position={} parseMore={} newEntryNeeded={}",
5107 position,yyextra->parseMore,newEntryNeeded);
5108
5109 return yyextra->parseMore;
5110}
void clear()
Definition dstring.h:219
DString & append(char c)
Definition dstring.h:478
@ 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
virtual DString trOverloadText()=0
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:50
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:52
const char * qPrint(const char *s)
Definition dstring.h:772
#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:4355

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, 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: