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

4265 : p(std::make_unique<Private>())
4266{
4267 preYYlex_init_extra(&p->state,&p->yyscanner);
4268 addSearchDir(".");
4269}
void addSearchDir(const QCString &dir)
Definition pre.l:4258
std::unique_ptr< Private > p
Definition pre.h:38

References addSearchDir(), and p.

◆ ~Preprocessor()

Preprocessor::~Preprocessor ( )

Definition at line 4271 of file pre.l.

4272{
4273 preYYlex_destroy(p->yyscanner);
4274}

References p.

Member Function Documentation

◆ addSearchDir()

void Preprocessor::addSearchDir ( const QCString & dir)

Definition at line 4258 of file pre.l.

4259{
4260 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4261 FileInfo fi(dir.str());
4262 if (fi.isDir()) state->pathList.push_back(fi.absFilePath());
4263}
const std::string & str() const
Definition qcstring.h:550

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

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

References AUTO_TRACE, Config_getBool, end(), 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: