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< Privatep

Detailed Description

Definition at line 26 of file pre.h.

Constructor & Destructor Documentation

◆ Preprocessor()

Preprocessor::Preprocessor ( )

Definition at line 4291 of file pre.l.

4291 : p(std::make_unique<Private>())
4292{
4293 preYYlex_init_extra(&p->state,&p->yyscanner);
4294 addSearchDir(".");
4295}
void addSearchDir(const DString &dir)
Definition pre.l:4284
std::unique_ptr< Private > p
Definition pre.h:37

References addSearchDir(), and p.

◆ ~Preprocessor()

Preprocessor::~Preprocessor ( )

Definition at line 4297 of file pre.l.

4298{
4299 preYYlex_destroy(p->yyscanner);
4300}

References p.

Member Function Documentation

◆ addSearchDir()

void Preprocessor::addSearchDir ( const DString & dir)

Definition at line 4284 of file pre.l.

4285{
4286 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4287 FileInfo fi(dir.str());
4288 if (fi.isDir()) state->pathList.push_back(fi.absFilePath());
4289}
const std::string & str() const
Definition dstring.h:649

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

4303{
4304 AUTO_TRACE("fileName={}",fileName);
4305 yyscan_t yyscanner = p->yyscanner;
4306 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4307 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4308
4309#ifdef FLEX_DEBUG
4310 preYYset_debug(Debug::isFlagSet(Debug::Lex_pre)?1:0,yyscanner);
4311#endif
4312
4313 DebugLex debugLex(Debug::Lex_pre, __FILE__, qPrint(fileName));
4314 //printf("##########################\n%s\n####################\n",
4315 // qPrint(input));
4316
4317 state->macroExpansion = Config_getBool(MACRO_EXPANSION);
4318 state->expandOnlyPredef = Config_getBool(EXPAND_ONLY_PREDEF);
4319 state->skip=false;
4320 state->curlyCount=0;
4321 state->lexRulesPart=false;
4322 state->nospaces=false;
4323 state->inputBuf=&input;
4324 state->inputBufPos=0;
4325 state->outputBuf=&output;
4326 state->includeStack.clear();
4327 state->expandedDict.clear();
4328 state->contextDefines.clear();
4329 state->pragmaSet.clear();
4330 state->condGuardCount=0;
4331 state->condGuardErrorLine=0;
4332 while (!state->levelGuard.empty()) state->levelGuard.pop();
4333 while (!state->condStack.empty()) state->condStack.pop();
4334
4335 setFileName(yyscanner,fileName);
4336
4337 state->inputFileDef = state->yyFileDef;
4338 //yyextra->defineManager.startContext(state->fileName);
4339
4340 initPredefined(yyscanner,fileName);
4341
4342 state->yyLineNr = 1;
4343 state->yyColNr = 1;
4344 state->ifcount = 0;
4345
4346 BEGIN( Start );
4347
4348 state->expectGuard = EntryType::guessSection(fileName).isHeader();
4349 state->guardName.clear();
4350 state->lastGuardName.clear();
4351 state->guardExpr.clear();
4352
4353 preYYlex(yyscanner);
4354
4355 while (!state->condStack.empty())
4356 {
4357 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4358 DString sectionInfo = " ";
4359 if (ctx->sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",qPrint(ctx->sectionId.stripWhiteSpace()));
4360 warn(ctx->fileName,ctx->lineNr,"Conditional section{}does not have "
4361 "a corresponding \\endcond command within this file.",sectionInfo);
4362 state->condStack.pop();
4363 }
4364 // make sure we don't extend a \cond with missing \endcond over multiple files (see bug 624829)
4365 forceEndCondSection(yyscanner);
4366
4367 if (!state->levelGuard.empty())
4368 {
4369 if (yyextra->condGuardErrorLine!=0)
4370 {
4371 warn(yyextra->condGuardErrorFileName,yyextra->condGuardErrorLine,"{}",yyextra->condGuardErrorMessage);
4372 }
4373 else
4374 {
4375 warn(state->fileName,state->yyLineNr,"More #if's than #endif's found (might be in an included file).");
4376 }
4377 }
4378
4380 {
4381 std::lock_guard<std::mutex> lock(g_debugMutex);
4382 Debug::print(Debug::Preprocessor,0,"Preprocessor output of {} (size: {} bytes):\n",fileName,output.size());
4383 std::string contents;
4385 {
4386 contents=output;
4387 }
4388 else // need to add line numbers
4389 {
4390 int line=1;
4391 bool startOfLine = true;
4392 size_t content_size = output.size() +
4393 output.size()*6/40; // assuming 40 chars per line on average
4394 // and 6 chars extra for the line number
4395 contents.reserve(content_size);
4396 size_t pos=0;
4397 while (pos<output.size())
4398 {
4399 if (startOfLine)
4400 {
4401 char lineNrStr[15];
4402 snprintf(lineNrStr,15,"%05d ",line++);
4403 contents+=lineNrStr;
4404 }
4405 contents += output[pos];
4406 startOfLine = output[pos]=='\n';
4407 pos++;
4408 }
4409 }
4410 char end[2]={0,0};
4411 if (!contents.empty() && contents[contents.length()-1]!='\n')
4412 {
4413 end[0]='\n';
4414 }
4415 Debug::print(Debug::Preprocessor,0,"---------\n{}{}---------\n",contents,end);
4416 if (yyextra->contextDefines.size()>0)
4417 {
4418 Debug::print(Debug::Preprocessor,0,"Macros accessible in this file ({}):\n", fileName);
4419 Debug::print(Debug::Preprocessor,0,"---------\n");
4420 for (auto &kv : yyextra->contextDefines)
4421 {
4422 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4423 }
4424 for (auto &kv : yyextra->localDefines)
4425 {
4426 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4427 }
4428 Debug::print(Debug::Preprocessor,0,"\n---------\n");
4429 }
4430 else
4431 {
4432 Debug::print(Debug::Preprocessor,0,"No macros accessible in this file ({}).\n", fileName);
4433 }
4434 }
4435
4436 {
4437 std::lock_guard<std::mutex> lock(g_updateGlobals);
4438 for (const auto &inc : state->includeRelations)
4439 {
4440 auto toKind = [](bool local,bool imported) -> IncludeKind
4441 {
4442 if (local)
4443 {
4444 if (imported)
4445 {
4447 }
4449 }
4450 else if (imported)
4451 {
4453 }
4455 };
4456 if (inc->fromFileDef)
4457 {
4458 inc->fromFileDef->addIncludeDependency(inc->toFileDef,inc->includeName,toKind(inc->local,inc->imported));
4459 }
4460 if (inc->toFileDef && inc->fromFileDef)
4461 {
4462 inc->toFileDef->addIncludedByDependency(inc->fromFileDef,inc->fromFileDef->docName(),toKind(inc->local,inc->imported));
4463 }
4464 }
4465 // add the macro definition for this file to the global map
4466 Doxygen::macroDefinitions.emplace(state->fileName.str(),std::move(state->macroDefinitions));
4467 }
4468
4469 //yyextra->defineManager.endContext();
4470}
DString & sprintf(const char *format,...)
Definition dstring.cpp:30
@ 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:133
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:19
yyguts_t * yyscan_t
Definition code.l:24
#define Config_getBool(name)
Definition config.h:33
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:176
#define AUTO_TRACE(...)
Definition docnode.cpp:51
const char * qPrint(const char *s)
Definition dstring.h:787
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:2279
static void forceEndCondSection(yyscan_t yyscanner)
Definition pre.l:4013
static std::mutex g_updateGlobals
Definition pre.l:236
static void initPredefined(yyscan_t yyscanner, const DString &fileName)
Definition pre.l:4157
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: