summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-06-15 15:38:20 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2009-06-15 15:39:20 +0200
commite2a0a4d7c572f0d2771731d48ea33b9925c58f1e (patch)
tree92d7f52d4a50dc5286ecc3cea69b00100bc548b7 /src/libs/cplusplus
parentdbba0ff8d7456de3d8e7cc2796c48fcbc700acf1 (diff)
downloadqt-creator-e2a0a4d7c572f0d2771731d48ea33b9925c58f1e.tar.gz
Keep the original encoded text around while preprocessing.
Diffstat (limited to 'src/libs/cplusplus')
-rw-r--r--src/libs/cplusplus/CppDocument.cpp2
-rw-r--r--src/libs/cplusplus/CppDocument.h2
-rw-r--r--src/libs/cplusplus/FastPreprocessor.cpp2
-rw-r--r--src/libs/cplusplus/FastPreprocessor.h2
-rw-r--r--src/libs/cplusplus/pp-engine.cpp27
-rw-r--r--src/libs/cplusplus/pp-engine.h14
6 files changed, 35 insertions, 14 deletions
diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp
index 540f386d53..619b70799f 100644
--- a/src/libs/cplusplus/CppDocument.cpp
+++ b/src/libs/cplusplus/CppDocument.cpp
@@ -356,7 +356,7 @@ void Snapshot::insert(Document::Ptr doc)
insert(doc->fileName(), doc);
}
-QByteArray Snapshot::preprocessedCode(const QByteArray &source, const QString &fileName) const
+QByteArray Snapshot::preprocessedCode(const QString &source, const QString &fileName) const
{
FastPreprocessor pp(*this);
return pp.run(fileName, source);
diff --git a/src/libs/cplusplus/CppDocument.h b/src/libs/cplusplus/CppDocument.h
index 71d203f88a..33aeec6f26 100644
--- a/src/libs/cplusplus/CppDocument.h
+++ b/src/libs/cplusplus/CppDocument.h
@@ -272,7 +272,7 @@ public:
Snapshot();
~Snapshot();
- QByteArray preprocessedCode(const QByteArray &source,
+ QByteArray preprocessedCode(const QString &source,
const QString &fileName) const;
Document::Ptr documentFromSource(const QByteArray &preprocessedCode,
diff --git a/src/libs/cplusplus/FastPreprocessor.cpp b/src/libs/cplusplus/FastPreprocessor.cpp
index 09afbaf340..4472949bc5 100644
--- a/src/libs/cplusplus/FastPreprocessor.cpp
+++ b/src/libs/cplusplus/FastPreprocessor.cpp
@@ -36,7 +36,7 @@ FastPreprocessor::FastPreprocessor(const Snapshot &snapshot)
_preproc(this, &_env)
{ }
-QByteArray FastPreprocessor::run(QString fileName, const QByteArray &source)
+QByteArray FastPreprocessor::run(QString fileName, const QString &source)
{
const QByteArray preprocessed = _preproc(fileName, source);
return preprocessed;
diff --git a/src/libs/cplusplus/FastPreprocessor.h b/src/libs/cplusplus/FastPreprocessor.h
index fc4a2e6304..0c0e0831dd 100644
--- a/src/libs/cplusplus/FastPreprocessor.h
+++ b/src/libs/cplusplus/FastPreprocessor.h
@@ -51,7 +51,7 @@ class CPLUSPLUS_EXPORT FastPreprocessor: public Client
public:
FastPreprocessor(const Snapshot &snapshot);
- QByteArray run(QString fileName, const QByteArray &source);
+ QByteArray run(QString fileName, const QString &source);
// CPlusPlus::Client
virtual void sourceNeeded(QString &fileName, IncludeType, unsigned)
diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp
index 239db98545..2714e28405 100644
--- a/src/libs/cplusplus/pp-engine.cpp
+++ b/src/libs/cplusplus/pp-engine.cpp
@@ -564,11 +564,21 @@ void Preprocessor::popState()
_savedStates.removeLast();
}
-QByteArray Preprocessor::operator()(const QString &filename,
+QByteArray Preprocessor::operator()(const QString &fileName, const QString &source)
+{
+ const QString previousOriginalSource = _originalSource;
+ _originalSource = source;
+ const QByteArray bytes = source.toLatin1();
+ const QByteArray preprocessedCode = operator()(fileName, bytes);
+ _originalSource = previousOriginalSource;
+ return preprocessedCode;
+}
+
+QByteArray Preprocessor::operator()(const QString &fileName,
const QByteArray &source)
{
QByteArray preprocessed;
- preprocess(filename, source, &preprocessed);
+ preprocess(fileName, source, &preprocessed);
return preprocessed;
}
@@ -1098,7 +1108,7 @@ void Preprocessor::processInclude(bool, TokenIterator firstToken,
const char *beginOfPath = endOfToken(*start);
const char *endOfPath = startOfToken(*tk);
- QString fn = QString::fromUtf8(beginOfPath, endOfPath - beginOfPath);
+ QString fn = string(beginOfPath, endOfPath - beginOfPath);
client->sourceNeeded(fn, Client::IncludeGlobal, firstToken->lineno);
} else if (tk->is(T_ANGLE_STRING_LITERAL) || tk->is(T_STRING_LITERAL)) {
@@ -1111,7 +1121,7 @@ void Preprocessor::processInclude(bool, TokenIterator firstToken,
if (beginOfPath + 1 != endOfPath && ((quote == '"' && endOfPath[-1] == '"') ||
(quote == '<' && endOfPath[-1] == '>'))) {
- QString fn = QString::fromUtf8(beginOfPath + 1, spell.length() - 2);
+ QString fn = string(beginOfPath + 1, spell.length() - 2);
client->sourceNeeded(fn, Client::IncludeLocal, firstToken->lineno);
}
}
@@ -1422,3 +1432,12 @@ bool Preprocessor::isQtReservedWord(const QByteArray &macroId) const
return true;
return false;
}
+
+QString Preprocessor::string(const char *first, int length) const
+{
+ if (_originalSource.isEmpty())
+ return QString::fromUtf8(first, length);
+
+ const int position = first - _source.constData();
+ return _originalSource.mid(position, length);
+}
diff --git a/src/libs/cplusplus/pp-engine.h b/src/libs/cplusplus/pp-engine.h
index 46ea0bc061..9930a59ceb 100644
--- a/src/libs/cplusplus/pp-engine.h
+++ b/src/libs/cplusplus/pp-engine.h
@@ -50,25 +50,23 @@
#define CPLUSPLUS_PP_ENGINE_H
#include "PreprocessorClient.h"
+#include "pp-macro-expander.h"
#include <Token.h>
#include <QVector>
namespace CPlusPlus {
- class Token;
-}
-
-namespace CPlusPlus {
struct Value;
+class Environment;
class CPLUSPLUS_EXPORT Preprocessor
{
public:
Preprocessor(Client *client, Environment *env);
- QByteArray operator()(const QString &filename,
- const QByteArray &source);
+ QByteArray operator()(const QString &filename, const QString &source);
+ QByteArray operator()(const QString &filename, const QByteArray &source);
void preprocess(const QString &filename,
const QByteArray &source,
@@ -169,6 +167,8 @@ private:
void out(char ch);
void out(const char *s);
+ QString string(const char *first, int len) const;
+
private:
Client *client;
Environment *env;
@@ -186,6 +186,8 @@ private:
QByteArray *_result;
bool _markGeneratedTokens;
+
+ QString _originalSource;
};
} // namespace CPlusPlus