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 2403 of file commentcnv.l.

2404{
2405 DString fileName { fn };
2406 yyscan_t yyscanner;
2407 commentcnvYY_state extra(&inBuf,outBuf);
2408 commentcnvYYlex_init_extra(&extra,&yyscanner);
2409#ifdef FLEX_DEBUG
2410 commentcnvYYset_debug(Debug::isFlagSet(Debug::Lex_commentcnv)?1:0,yyscanner);
2411#endif
2412 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2413 //printf("convertCppComments(%s)\n",qPrint(fileName));
2414 yyextra->inBufPos = 0;
2415 yyextra->col = 0;
2416 yyextra->mlBrief = Config_getBool(MULTILINE_CPP_IS_BRIEF);
2417 yyextra->skip = false;
2418 yyextra->fileName = fileName;
2419 yyextra->lang = getLanguageFromFileName(fileName);
2420 yyextra->pythonDocString = false;
2421 yyextra->lineNr = 1;
2422 yyextra->raiseLevel = 0;
2423 yyextra->raiseLabel = "";
2424 yyextra->raiseIncrement = 0;
2425 yyextra->raisePrefix = "";
2426 yyextra->insertCppCommentMarker=false;
2427 yyextra->expandedAliases.clear();
2428 yyextra->replacements.clear();
2429 while (!yyextra->condStack.empty()) yyextra->condStack.pop();
2430 clearCommentStack(yyscanner);
2431 yyextra->vhdl = false;
2432
2433 DebugLex debugLex(Debug::Lex_commentcnv,__FILE__, qPrint(fileName));
2434 yyextra->isFixedForm = false;
2435 if (yyextra->lang==SrcLangExt::Fortran)
2436 {
2438 yyextra->isFixedForm = recognizeFixedForm(inBuf,fmt);
2439 }
2440
2441 if (yyextra->lang==SrcLangExt::Markdown)
2442 {
2443 yyextra->nestingCount=0;
2444 BEGIN(CComment);
2445 yyextra->commentStack.push(yyextra->lineNr);
2446 }
2447 else
2448 {
2449 BEGIN(Scan);
2450 }
2451 yylex(yyscanner);
2452 while (!yyextra->condStack.empty())
2453 {
2454 const commentcnvYY_CondCtx &ctx = yyextra->condStack.top();
2455 DString sectionInfo(" ");
2456 if (ctx.sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",ctx.sectionId.stripWhiteSpace().data());
2457 warn(yyextra->fileName,ctx.lineNr,"Conditional section{}does not have "
2458 "a corresponding \\endcond command within this file.",sectionInfo.data());
2459 yyextra->condStack.pop();
2460 }
2461 if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt::Markdown && yyextra->lang!=SrcLangExt::Fortran)
2462 {
2463 DString lines;
2464 bool first = true;
2465 while (!yyextra->commentStack.empty())
2466 {
2467 int lineNr = yyextra->commentStack.top();
2468 if (!first) lines += ", ";
2469 lines += DString().setNum(lineNr);
2470 first = false;
2471 yyextra->commentStack.pop();
2472 }
2473 warn(yyextra->fileName,yyextra->lineNr,"Reached end of file while still inside a (nested) comment. "
2474 "Nesting level {} (possible line reference(s): {})",yyextra->nestingCount,lines);
2475 }
2476 yyextra->nestingCount = 0;
2478 {
2479 Debug::print(Debug::CommentCnv,0,"-----------\nCommentCnv: {}\n"
2480 "output=[\n{}]\n-----------\n",fileName,yyextra->outBuf
2481 );
2482 }
2483 commentcnvYYlex_destroy(yyscanner);
2484}
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:25
#define yyguts_t
Definition code.l:23
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:614
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
Definition util.cpp:4300

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, yyguts_t, and yylex().

Referenced by generateHtmlForComment(), and parseFile().