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;
|
||||
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "path.h"
|
||||
#include "symboldatabase.h"
|
||||
#include "templatesimplifier.h"
|
||||
#include "preprocessor.h" // Preprocessor::macroChar
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue