Preprocessor: don't insert macroChar inside .1 and 1. tokens

This commit is contained in:
Daniel Marjamäki 2014-01-02 11:21:23 +01:00
parent a1b0d190df
commit 2f91539d1d
2 changed files with 20 additions and 1 deletions

View File

@ -3151,7 +3151,18 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
chr = !chr;
else if (str || chr)
continue;
else if (std::isalnum(macrocode[i]) || macrocode[i] == '_') {
else if (macrocode[i] == '.') { // 5. / .5
if ((i > 0U && std::isdigit(macrocode[i-1])) ||
(i+1 < macrocode.size() && std::isdigit(macrocode[i+1]))) {
if (i > 0U && !std::isdigit(macrocode[i-1])) {
macrocode.insert(i, 1U, macroChar);
i++;
}
i++;
if (i<macrocode.size() && std::isdigit(macrocode[i]))
i++;
}
} else if (std::isalnum(macrocode[i]) || macrocode[i] == '_') {
if ((i > 0U) &&
(!std::isalnum(macrocode[i-1])) &&
(macrocode[i-1] != '_') &&

View File

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