Doxygen
Loading...
Searching...
No Matches
Preprocessor Class Reference

#include <src/pre.h>

Classes

struct  Private

Public Member Functions

 Preprocessor ()
 ~Preprocessor ()
void processFile (const QCString &fileName, const std::string &input, std::string &output)
void addSearchDir (const QCString &dir)

Private Attributes

std::unique_ptr< Privatep

Detailed Description

Definition at line 27 of file pre.h.

Constructor & Destructor Documentation

◆ Preprocessor()

Preprocessor::Preprocessor ( )

Definition at line 4237 of file pre.l.

4237 : p(std::make_unique<Private>())
4238{
4239 preYYlex_init_extra(&p->state,&p->yyscanner);
4240 addSearchDir(".");
4241}
void addSearchDir(const QCString &dir)
Definition pre.l:4230
std::unique_ptr< Private > p
Definition pre.h:38

References addSearchDir(), and p.

◆ ~Preprocessor()

Preprocessor::~Preprocessor ( )

Definition at line 4243 of file pre.l.

4244{
4245 preYYlex_destroy(p->yyscanner);
4246}

References p.

Member Function Documentation

◆ addSearchDir()

void Preprocessor::addSearchDir ( const QCString & dir)

Definition at line 4230 of file pre.l.

4231{
4232 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4233 FileInfo fi(dir.str());
4234 if (fi.isDir()) state->pathList.push_back(fi.absFilePath());
4235}
const std::string & str() const
Definition qcstring.h:552

References FileInfo::absFilePath(), FileInfo::isDir(), p, and QCString::str().

Referenced by parseFile(), and Preprocessor().

◆ processFile()

void Preprocessor::processFile ( const QCString & fileName,
const std::string & input,
std::string & output )

Definition at line 4248 of file pre.l.

4249{
4250 AUTO_TRACE("fileName={}",fileName);
4251 yyscan_t yyscanner = p->yyscanner;
4252 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4253 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4254
4255#ifdef FLEX_DEBUG
4256 preYYset_debug(Debug::isFlagSet(Debug::Lex_pre)?1:0,yyscanner);
4257#endif
4258
4259 DebugLex debugLex(Debug::Lex_pre, __FILE__, qPrint(fileName));
4260 //printf("##########################\n%s\n####################\n",
4261 // qPrint(input));
4262
4263 state->macroExpansion = Config_getBool(MACRO_EXPANSION);
4264 state->expandOnlyPredef = Config_getBool(EXPAND_ONLY_PREDEF);
4265 state->skip=FALSE;
4266 state->curlyCount=0;
4267 state->lexRulesPart=false;
4268 state->nospaces=FALSE;
4269 state->inputBuf=&input;
4270 state->inputBufPos=0;
4271 state->outputBuf=&output;
4272 state->includeStack.clear();
4273 state->expandedDict.clear();
4274 state->contextDefines.clear();
4275 state->pragmaSet.clear();
4276 state->condGuardCount=0;
4277 state->condGuardErrorLine=0;
4278 while (!state->levelGuard.empty()) state->levelGuard.pop();
4279 while (!state->condStack.empty()) state->condStack.pop();
4280
4281 setFileName(yyscanner,fileName);
4282
4283 state->inputFileDef = state->yyFileDef;
4284 //yyextra->defineManager.startContext(state->fileName);
4285
4286 initPredefined(yyscanner,fileName);
4287
4288 state->yyLineNr = 1;
4289 state->yyColNr = 1;
4290 state->ifcount = 0;
4291
4292 BEGIN( Start );
4293
4294 state->expectGuard = guessSection(fileName).isHeader();
4295 state->guardName.clear();
4296 state->lastGuardName.clear();
4297 state->guardExpr.clear();
4298
4299 preYYlex(yyscanner);
4300
4301 while (!state->condStack.empty())
4302 {
4303 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4304 QCString sectionInfo = " ";
4305 if (ctx->sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",qPrint(ctx->sectionId.stripWhiteSpace()));
4306 warn(ctx->fileName,ctx->lineNr,"Conditional section{}does not have "
4307 "a corresponding \\endcond command within this file.",sectionInfo);
4308 state->condStack.pop();
4309 }
4310 // make sure we don't extend a \cond with missing \endcond over multiple files (see bug 624829)
4311 forceEndCondSection(yyscanner);
4312
4313 if (!state->levelGuard.empty())
4314 {
4315 if (yyextra->condGuardErrorLine!=0)
4316 {
4317 warn(yyextra->condGuardErrorFileName,yyextra->condGuardErrorLine,"{}",yyextra->condGuardErrorMessage);
4318 }
4319 else
4320 {
4321 warn(state->fileName,state->yyLineNr,"More #if's than #endif's found (might be in an included file).");
4322 }
4323 }
4324
4326 {
4327 std::lock_guard<std::mutex> lock(g_debugMutex);
4328 Debug::print(Debug::Preprocessor,0,"Preprocessor output of {} (size: {} bytes):\n",fileName,output.size());
4329 std::string contents;
4331 {
4332 contents=output;
4333 }
4334 else // need to add line numbers
4335 {
4336 int line=1;
4337 bool startOfLine = true;
4338 size_t content_size = output.size() +
4339 output.size()*6/40; // assuming 40 chars per line on average
4340 // and 6 chars extra for the line number
4341 contents.reserve(content_size);
4342 size_t pos=0;
4343 while (pos<output.size())
4344 {
4345 if (startOfLine)
4346 {
4347 char lineNrStr[15];
4348 snprintf(lineNrStr,15,"%05d ",line++);
4349 contents+=lineNrStr;
4350 }
4351 contents += output[pos];
4352 startOfLine = output[pos]=='\n';
4353 pos++;
4354 }
4355 }
4356 char end[2]={0,0};
4357 if (!contents.empty() && contents[contents.length()-1]!='\n')
4358 {
4359 end[0]='\n';
4360 }
4361 Debug::print(Debug::Preprocessor,0,"---------\n{}{}---------\n",contents,end);
4362 if (yyextra->contextDefines.size()>0)
4363 {
4364 Debug::print(Debug::Preprocessor,0,"Macros accessible in this file ({}):\n", fileName);
4365 Debug::print(Debug::Preprocessor,0,"---------\n");
4366 for (auto &kv : yyextra->contextDefines)
4367 {
4368 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4369 }
4370 for (auto &kv : yyextra->localDefines)
4371 {
4372 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4373 }
4374 Debug::print(Debug::Preprocessor,0,"\n---------\n");
4375 }
4376 else
4377 {
4378 Debug::print(Debug::Preprocessor,0,"No macros accessible in this file ({}).\n", fileName);
4379 }
4380 }
4381
4382 {
4383 std::lock_guard<std::mutex> lock(g_updateGlobals);
4384 for (const auto &inc : state->includeRelations)
4385 {
4386 auto toKind = [](bool local,bool imported) -> IncludeKind
4387 {
4388 if (local)
4389 {
4390 if (imported)
4391 {
4393 }
4395 }
4396 else if (imported)
4397 {
4399 }
4401 };
4402 if (inc->fromFileDef)
4403 {
4404 inc->fromFileDef->addIncludeDependency(inc->toFileDef,inc->includeName,toKind(inc->local,inc->imported));
4405 }
4406 if (inc->toFileDef && inc->fromFileDef)
4407 {
4408 inc->toFileDef->addIncludedByDependency(inc->fromFileDef,inc->fromFileDef->docName(),toKind(inc->local,inc->imported));
4409 }
4410 }
4411 // add the macro definition for this file to the global map
4412 Doxygen::macroDefinitions.emplace(state->fileName.str(),std::move(state->macroDefinitions));
4413 }
4414
4415 //yyextra->defineManager.endContext();
4416}
@ NoLineNo
Definition debug.h:42
@ Lex_pre
Definition debug.h:65
@ Preprocessor
Definition debug.h:30
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:133
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:77
static DefinesPerFileList macroDefinitions
Definition doxygen.h:135
QCString & sprintf(const char *format,...)
Definition qcstring.cpp:29
yyguts_t * yyscan_t
Definition code.l:24
#define Config_getBool(name)
Definition config.h:33
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175
#define AUTO_TRACE(...)
Definition docnode.cpp:48
IncludeKind
Definition filedef.h:47
@ IncludeLocal
Definition filedef.h:50
@ ImportSystemObjC
Definition filedef.h:51
@ ImportLocalObjC
Definition filedef.h:52
@ IncludeSystem
Definition filedef.h:49
#define warn(file, line, fmt,...)
Definition message.h:97
static void initPredefined(yyscan_t yyscanner, const QCString &fileName)
Definition pre.l:4103
static void setFileName(yyscan_t yyscanner, const QCString &name)
Definition pre.l:2258
static void forceEndCondSection(yyscan_t yyscanner)
Definition pre.l:3959
static std::mutex g_updateGlobals
Definition pre.l:234
static std::mutex g_debugMutex
Definition pre.l:232
const char * qPrint(const char *s)
Definition qcstring.h:687
#define FALSE
Definition qcstring.h:34
EntryType guessSection(const QCString &name)
Definition util.cpp:338

References AUTO_TRACE, Config_getBool, end(), FALSE, forceEndCondSection(), g_debugMutex, g_updateGlobals, guessSection(), ImportLocalObjC, ImportSystemObjC, IncludeLocal, IncludeSystem, initPredefined(), Debug::isFlagSet(), Debug::Lex_pre, Doxygen::macroDefinitions, Debug::NoLineNo, p, Debug::Preprocessor, Debug::print(), qPrint(), setFileName(), QCString::size(), QCString::sprintf(), and warn.

Referenced by parseFile().

Member Data Documentation

◆ p

std::unique_ptr<Private> Preprocessor::p
private

Definition at line 38 of file pre.h.

Referenced by addSearchDir(), Preprocessor(), processFile(), and ~Preprocessor().


The documentation for this class was generated from the following files: