Fixed #1383 (Preprocessor: define - ifndef problem)
This commit is contained in:
parent
0c65796984
commit
29b2be19ab
|
@ -712,7 +712,7 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
|
|||
continue;
|
||||
}
|
||||
|
||||
if (line.compare(0, 8, "#define ") == 0 && line.find("(", 8) == std::string::npos)
|
||||
if (line.compare(0, 8, "#define ") == 0)
|
||||
{
|
||||
if (line.find(" ", 8) == std::string::npos)
|
||||
defines.insert(line.substr(8));
|
||||
|
@ -1219,13 +1219,15 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
|
|||
std::string def = getdef(line, true);
|
||||
std::string ndef = getdef(line, false);
|
||||
|
||||
if (line.compare(0, 8, "#define ") == 0 && line.find("(", 8) == std::string::npos)
|
||||
if (line.compare(0, 8, "#define ") == 0)
|
||||
{
|
||||
std::string::size_type pos = line.find(" ", 8);
|
||||
std::string::size_type pos = line.find_first_of(" (", 8);
|
||||
if (pos == std::string::npos)
|
||||
cfgmap[line.substr(8)] = "";
|
||||
else
|
||||
else if (line[pos] == ' ')
|
||||
cfgmap[line.substr(8, pos - 8)] = line.substr(pos + 1);
|
||||
else
|
||||
cfgmap[line.substr(8, pos - 8)] = "";
|
||||
}
|
||||
|
||||
else if (line.find("#elif ") == 0)
|
||||
|
|
|
@ -178,6 +178,7 @@ private:
|
|||
|
||||
// define and then ifdef
|
||||
TEST_CASE(define_ifdef);
|
||||
TEST_CASE(define_ifndef);
|
||||
TEST_CASE(endfile);
|
||||
|
||||
TEST_CASE(redundant_config);
|
||||
|
@ -2145,6 +2146,25 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void define_ifndef()
|
||||
{
|
||||
const char filedata[] = "#define A(x) (x)\n"
|
||||
"#ifndef A\n"
|
||||
";\n"
|
||||
"#endif\n";
|
||||
|
||||
// Preprocess => actual result..
|
||||
std::istringstream istr(filedata);
|
||||
std::map<std::string, std::string> actual;
|
||||
Preprocessor preprocessor;
|
||||
preprocessor.preprocess(istr, actual, "file.c");
|
||||
|
||||
// Compare results..
|
||||
ASSERT_EQUALS("\n\n\n\n", actual[""]);
|
||||
TODO_ASSERT_EQUALS(1, actual.size());
|
||||
ASSERT_EQUALS(2, actual.size());
|
||||
}
|
||||
|
||||
void redundant_config()
|
||||
{
|
||||
const char filedata[] = "int main() {\n"
|
||||
|
|
Loading…
Reference in New Issue