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

3998 : p(std::make_unique<Private>())
3999{
4000 preYYlex_init_extra(&p->state,&p->yyscanner);
4001 addSearchDir(".");
4002}
void addSearchDir(const QCString &dir)
Definition pre.l:3991
std::unique_ptr< Private > p
Definition pre.h:38

References addSearchDir(), and p.

◆ ~Preprocessor()

Preprocessor::~Preprocessor ( )

Definition at line 4004 of file pre.l.

4005{
4006 preYYlex_destroy(p->yyscanner);
4007}

References p.

Member Function Documentation

◆ addSearchDir()

void Preprocessor::addSearchDir ( const QCString & dir)

Definition at line 3991 of file pre.l.

3992{
3993 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
3994 FileInfo fi(dir.str());
3995 if (fi.isDir()) state->pathList.push_back(fi.absFilePath());
3996}
const std::string & str() const
Definition qcstring.h:537

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

4010{
4011 AUTO_TRACE("fileName={}",fileName);
4012 yyscan_t yyscanner = p->yyscanner;
4013 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4014 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4015
4016#ifdef FLEX_DEBUG
4017 preYYset_debug(Debug::isFlagSet(Debug::Lex_pre)?1:0,yyscanner);
4018#endif
4019
4020 DebugLex debugLex(Debug::Lex_pre, __FILE__, qPrint(fileName));
4021 //printf("##########################\n%s\n####################\n",
4022 // qPrint(input));
4023
4024 state->macroExpansion = Config_getBool(MACRO_EXPANSION);
4025 state->expandOnlyPredef = Config_getBool(EXPAND_ONLY_PREDEF);
4026 state->skip=FALSE;
4027 state->curlyCount=0;
4028 state->lexRulesPart=false;
4029 state->nospaces=FALSE;
4030 state->inputBuf=&input;
4031 state->inputBufPos=0;
4032 state->outputBuf=&output;
4033 state->includeStack.clear();
4034 state->expandedDict.clear();
4035 state->contextDefines.clear();
4036 state->pragmaSet.clear();
4037 while (!state->condStack.empty()) state->condStack.pop();
4038
4039 setFileName(yyscanner,fileName);
4040
4041 state->inputFileDef = state->yyFileDef;
4042 //yyextra->defineManager.startContext(state->fileName);
4043
4044 initPredefined(yyscanner,fileName);
4045
4046 state->yyLineNr = 1;
4047 state->yyColNr = 1;
4048 state->ifcount = 0;
4049
4050 BEGIN( Start );
4051
4052 state->expectGuard = guessSection(fileName).isHeader();
4053 state->guardName.clear();
4054 state->lastGuardName.clear();
4055 state->guardExpr.clear();
4056
4057 preYYlex(yyscanner);
4058
4059 while (!state->condStack.empty())
4060 {
4061 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4062 QCString sectionInfo = " ";
4063 if (ctx->sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",qPrint(ctx->sectionId.stripWhiteSpace()));
4064 warn(ctx->fileName,ctx->lineNr,"Conditional section%sdoes not have "
4065 "a corresponding \\endcond command within this file.",qPrint(sectionInfo));
4066 state->condStack.pop();
4067 }
4068 // make sure we don't extend a \cond with missing \endcond over multiple files (see bug 624829)
4069 forceEndCondSection(yyscanner);
4070
4072 {
4073 std::lock_guard<std::mutex> lock(g_debugMutex);
4074 Debug::print(Debug::Preprocessor,0,"Preprocessor output of %s (size: %zu bytes):\n",qPrint(fileName),output.size());
4075 std::string contents;
4077 {
4078 contents=output;
4079 }
4080 else // need to add line numbers
4081 {
4082 int line=1;
4083 bool startOfLine = true;
4084 size_t content_size = output.size() +
4085 output.size()*6/40; // assuming 40 chars per line on average
4086 // and 6 chars extra for the line number
4087 contents.reserve(content_size);
4088 size_t pos=0;
4089 while (pos<output.size())
4090 {
4091 if (startOfLine)
4092 {
4093 char lineNrStr[15];
4094 snprintf(lineNrStr,15,"%05d ",line++);
4095 contents+=lineNrStr;
4096 }
4097 contents += output[pos];
4098 startOfLine = output[pos]=='\n';
4099 pos++;
4100 }
4101 }
4102 char end[2]={0,0};
4103 if (!contents.empty() && contents[contents.length()-1]!='\n')
4104 {
4105 end[0]='\n';
4106 }
4107 Debug::print(Debug::Preprocessor,0,"---------\n%s%s---------\n",contents.c_str(),end);
4108 if (yyextra->contextDefines.size()>0)
4109 {
4110 Debug::print(Debug::Preprocessor,0,"Macros accessible in this file (%s):\n", qPrint(fileName));
4111 Debug::print(Debug::Preprocessor,0,"---------\n");
4112 for (auto &kv : yyextra->contextDefines)
4113 {
4114 Debug::print(Debug::Preprocessor,0,"%s ",qPrint(kv.second.name));
4115 }
4116 for (auto &kv : yyextra->localDefines)
4117 {
4118 Debug::print(Debug::Preprocessor,0,"%s ",qPrint(kv.second.name));
4119 }
4120 Debug::print(Debug::Preprocessor,0,"\n---------\n");
4121 }
4122 else
4123 {
4124 Debug::print(Debug::Preprocessor,0,"No macros accessible in this file (%s).\n", qPrint(fileName));
4125 }
4126 }
4127
4128 {
4129 std::lock_guard<std::mutex> lock(g_updateGlobals);
4130 for (const auto &inc : state->includeRelations)
4131 {
4132 auto toKind = [](bool local,bool imported) -> IncludeKind
4133 {
4134 if (local)
4135 {
4136 if (imported)
4137 {
4139 }
4141 }
4142 else if (imported)
4143 {
4145 }
4147 };
4148 if (inc->fromFileDef)
4149 {
4150 inc->fromFileDef->addIncludeDependency(inc->toFileDef,inc->includeName,toKind(inc->local,inc->imported));
4151 }
4152 if (inc->toFileDef && inc->fromFileDef)
4153 {
4154 inc->toFileDef->addIncludedByDependency(inc->fromFileDef,inc->fromFileDef->docName(),toKind(inc->local,inc->imported));
4155 }
4156 }
4157 // add the macro definition for this file to the global map
4158 Doxygen::macroDefinitions.emplace(state->fileName.str(),std::move(state->macroDefinitions));
4159 }
4160
4161 //yyextra->defineManager.endContext();
4162}
@ NoLineNo
Definition debug.h:41
@ Lex_pre
Definition debug.h:63
@ Preprocessor
Definition debug.h:29
static void print(DebugMask mask, int prio, const char *fmt,...)
Definition debug.cpp:81
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:135
static DefinesPerFileList macroDefinitions
Definition doxygen.h:137
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:46
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:59
static void initPredefined(yyscan_t yyscanner, const QCString &fileName)
Definition pre.l:3864
static void setFileName(yyscan_t yyscanner, const QCString &name)
Definition pre.l:2149
static void forceEndCondSection(yyscan_t yyscanner)
Definition pre.l:3720
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:672
#define FALSE
Definition qcstring.h:34
EntryType guessSection(const QCString &name)
Definition util.cpp:349

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