Doxygen
Loading...
Searching...
No Matches
commentcnv.h File Reference

First pass comment processing. More...

#include <src/commentcnv.h>

Include dependency graph for commentcnv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void convertCppComments (const std::string &inBuf, std::string &outBuf, const std::string &fn)
 Converts the comments in a file.

Detailed Description

First pass comment processing.

Definition in file commentcnv.h.

Function Documentation

◆ convertCppComments()

void convertCppComments ( const std::string & inBuf,
std::string & outBuf,
const std::string & fn )

Converts the comments in a file.

Parameters
inBufinput buffer holding the file content.
outBufoutput buffer to which the results after conversion are written to.
fnthe name of the file from which the comments originate.

The following is converted:

  • C++ style multiline doxygen comments are converted to C style doxygen comments.
  • conditional sections are processed.
  • aliases are expanded.

This function does three things:

  1. It converts multi-line C++ style comment blocks (that are aligned) to C style comment blocks (if MULTILINE_CPP_IS_BRIEF is set to NO).
  2. It replaces aliases with their definition (see ALIASES)
  3. It handles conditional sections (cond...endcond blocks)

Definition at line 2260 of file commentcnv.l.

2261{
2262 DString fileName { fn };
2263 yyscan_t yyscanner;
2264 commentcnvYY_state extra(&inBuf,outBuf);
2265 commentcnvYYlex_init_extra(&extra,&yyscanner);
2266#ifdef FLEX_DEBUG
2267 commentcnvYYset_debug(Debug::isFlagSet(Debug::Lex_commentcnv)?1:0,yyscanner);
2268#endif
2269 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2270 //printf("convertCppComments(%s)\n",qPrint(fileName));
2271 yyextra->inBufPos = 0;
2272 yyextra->col = 0;
2273 yyextra->mlBrief = Config_getBool(MULTILINE_CPP_IS_BRIEF);
2274 yyextra->skip = false;
2275 yyextra->fileName = fileName;
2276 yyextra->lang = getLanguageFromFileName(fileName);
2277 yyextra->pythonDocString = false;
2278 yyextra->lineNr = 1;
2279 yyextra->raiseLevel = 0;
2280 yyextra->raiseLabel = "";
2281 yyextra->raiseIncrement = 0;
2282 yyextra->raisePrefix = "";
2283 yyextra->insertCppCommentMarker=false;
2284 yyextra->expandedAliases.clear();
2285 yyextra->replacements.clear();
2286 while (!yyextra->condStack.empty()) yyextra->condStack.pop();
2287 clearCommentStack(yyscanner);
2288 yyextra->vhdl = false;
2289
2290 DebugLex debugLex(Debug::Lex_commentcnv,__FILE__, qPrint(fileName));
2291 yyextra->isFixedForm = false;
2292 if (yyextra->lang==SrcLangExt::Fortran)
2293 {
2295 yyextra->isFixedForm = recognizeFixedForm(inBuf,fmt);
2296 }
2297
2298 if (yyextra->lang==SrcLangExt::Markdown)
2299 {
2300 yyextra->nestingCount=0;
2301 BEGIN(CComment);
2302 yyextra->commentStack.push(yyextra->lineNr);
2303 }
2304 else
2305 {
2306 BEGIN(Scan);
2307 }
2308 yylex(yyscanner);
2309 while (!yyextra->condStack.empty())
2310 {
2311 const commentcnvYY_CondCtx &ctx = yyextra->condStack.top();
2312 DString sectionInfo(" ");
2313 if (ctx.sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",ctx.sectionId.stripWhiteSpace().data());
2314 warn(yyextra->fileName,ctx.lineNr,"Conditional section{}does not have "
2315 "a corresponding \\endcond command within this file.",sectionInfo.data());
2316 yyextra->condStack.pop();
2317 }
2318 if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt::Markdown && yyextra->lang!=SrcLangExt::Fortran)
2319 {
2320 DString lines;
2321 bool first = true;
2322 while (!yyextra->commentStack.empty())
2323 {
2324 int lineNr = yyextra->commentStack.top();
2325 if (!first) lines += ", ";
2326 lines += DString().setNum(lineNr);
2327 first = false;
2328 yyextra->commentStack.pop();
2329 }
2330 warn(yyextra->fileName,yyextra->lineNr,"Reached end of file while still inside a (nested) comment. "
2331 "Nesting level {} (possible line reference(s): {})",yyextra->nestingCount,lines);
2332 }
2333 yyextra->nestingCount = 0;
2335 {
2336 Debug::print(Debug::CommentCnv,0,"-----------\nCommentCnv: {}\n"
2337 "output=[\n{}]\n-----------\n",fileName,yyextra->outBuf
2338 );
2339 }
2340 commentcnvYYlex_destroy(yyscanner);
2341}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
DString & setNum(short n)
Definition dstring.h:552
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:337
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
@ Lex_commentcnv
Definition debug.h:55
@ CommentCnv
Definition debug.h:32
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:78
yyguts_t * yyscan_t
Definition code.l:24
static void clearCommentStack(yyscan_t yyscanner)
#define Config_getBool(name)
Definition config.h:33
int yylex(void)
const char * qPrint(const char *s)
Definition dstring.h:783
bool recognizeFixedForm(const DString &contents, FortranFormat format)
FortranFormat convertFileNameFortranParserCode(const DString &fn)
#define warn(file, line, fmt,...)
Definition message.h:97
Definition message.h:146
FortranFormat
Definition types.h:612
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
Definition util.cpp:4177

References clearCommentStack(), Debug::CommentCnv, Config_getBool, convertFileNameFortranParserCode(), DString::data(), getLanguageFromFileName(), Debug::isFlagSet(), Debug::Lex_commentcnv, commentcnvYY_CondCtx::lineNr, Debug::print(), qPrint(), recognizeFixedForm(), commentcnvYY_CondCtx::sectionId, DString::setNum(), DString::sprintf(), DString::stripWhiteSpace(), warn, and yylex().

Referenced by generateHtmlForComment(), and parseFile().