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

4062 : p(std::make_unique<Private>())
4063{
4064 preYYlex_init_extra(&p->state,&p->yyscanner);
4065 addSearchDir(".");
4066}
void addSearchDir(const QCString &dir)
Definition pre.l:4055
std::unique_ptr< Private > p
Definition pre.h:38

References addSearchDir(), and p.

◆ ~Preprocessor()

Preprocessor::~Preprocessor ( )

Definition at line 4068 of file pre.l.

4069{
4070 preYYlex_destroy(p->yyscanner);
4071}

References p.

Member Function Documentation

◆ addSearchDir()

void Preprocessor::addSearchDir ( const QCString & dir)

Definition at line 4055 of file pre.l.

4056{
4057 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4058 FileInfo fi(dir.str());
4059 if (fi.isDir()) state->pathList.push_back(fi.absFilePath());
4060}
const std::string & str() const
Definition qcstring.h:552

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

4074{
4075 AUTO_TRACE("fileName={}",fileName);
4076 yyscan_t yyscanner = p->yyscanner;
4077 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4078 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4079
4080#ifdef FLEX_DEBUG
4081 preYYset_debug(Debug::isFlagSet(Debug::Lex_pre)?1:0,yyscanner);
4082#endif
4083
4084 DebugLex debugLex(Debug::Lex_pre, __FILE__, qPrint(fileName));
4085 //printf("##########################\n%s\n####################\n",
4086 // qPrint(input));
4087
4088 state->macroExpansion = Config_getBool(MACRO_EXPANSION);
4089 state->expandOnlyPredef = Config_getBool(EXPAND_ONLY_PREDEF);
4090 state->skip=FALSE;
4091 state->curlyCount=0;
4092 state->lexRulesPart=false;
4093 state->nospaces=FALSE;
4094 state->inputBuf=&input;
4095 state->inputBufPos=0;
4096 state->outputBuf=&output;
4097 state->includeStack.clear();
4098 state->expandedDict.clear();
4099 state->contextDefines.clear();
4100 state->pragmaSet.clear();
4101 while (!state->condStack.empty()) state->condStack.pop();
4102
4103 setFileName(yyscanner,fileName);
4104
4105 state->inputFileDef = state->yyFileDef;
4106 //yyextra->defineManager.startContext(state->fileName);
4107
4108 initPredefined(yyscanner,fileName);
4109
4110 state->yyLineNr = 1;
4111 state->yyColNr = 1;
4112 state->ifcount = 0;
4113
4114 BEGIN( Start );
4115
4116 state->expectGuard = guessSection(fileName).isHeader();
4117 state->guardName.clear();
4118 state->lastGuardName.clear();
4119 state->guardExpr.clear();
4120
4121 preYYlex(yyscanner);
4122
4123 while (!state->condStack.empty())
4124 {
4125 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4126 QCString sectionInfo = " ";
4127 if (ctx->sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",qPrint(ctx->sectionId.stripWhiteSpace()));
4128 warn(ctx->fileName,ctx->lineNr,"Conditional section{}does not have "
4129 "a corresponding \\endcond command within this file.",sectionInfo);
4130 state->condStack.pop();
4131 }
4132 // make sure we don't extend a \cond with missing \endcond over multiple files (see bug 624829)
4133 forceEndCondSection(yyscanner);
4134
4135 if (!state->levelGuard.empty())
4136 {
4137 warn(state->fileName,state->yyLineNr,"More #if's than #endif's found (might be in an included file).");
4138 }
4139
4141 {
4142 std::lock_guard<std::mutex> lock(g_debugMutex);
4143 Debug::print(Debug::Preprocessor,0,"Preprocessor output of {} (size: {} bytes):\n",fileName,output.size());
4144 std::string contents;
4146 {
4147 contents=output;
4148 }
4149 else // need to add line numbers
4150 {
4151 int line=1;
4152 bool startOfLine = true;
4153 size_t content_size = output.size() +
4154 output.size()*6/40; // assuming 40 chars per line on average
4155 // and 6 chars extra for the line number
4156 contents.reserve(content_size);
4157 size_t pos=0;
4158 while (pos<output.size())
4159 {
4160 if (startOfLine)
4161 {
4162 char lineNrStr[15];
4163 snprintf(lineNrStr,15,"%05d ",line++);
4164 contents+=lineNrStr;
4165 }
4166 contents += output[pos];
4167 startOfLine = output[pos]=='\n';
4168 pos++;
4169 }
4170 }
4171 char end[2]={0,0};
4172 if (!contents.empty() && contents[contents.length()-1]!='\n')
4173 {
4174 end[0]='\n';
4175 }
4176 Debug::print(Debug::Preprocessor,0,"---------\n{}{}---------\n",contents,end);
4177 if (yyextra->contextDefines.size()>0)
4178 {
4179 Debug::print(Debug::Preprocessor,0,"Macros accessible in this file ({}):\n", fileName);
4180 Debug::print(Debug::Preprocessor,0,"---------\n");
4181 for (auto &kv : yyextra->contextDefines)
4182 {
4183 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4184 }
4185 for (auto &kv : yyextra->localDefines)
4186 {
4187 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4188 }
4189 Debug::print(Debug::Preprocessor,0,"\n---------\n");
4190 }
4191 else
4192 {
4193 Debug::print(Debug::Preprocessor,0,"No macros accessible in this file ({}).\n", fileName);
4194 }
4195 }
4196
4197 {
4198 std::lock_guard<std::mutex> lock(g_updateGlobals);
4199 for (const auto &inc : state->includeRelations)
4200 {
4201 auto toKind = [](bool local,bool imported) -> IncludeKind
4202 {
4203 if (local)
4204 {
4205 if (imported)
4206 {
4208 }
4210 }
4211 else if (imported)
4212 {
4214 }
4216 };
4217 if (inc->fromFileDef)
4218 {
4219 inc->fromFileDef->addIncludeDependency(inc->toFileDef,inc->includeName,toKind(inc->local,inc->imported));
4220 }
4221 if (inc->toFileDef && inc->fromFileDef)
4222 {
4223 inc->toFileDef->addIncludedByDependency(inc->fromFileDef,inc->fromFileDef->docName(),toKind(inc->local,inc->imported));
4224 }
4225 }
4226 // add the macro definition for this file to the global map
4227 Doxygen::macroDefinitions.emplace(state->fileName.str(),std::move(state->macroDefinitions));
4228 }
4229
4230 //yyextra->defineManager.endContext();
4231}
@ NoLineNo
Definition debug.h:42
@ Lex_pre
Definition debug.h:64
@ Preprocessor
Definition debug.h:30
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:76
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:97
static void initPredefined(yyscan_t yyscanner, const QCString &fileName)
Definition pre.l:3928
static void setFileName(yyscan_t yyscanner, const QCString &name)
Definition pre.l:2212
static void forceEndCondSection(yyscan_t yyscanner)
Definition pre.l:3784
static std::mutex g_updateGlobals
Definition pre.l:235
static std::mutex g_debugMutex
Definition pre.l:233
const char * qPrint(const char *s)
Definition qcstring.h:687
#define FALSE
Definition qcstring.h:34
EntryType guessSection(const QCString &name)
Definition util.cpp:350

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