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

First pass comment processing. More...

#include <string>
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 2141 of file commentcnv.l.

2142{
2143 DString fileName { fn };
2144 yyscan_t yyscanner;
2145 commentcnvYY_state extra(&inBuf,outBuf);
2146 commentcnvYYlex_init_extra(&extra,&yyscanner);
2147#ifdef FLEX_DEBUG
2148 commentcnvYYset_debug(Debug::isFlagSet(Debug::Lex_commentcnv)?1:0,yyscanner);
2149#endif
2150 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2151 //printf("convertCppComments(%s)\n",qPrint(fileName));
2152 yyextra->inBufPos = 0;
2153 yyextra->col = 0;
2154 yyextra->mlBrief = Config_getBool(MULTILINE_CPP_IS_BRIEF);
2155 yyextra->skip = false;
2156 yyextra->fileName = fileName;
2157 yyextra->lang = getLanguageFromFileName(fileName);
2158 yyextra->pythonDocString = false;
2159 yyextra->lineNr = 1;
2160 yyextra->raiseLevel = 0;
2161 yyextra->raiseLabel = "";
2162 yyextra->raiseIncrement = 0;
2163 yyextra->raisePrefix = "";
2164 yyextra->insertCppCommentMarker=false;
2165 yyextra->expandedAliases.clear();
2166 while (!yyextra->condStack.empty()) yyextra->condStack.pop();
2167 clearCommentStack(yyscanner);
2168 yyextra->vhdl = false;
2169
2170 DebugLex debugLex(Debug::Lex_commentcnv,__FILE__, qPrint(fileName));
2171 yyextra->isFixedForm = false;
2172 if (yyextra->lang==SrcLangExt::Fortran)
2173 {
2175 yyextra->isFixedForm = recognizeFixedForm(inBuf,fmt);
2176 }
2177
2178 if (yyextra->lang==SrcLangExt::Markdown)
2179 {
2180 yyextra->nestingCount=0;
2181 BEGIN(CComment);
2182 yyextra->commentStack.push(yyextra->lineNr);
2183 }
2184 else
2185 {
2186 BEGIN(Scan);
2187 }
2188 yylex(yyscanner);
2189 while (!yyextra->condStack.empty())
2190 {
2191 const commentcnvYY_CondCtx &ctx = yyextra->condStack.top();
2192 DString sectionInfo(" ");
2193 if (ctx.sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",ctx.sectionId.stripWhiteSpace().data());
2194 warn(yyextra->fileName,ctx.lineNr,"Conditional section{}does not have "
2195 "a corresponding \\endcond command within this file.",sectionInfo.data());
2196 yyextra->condStack.pop();
2197 }
2198 if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt::Markdown && yyextra->lang!=SrcLangExt::Fortran)
2199 {
2200 DString lines;
2201 bool first = true;
2202 while (!yyextra->commentStack.empty())
2203 {
2204 int lineNr = yyextra->commentStack.top();
2205 if (!first) lines += ", ";
2206 lines += DString().setNum(lineNr);
2207 first = false;
2208 yyextra->commentStack.pop();
2209 }
2210 warn(yyextra->fileName,yyextra->lineNr,"Reached end of file while still inside a (nested) comment. "
2211 "Nesting level {} (possible line reference(s): {})",yyextra->nestingCount,lines);
2212 }
2213 yyextra->nestingCount = 0;
2215 {
2216 Debug::print(Debug::CommentCnv,0,"-----------\nCommentCnv: {}\n"
2217 "output=[\n{}]\n-----------\n",fileName,yyextra->outBuf
2218 );
2219 }
2220 commentcnvYYlex_destroy(yyscanner);
2221}
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:4168

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().