MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / preprocess

Method preprocess

externals/simplecpp/simplecpp.cpp:3342–3876  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3340}
3341
3342void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, simplecpp::FileDataCache &cache, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage, std::list<simplecpp::IfCond> *ifCond)
3343{
3344#ifdef SIMPLECPP_WINDOWS
3345 if (dui.clearIncludeCache)
3346 nonExistingFilesCache.clear();
3347#endif
3348
3349 std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType);
3350 sizeOfType.insert(std::make_pair("char", sizeof(char)));
3351 sizeOfType.insert(std::make_pair("short", sizeof(short)));
3352 sizeOfType.insert(std::make_pair("short int", sizeOfType["short"]));
3353 sizeOfType.insert(std::make_pair("int", sizeof(int)));
3354 sizeOfType.insert(std::make_pair("long", sizeof(long)));
3355 sizeOfType.insert(std::make_pair("long int", sizeOfType["long"]));
3356 sizeOfType.insert(std::make_pair("long long", sizeof(long long)));
3357 sizeOfType.insert(std::make_pair("float", sizeof(float)));
3358 sizeOfType.insert(std::make_pair("double", sizeof(double)));
3359 sizeOfType.insert(std::make_pair("long double", sizeof(long double)));
3360 sizeOfType.insert(std::make_pair("char *", sizeof(char *)));
3361 sizeOfType.insert(std::make_pair("short *", sizeof(short *)));
3362 sizeOfType.insert(std::make_pair("short int *", sizeOfType["short *"]));
3363 sizeOfType.insert(std::make_pair("int *", sizeof(int *)));
3364 sizeOfType.insert(std::make_pair("long *", sizeof(long *)));
3365 sizeOfType.insert(std::make_pair("long int *", sizeOfType["long *"]));
3366 sizeOfType.insert(std::make_pair("long long *", sizeof(long long *)));
3367 sizeOfType.insert(std::make_pair("float *", sizeof(float *)));
3368 sizeOfType.insert(std::make_pair("double *", sizeof(double *)));
3369 sizeOfType.insert(std::make_pair("long double *", sizeof(long double *)));
3370
3371 // use a dummy vector for the macros because as this is not part of the file and would add an empty entry - e.g. /usr/include/poll.h
3372 std::vector<std::string> dummy;
3373
3374 const bool hasInclude = isCpp17OrLater(dui) || isGnu(dui);
3375 MacroMap macros;
3376 bool strictAnsiDefined = false;
3377 for (auto it = dui.defines.cbegin(); it != dui.defines.cend(); ++it) {
3378 const std::string &macrostr = *it;
3379 const std::string::size_type eq = macrostr.find('=');
3380 const std::string::size_type par = macrostr.find('(');
3381 const std::string macroname = macrostr.substr(0, std::min(eq,par));
3382 if (macroname == "__STRICT_ANSI__")
3383 strictAnsiDefined = true;
3384 if (dui.undefined.find(macroname) != dui.undefined.end())
3385 continue;
3386 const std::string lhs(macrostr.substr(0,eq));
3387 const std::string rhs(eq==std::string::npos ? std::string("1") : macrostr.substr(eq+1));
3388 try {
3389 const Macro macro(lhs, rhs, dummy);
3390 macros.insert(std::pair<TokenString,Macro>(macro.name(), macro));
3391 } catch (const std::runtime_error& e) {
3392 if (outputList) {
3393 simplecpp::Output err{
3394 Output::DUI_ERROR,
3395 {},
3396 e.what()
3397 };
3398 outputList->emplace_back(std::move(err));
3399 }

Callers

nothing calls this directly

Calls 15

isCpp17OrLaterFunction · 0.85
isGnuFunction · 0.85
getLocaltimeFunction · 0.85
getDateDefineFunction · 0.85
getTimeDefineFunction · 0.85
gotoNextLineFunction · 0.85
isNameCharFunction · 0.85
preprocessTokenFunction · 0.85
openHeaderFunction · 0.85
frontMethod · 0.80
valueDefinedInCodeMethod · 0.80
MacroClass · 0.70

Tested by

no test coverage detected