Skip to main content

The Preprocessor Class Reference

Declaration

class Preprocessor { ... }

Included Headers

#include <src/pre.h>

Public Constructors Index

Preprocessor ()

Public Destructor Index

~Preprocessor ()

Public Member Functions Index

voidprocessFile (const QCString &fileName, const std::string &input, std::string &output)
voidaddSearchDir (const QCString &dir)

Private Member Attributes Index

std::unique_ptr< Private >p

Definition at line 27 of file pre.h.

Public Constructors

Preprocessor()

Preprocessor::Preprocessor ()

Declaration at line 30 of file pre.h, definition at line 4000 of file pre.l.

4000Preprocessor::Preprocessor() : p(std::make_unique<Private>())
4001{
4002 preYYlex_init_extra(&p->state,&p->yyscanner);
4003 addSearchDir(".");
4004}

References addSearchDir and p.

Public Destructor

~Preprocessor()

Preprocessor::~Preprocessor ()

Declaration at line 31 of file pre.h, definition at line 4006 of file pre.l.

4007{
4008 preYYlex_destroy(p->yyscanner);
4009}

Reference p.

Public Member Functions

addSearchDir()

void Preprocessor::addSearchDir (const QCString & dir)

Declaration at line 35 of file pre.h, definition at line 3993 of file pre.l.

3994{
3995 YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
3996 FileInfo fi(dir.str());
3997 if (fi.isDir()) state->pathList.push_back(fi.absFilePath());
3998}

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)

Declaration at line 34 of file pre.h, definition at line 4011 of file pre.l.

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

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.

Private Member Attributes

p

std::unique_ptr<Private> Preprocessor::p

Definition at line 38 of file pre.h.

38 std::unique_ptr<Private> p;

Referenced by addSearchDir, Preprocessor, processFile and ~Preprocessor.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus by Doxygen 1.14.0.