Preprocessor: Don't insert macroChar inside 1.f and 1.e+7 as that mess it up later. Thanks ettlmartin for telling me about this.

This commit is contained in:
Daniel Marjamäki 2013-12-31 10:24:14 +01:00
parent 24a9da3771
commit 7e71c41ba7
2 changed files with 28 additions and 4 deletions

View File

@ -3158,13 +3158,29 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
(macrocode[i-1] != macroChar)) {
macrocode.insert(i, 1U, macroChar);
}
// 1e-7 / 1e+7
if (i+3 < macrocode.size() &&
std::isdigit(macrocode[i]) &&
if (i+3U < macrocode.size() &&
(std::isdigit(macrocode[i]) || macrocode[i]=='.') &&
(macrocode[i+1] == 'e' || macrocode[i+1] == 'E') &&
(macrocode[i+2] == '-' || macrocode[i+2] == '+') &&
std::isdigit(macrocode[i+3]))
i += 3;
std::isdigit(macrocode[i+3])) {
i += 3U;
}
// 1.f / 1.e7
if (i+2U < macrocode.size() &&
std::isdigit(macrocode[i]) &&
macrocode[i+1] == '.' &&
std::isalnum(macrocode[i+2])) {
i += 2U;
if (i+2U < macrocode.size() &&
(macrocode[i+0] == 'e' || macrocode[i+0] == 'E') &&
(macrocode[i+1] == '-' || macrocode[i+1] == '+') &&
std::isdigit(macrocode[i+2])) {
i += 2U;
}
}
}
}
line.insert(pos1, macroChar + macrocode);

View File

@ -1990,6 +1990,14 @@ private:
const char filedata3[] = "#define A (1e+7)\n"
"a=A;";
ASSERT_EQUALS("\na=$($1e+7);", OurPreprocessor::expandMacros(filedata3));
const char filedata4[] = "#define A (1.e+7)\n"
"a=A;";
ASSERT_EQUALS("\na=$($1.e+7);", OurPreprocessor::expandMacros(filedata4));
const char filedata5[] = "#define A (1.7f)\n"
"a=A;";
ASSERT_EQUALS("\na=$($1.7f);", OurPreprocessor::expandMacros(filedata5));
}
void macroInMacro1() {