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

4142 : p(std::make_unique<Private>())
4143{
4144 preYYlex_init_extra(&p->state,&p->yyscanner);
4145 addSearchDir(".");
4146}
void addSearchDir(const QCString &dir)
Definition pre.l:4135
std::unique_ptr< Private > p
Definition pre.h:38

References addSearchDir(), and p.

◆ ~Preprocessor()

Preprocessor::~Preprocessor ( )

Definition at line 4148 of file pre.l.

4149{
4150 preYYlex_destroy(p->yyscanner);
4151}

References p.

Member Function Documentation

◆ addSearchDir()

void Preprocessor::addSearchDir ( const QCString & dir)

Definition at line 4135 of file pre.l.

4136{
4137 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4138 FileInfo fi(dir.str());
4139 if (fi.isDir()) state->pathList.push_back(fi.absFilePath());
4140}
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 4153 of file pre.l.

4154{
4155 AUTO_TRACE("fileName={}",fileName);
4156 yyscan_t yyscanner = p->yyscanner;
4157 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
4158 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4159
4160#ifdef FLEX_DEBUG
4161 preYYset_debug(Debug::isFlagSet(Debug::Lex_pre)?1:0,yyscanner);
4162#endif
4163
4164 DebugLex debugLex(Debug::Lex_pre, __FILE__, qPrint(fileName));
4165 //printf("##########################\n%s\n####################\n",
4166 // qPrint(input));
4167
4168 state->macroExpansion = Config_getBool(MACRO_EXPANSION);
4169 state->expandOnlyPredef = Config_getBool(EXPAND_ONLY_PREDEF);
4170 state->skip=FALSE;
4171 state->curlyCount=0;
4172 state->lexRulesPart=false;
4173 state->nospaces=FALSE;
4174 state->inputBuf=&input;
4175 state->inputBufPos=0;
4176 state->outputBuf=&output;
4177 state->includeStack.clear();
4178 state->expandedDict.clear();
4179 state->contextDefines.clear();
4180 state->pragmaSet.clear();
4181 while (!state->condStack.empty()) state->condStack.pop();
4182
4183 setFileName(yyscanner,fileName);
4184
4185 state->inputFileDef = state->yyFileDef;
4186 //yyextra->defineManager.startContext(state->fileName);
4187
4188 initPredefined(yyscanner,fileName);
4189
4190 state->yyLineNr = 1;
4191 state->yyColNr = 1;
4192 state->ifcount = 0;
4193
4194 BEGIN( Start );
4195
4196 state->expectGuard = guessSection(fileName).isHeader();
4197 state->guardName.clear();
4198 state->lastGuardName.clear();
4199 state->guardExpr.clear();
4200
4201 preYYlex(yyscanner);
4202
4203 while (!state->condStack.empty())
4204 {
4205 const std::unique_ptr<preYY_CondCtx> &ctx = state->condStack.top();
4206 QCString sectionInfo = " ";
4207 if (ctx->sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",qPrint(ctx->sectionId.stripWhiteSpace()));
4208 warn(ctx->fileName,ctx->lineNr,"Conditional section{}does not have "
4209 "a corresponding \\endcond command within this file.",sectionInfo);
4210 state->condStack.pop();
4211 }
4212 // make sure we don't extend a \cond with missing \endcond over multiple files (see bug 624829)
4213 forceEndCondSection(yyscanner);
4214
4215 if (!state->levelGuard.empty())
4216 {
4217 warn(state->fileName,state->yyLineNr,"More #if's than #endif's found (might be in an included file).");
4218 }
4219
4221 {
4222 std::lock_guard<std::mutex> lock(g_debugMutex);
4223 Debug::print(Debug::Preprocessor,0,"Preprocessor output of {} (size: {} bytes):\n",fileName,output.size());
4224 std::string contents;
4226 {
4227 contents=output;
4228 }
4229 else // need to add line numbers
4230 {
4231 int line=1;
4232 bool startOfLine = true;
4233 size_t content_size = output.size() +
4234 output.size()*6/40; // assuming 40 chars per line on average
4235 // and 6 chars extra for the line number
4236 contents.reserve(content_size);
4237 size_t pos=0;
4238 while (pos<output.size())
4239 {
4240 if (startOfLine)
4241 {
4242 char lineNrStr[15];
4243 snprintf(lineNrStr,15,"%05d ",line++);
4244 contents+=lineNrStr;
4245 }
4246 contents += output[pos];
4247 startOfLine = output[pos]=='\n';
4248 pos++;
4249 }
4250 }
4251 char end[2]={0,0};
4252 if (!contents.empty() && contents[contents.length()-1]!='\n')
4253 {
4254 end[0]='\n';
4255 }
4256 Debug::print(Debug::Preprocessor,0,"---------\n{}{}---------\n",contents,end);
4257 if (yyextra->contextDefines.size()>0)
4258 {
4259 Debug::print(Debug::Preprocessor,0,"Macros accessible in this file ({}):\n", fileName);
4260 Debug::print(Debug::Preprocessor,0,"---------\n");
4261 for (auto &kv : yyextra->contextDefines)
4262 {
4263 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4264 }
4265 for (auto &kv : yyextra->localDefines)
4266 {
4267 Debug::print(Debug::Preprocessor,0,"{} ",kv.second.name);
4268 }
4269 Debug::print(Debug::Preprocessor,0,"\n---------\n");
4270 }
4271 else
4272 {
4273 Debug::print(Debug::Preprocessor,0,"No macros accessible in this file ({}).\n", fileName);
4274 }
4275 }
4276
4277 {
4278 std::lock_guard<std::mutex> lock(g_updateGlobals);
4279 for (const auto &inc : state->includeRelations)
4280 {
4281 auto toKind = [](bool local,bool imported) -> IncludeKind
4282 {
4283 if (local)
4284 {
4285 if (imported)
4286 {
4288 }
4290 }
4291 else if (imported)
4292 {
4294 }
4296 };
4297 if (inc->fromFileDef)
4298 {
4299 inc->fromFileDef->addIncludeDependency(inc->toFileDef,inc->includeName,toKind(inc->local,inc->imported));
4300 }
4301 if (inc->toFileDef && inc->fromFileDef)
4302 {
4303 inc->toFileDef->addIncludedByDependency(inc->fromFileDef,inc->fromFileDef->docName(),toKind(inc->local,inc->imported));
4304 }
4305 }
4306 // add the macro definition for this file to the global map
4307 Doxygen::macroDefinitions.emplace(state->fileName.str(),std::move(state->macroDefinitions));
4308 }
4309
4310 //yyextra->defineManager.endContext();
4311}
@ 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:136
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:4008
static void setFileName(yyscan_t yyscanner, const QCString &name)
Definition pre.l:2223
static void forceEndCondSection(yyscan_t yyscanner)
Definition pre.l:3864
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:339

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: