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

#include <src/pre.h>

Classes

struct  Private

Public Member Functions

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

Private Attributes

std::unique_ptr< Private > p

Detailed Description

Definition at line 26 of file pre.h.

Constructor & Destructor Documentation

◆ Preprocessor()

Preprocessor::Preprocessor ( )

Definition at line 4399 of file pre.l.

4399 : p(std::make_unique<Private>())
4400{
4401 preYYlex_init_extra(&p->state,&p->yyscanner);
4402 addSearchDir(".");
4403}
void addSearchDir(const DString &dir)
Definition pre.l:4392
std::unique_ptr< Private > p
Definition pre.h:37

References addSearchDir(), and p.

◆ ~Preprocessor()

Preprocessor::~Preprocessor ( )

Definition at line 4405 of file pre.l.

4406{
4407 preYYlex_destroy(p->yyscanner);
4408}

References p.

Member Function Documentation

◆ addSearchDir()

void Preprocessor::addSearchDir ( const DString & dir)

Definition at line 4392 of file pre.l.

4393{
4394 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4395 FileInfo fi(dir.str());
4396 if (fi.isDir()) state->pathList.push_back(fi.absFilePath());
4397}
const std::string & str() const
Definition dstring.h:645

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

Referenced by parseFile(), and Preprocessor().

◆ processFile()

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

Definition at line 4410 of file pre.l.

4411{
4412 AUTO_TRACE("fileName={}",fileName);
4413 yyscan_t yyscanner = p->yyscanner;
4414 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4415 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4416
4417#ifdef FLEX_DEBUG
4418 preYYset_debug(Debug::isFlagSet(Debug::Lex_pre)?1:0,yyscanner);
4419#endif
4420
4421 DebugLex debugLex(Debug::Lex_pre, __FILE__, qPrint(fileName));
4422 //printf("##########################\n%s\n####################\n",
4423 // qPrint(input));
4424
4425 state->macroExpansion = Config_getBool(MACRO_EXPANSION);
4426 state->expandOnlyPredef = Config_getBool(EXPAND_ONLY_PREDEF);
4427 state->skip=false;
4428 state->curlyCount=0;
4429 state->lexRulesPart=false;
4430 state->nospaces=false;
4431 state->inputBuf=&input;
4432 state->inputBufPos=0;
4433 state->outputBuf=&output;
4434 state->includeStack.clear();
4435 state->expandedDict.clear();
4436 state->contextDefines.clear();
4437 state->pragmaSet.clear();
4438 state->condGuardCount=0;
4439 state->condGuardErrorLine=0;
4440 while (!state->levelGuard.empty()) state->levelGuard.pop();
4441 while (!state->condStack.empty()) state->condStack.pop();
4442
4443 setFileName(yyscanner,fileName);
4444
4445 state->inputFileDef = state->yyFileDef;
4446 //yyextra->defineManager.startContext(state->fileName);
4447
4448 initPredefined(yyscanner,fileName);
4449
4450 state->yyLineNr = 1;
4451 state->yyColNr = 1;
4452 state->ifcount = 0;
4453
4454 BEGIN( Start );
4455
4456 state->expectGuard = EntryType::guessSection(fileName).isHeader();
4457 state->guardName.clear();
4458 state->lastGuardName.clear();
4459 state->guardExpr.clear();
4460
4461 preYYlex(yyscanner);
4462
4463 while (!state->condStack.empty())
4464 {
4465 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4466 DString sectionInfo = " ";
4467 if (ctx->sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",qPrint(ctx->sectionId.stripWhiteSpace()));
4468 warn(ctx->fileName,ctx->lineNr,"Conditional section{}does not have "
4469 "a corresponding \\endcond command within this file.",sectionInfo);
4470 state->condStack.pop();
4471 }
4472 // make sure we don't extend a \cond with missing \endcond over multiple files (see bug 624829)
4473 forceEndCondSection(yyscanner);
4474
4475 if (!state->levelGuard.empty())
4476 {
4477 if (yyextra->condGuardErrorLine!=0)
4478 {
4479 warn(yyextra->condGuardErrorFileName,yyextra->condGuardErrorLine,"{}",yyextra->condGuardErrorMessage);
4480 }
4481 else
4482 {
4483 warn(state->fileName,state->yyLineNr,"More #if's than #endif's found (might be in an included file).");
4484 }
4485 }
4486
4488 {
4489 std::lock_guard<std::mutex> lock(g_debugMutex);
4490 Debug::print(Debug::Preprocessor,0,"Preprocessor output of {} (size: {} bytes):\n",fileName,output.size());
4491 std::string contents;
4493 {
4494 contents=output;
4495 }
4496 else // need to add line numbers
4497 {
4498 int line=1;
4499 bool startOfLine = true;
4500 size_t content_size = output.size() +
4501 output.size()*6/40; // assuming 40 chars per line on average
4502 // and 6 chars extra for the line number
4503 contents.reserve(content_size);
4504 size_t pos=0;
4505 while (pos<output.size())
4506 {
4507 if (startOfLine)
4508 {
4509 char lineNrStr[15];
4510 snprintf(lineNrStr,15,"%05d ",line++);
4511 contents+=lineNrStr;
4512 }
4513 contents += output[pos];
4514 startOfLine = output[pos]=='\n';
4515 pos++;
4516 }
4517 }
4518 char end[2]={0,0};
4519 if (!contents.empty() && contents[contents.length()-1]!='\n')
4520 {
4521 end[0]='\n';
4522 }
4523 Debug::print(Debug::Preprocessor,0,"---------\n{}{}---------\n",contents,end);
4524 if (yyextra->contextDefines.size()>0)
4525 {
4526 Debug::print(Debug::Preprocessor,0,"Macros accessible in this file ({}):\n", fileName);
4527 Debug::print(Debug::Preprocessor,0,"---------\n");
4528 for (auto &kv : yyextra->contextDefines)
4529 {
4530 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4531 }
4532 for (auto &kv : yyextra->localDefines)
4533 {
4534 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4535 }
4536 Debug::print(Debug::Preprocessor,0,"\n---------\n");
4537 }
4538 else
4539 {
4540 Debug::print(Debug::Preprocessor,0,"No macros accessible in this file ({}).\n", fileName);
4541 }
4542 }
4543
4544 {
4545 std::lock_guard<std::mutex> lock(g_updateGlobals);
4546 for (const auto &inc : state->includeRelations)
4547 {
4548 auto toKind = [](bool local,bool imported) -> IncludeKind
4549 {
4550 if (local)
4551 {
4552 if (imported)
4553 {
4555 }
4557 }
4558 else if (imported)
4559 {
4561 }
4563 };
4564 if (inc->fromFileDef)
4565 {
4566 inc->fromFileDef->addIncludeDependency(inc->toFileDef,inc->includeName,toKind(inc->local,inc->imported));
4567 }
4568 if (inc->toFileDef && inc->fromFileDef)
4569 {
4570 inc->toFileDef->addIncludedByDependency(inc->fromFileDef,inc->fromFileDef->docName(),toKind(inc->local,inc->imported));
4571 }
4572 }
4573 // add the macro definition for this file to the global map
4574 Doxygen::macroDefinitions.emplace(state->fileName.str(),std::move(state->macroDefinitions));
4575 }
4576
4577 //yyextra->defineManager.endContext();
4578}
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
@ NoLineNo
Definition debug.h:43
@ Lex_pre
Definition debug.h:66
@ Preprocessor
Definition debug.h:31
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
static DefinesPerFileList macroDefinitions
Definition doxygen.h:128
static EntryType guessSection(const DString &name)
Definition types.cpp:22
yyguts_t * yyscan_t
Definition code.l:25
#define yyguts_t
Definition code.l:23
#define Config_getBool(name)
Definition config.h:33
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:180
#define AUTO_TRACE(...)
Definition docnode.cpp:53
const char * qPrint(const char *s)
Definition dstring.h:783
IncludeKind
Definition filedef.h:44
@ IncludeLocal
Definition filedef.h:47
@ ImportSystemObjC
Definition filedef.h:48
@ ImportLocalObjC
Definition filedef.h:49
@ IncludeSystem
Definition filedef.h:46
#define warn(file, line, fmt,...)
Definition message.h:97
static void setFileName(yyscan_t yyscanner, const DString &name)
Definition pre.l:2281
static void forceEndCondSection(yyscan_t yyscanner)
Definition pre.l:4119
static std::mutex g_updateGlobals
Definition pre.l:237
static void initPredefined(yyscan_t yyscanner, const DString &fileName)
Definition pre.l:4265
static std::mutex g_debugMutex
Definition pre.l:235

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

Referenced by parseFile().

Member Data Documentation

◆ p

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

Definition at line 37 of file pre.h.

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


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