diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index e747ab837..5136efbce 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -35,6 +35,8 @@ bool Preprocessor::missingIncludeFlag; +char Preprocessor::macroChar = char(1); + Preprocessor::Preprocessor(Settings *settings, ErrorLogger *errorLogger) : _settings(settings), _errorLogger(errorLogger) { @@ -2759,7 +2761,7 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file macrocode.append(1,' '); // insert expanded macro code - line.insert(pos1, "$" + macrocode); + line.insert(pos1, macroChar + macrocode); // position = start position. pos = pos1; diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 19763995f..461269601 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -49,6 +49,9 @@ public: SystemHeader }; + /** character that is inserted in expanded macros */ + static char macroChar; + Preprocessor(Settings *settings = 0, ErrorLogger *errorLogger = 0); static bool missingIncludeFlag; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a6835c00d..63b901806 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -27,6 +27,7 @@ #include "path.h" #include "symboldatabase.h" #include "templatesimplifier.h" +#include "preprocessor.h" // Preprocessor::macroChar #include #include @@ -293,8 +294,8 @@ void Tokenizer::createTokens(std::istream &code) // Read one byte at a time from code and create tokens for (char ch = (char)code.get(); code.good(); ch = (char)code.get()) { - if (ch == '$') { - while (code.peek() == '$') + if (ch == Preprocessor::macroChar) { + while (code.peek() == Preprocessor::macroChar) code.get(); ch = ' '; expandedMacro = true; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index a6e2d5f92..89d785d9c 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -36,8 +36,9 @@ extern std::ostringstream output; class TestPreprocessor : public TestFixture { public: - TestPreprocessor() : TestFixture("TestPreprocessor") - { } + TestPreprocessor() : TestFixture("TestPreprocessor") { + Preprocessor::macroChar = '$'; + } class OurPreprocessor : public Preprocessor { public: @@ -256,6 +257,7 @@ private: TEST_CASE(undef8); TEST_CASE(undef9); + TEST_CASE(macroChar); } @@ -3422,6 +3424,14 @@ private: ASSERT_EQUALS(1U, actual.size()); ASSERT_EQUALS("\n\nFred & Wilma\n\n\n\n", actual[""]); } + + void macroChar() { + const char filedata[] = "#define X 1\nX\n"; + ASSERT_EQUALS("\n$1\n", OurPreprocessor::expandMacros(filedata,NULL)); + OurPreprocessor::macroChar = '¤'; + ASSERT_EQUALS("\n¤1\n", OurPreprocessor::expandMacros(filedata,NULL)); + OurPreprocessor::macroChar = '$'; + } }; REGISTER_TEST(TestPreprocessor)