Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions externals/simplecpp/simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3333,13 +3333,23 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
const std::string &macrostr = *it;
const std::string::size_type eq = macrostr.find('=');
const std::string::size_type par = macrostr.find('(');
const std::string::size_type useMName = macrostr.find("_~");
const std::string macroname = macrostr.substr(0, std::min(eq,par));
if (macroname == "__STRICT_ANSI__")
strictAnsiDefined = true;
if (dui.undefined.find(macroname) != dui.undefined.end())
continue;
const std::string lhs(macrostr.substr(0,eq));
const std::string rhs(eq==std::string::npos ? std::string("1") : macrostr.substr(eq+1));
std::string lhs;
std::string rhs;
if (useMName != std::string::npos) {
//Define macro as itself or to specified value
lhs.assign(macrostr.substr(0, useMName));
rhs.assign(eq == std::string::npos ? lhs : macrostr.substr(eq + 1));
} else {
//Define macro as 1 or to specified value
lhs.assign(macrostr.substr(0, eq));
rhs.assign(eq == std::string::npos ? std::string("1") : macrostr.substr(eq + 1));
}
const Macro macro(lhs, rhs, dummy);
macros.insert(std::pair<TokenString,Macro>(macro.name(), macro));
}
Expand Down
4 changes: 3 additions & 1 deletion lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
if (dtok->op == '(')
dtok = dtok->next;
if (sameline(iftok,dtok) && dtok->name && defined.find(dtok->str()) == defined.end() && undefined.find(dtok->str()) == undefined.end())
configset.insert(dtok->str());
configset.insert(dtok->str() + "=" + dtok->str()); // if defined is set to itself.
}
std::string cfgStr;
for (const std::string &s : configset) {
Expand Down Expand Up @@ -553,6 +553,8 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
const simplecpp::Token *expr1 = cmdtok->next;
if (sameline(tok,expr1) && expr1->name && !sameline(tok,expr1->next))
config = expr1->str();
if (cmdtok->str() == "ifdef")
config.append("=" + expr1->str()); //ifdef:S shall be defined as itself
if (defined.find(config) != defined.end())
config.clear();
} else if (cmdtok->str() == "if") {
Expand Down
Loading