Fixed #3534 (Broken support for dollar signs in identifiers)
This commit is contained in:
parent
782cd5d228
commit
01ddfb6f80
|
@ -35,6 +35,8 @@
|
||||||
|
|
||||||
bool Preprocessor::missingIncludeFlag;
|
bool Preprocessor::missingIncludeFlag;
|
||||||
|
|
||||||
|
char Preprocessor::macroChar = char(1);
|
||||||
|
|
||||||
Preprocessor::Preprocessor(Settings *settings, ErrorLogger *errorLogger) : _settings(settings), _errorLogger(errorLogger)
|
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,' ');
|
macrocode.append(1,' ');
|
||||||
|
|
||||||
// insert expanded macro code
|
// insert expanded macro code
|
||||||
line.insert(pos1, "$" + macrocode);
|
line.insert(pos1, macroChar + macrocode);
|
||||||
|
|
||||||
// position = start position.
|
// position = start position.
|
||||||
pos = pos1;
|
pos = pos1;
|
||||||
|
|
|
@ -49,6 +49,9 @@ public:
|
||||||
SystemHeader
|
SystemHeader
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** character that is inserted in expanded macros */
|
||||||
|
static char macroChar;
|
||||||
|
|
||||||
Preprocessor(Settings *settings = 0, ErrorLogger *errorLogger = 0);
|
Preprocessor(Settings *settings = 0, ErrorLogger *errorLogger = 0);
|
||||||
|
|
||||||
static bool missingIncludeFlag;
|
static bool missingIncludeFlag;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "symboldatabase.h"
|
#include "symboldatabase.h"
|
||||||
#include "templatesimplifier.h"
|
#include "templatesimplifier.h"
|
||||||
|
#include "preprocessor.h" // Preprocessor::macroChar
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -293,8 +294,8 @@ void Tokenizer::createTokens(std::istream &code)
|
||||||
|
|
||||||
// Read one byte at a time from code and create tokens
|
// Read one byte at a time from code and create tokens
|
||||||
for (char ch = (char)code.get(); code.good(); ch = (char)code.get()) {
|
for (char ch = (char)code.get(); code.good(); ch = (char)code.get()) {
|
||||||
if (ch == '$') {
|
if (ch == Preprocessor::macroChar) {
|
||||||
while (code.peek() == '$')
|
while (code.peek() == Preprocessor::macroChar)
|
||||||
code.get();
|
code.get();
|
||||||
ch = ' ';
|
ch = ' ';
|
||||||
expandedMacro = true;
|
expandedMacro = true;
|
||||||
|
|
|
@ -36,8 +36,9 @@ extern std::ostringstream output;
|
||||||
|
|
||||||
class TestPreprocessor : public TestFixture {
|
class TestPreprocessor : public TestFixture {
|
||||||
public:
|
public:
|
||||||
TestPreprocessor() : TestFixture("TestPreprocessor")
|
TestPreprocessor() : TestFixture("TestPreprocessor") {
|
||||||
{ }
|
Preprocessor::macroChar = '$';
|
||||||
|
}
|
||||||
|
|
||||||
class OurPreprocessor : public Preprocessor {
|
class OurPreprocessor : public Preprocessor {
|
||||||
public:
|
public:
|
||||||
|
@ -256,6 +257,7 @@ private:
|
||||||
TEST_CASE(undef8);
|
TEST_CASE(undef8);
|
||||||
TEST_CASE(undef9);
|
TEST_CASE(undef9);
|
||||||
|
|
||||||
|
TEST_CASE(macroChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3422,6 +3424,14 @@ private:
|
||||||
ASSERT_EQUALS(1U, actual.size());
|
ASSERT_EQUALS(1U, actual.size());
|
||||||
ASSERT_EQUALS("\n\nFred & Wilma\n\n\n\n", actual[""]);
|
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)
|
REGISTER_TEST(TestPreprocessor)
|
||||||
|
|
Loading…
Reference in New Issue