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 4398 of file pre.l.

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

References addSearchDir(), and p.

◆ ~Preprocessor()

Preprocessor::~Preprocessor ( )

Definition at line 4404 of file pre.l.

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

References p.

Member Function Documentation

◆ addSearchDir()

void Preprocessor::addSearchDir ( const DString & dir)

Definition at line 4391 of file pre.l.

4392{
4393 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4394 FileInfo fi(dir.str());
4395 if (fi.isDir()) state->pathList.push_back(fi.absFilePath());
4396}
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 4409 of file pre.l.

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

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

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: