summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/PreprocessorEnvironment.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@nokia.com>2012-03-26 15:18:01 +0200
committerErik Verbruggen <erik.verbruggen@nokia.com>2012-03-29 14:28:17 +0200
commit60db5736604583fe99dde3c25412d97f9b77489d (patch)
tree2f5bf1342086232de0570500fd440a98eb12cb96 /src/libs/cplusplus/PreprocessorEnvironment.cpp
parent159058d9eb7ab233f94cc6a0a5b0e7e8f691a041 (diff)
downloadqt-creator-60db5736604583fe99dde3c25412d97f9b77489d.tar.gz
[C++] Rewrite of the preprocessor.
This rewrite fixes a couple of issues with the pre-processor. It now supports: - macros in macro bodies - stringification of parameters [cpp.stringize] - the concatenation operator [cpp.concat] - #include MACRO_HERE - defined() inside macro bodies used in pp-conditions. Change-Id: Ifdb78041fb6afadf44f939a4bd66ce2832b8601f Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/libs/cplusplus/PreprocessorEnvironment.cpp')
-rw-r--r--src/libs/cplusplus/PreprocessorEnvironment.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/libs/cplusplus/PreprocessorEnvironment.cpp b/src/libs/cplusplus/PreprocessorEnvironment.cpp
index 42c3bc04f4..174afe66a7 100644
--- a/src/libs/cplusplus/PreprocessorEnvironment.cpp
+++ b/src/libs/cplusplus/PreprocessorEnvironment.cpp
@@ -150,7 +150,7 @@ void Environment::reset()
_hash_count = 401;
}
-bool Environment::isBuiltinMacro(const QByteArray &s)
+bool Environment::isBuiltinMacro(const Internal::ByteArrayRef &s)
{
if (s.length() != 8)
return false;
@@ -236,6 +236,22 @@ Macro *Environment::resolve(const QByteArray &name) const
return it;
}
+Macro *Environment::resolve(const Internal::ByteArrayRef &name) const
+{
+ if (! _macros)
+ return 0;
+
+ Macro *it = _hash[hashCode(name) % _hash_count];
+ for (; it; it = it->_next) {
+ if (it->name() != name)
+ continue;
+ else if (it->isHidden())
+ return 0;
+ else break;
+ }
+ return it;
+}
+
unsigned Environment::hashCode(const QByteArray &s)
{
unsigned hash_value = 0;
@@ -246,6 +262,16 @@ unsigned Environment::hashCode(const QByteArray &s)
return hash_value;
}
+unsigned Environment::hashCode(const Internal::ByteArrayRef &s)
+{
+ unsigned hash_value = 0;
+
+ for (int i = 0; i < s.length(); ++i)
+ hash_value = (hash_value << 5) - hash_value + s.at(i);
+
+ return hash_value;
+}
+
void Environment::rehash()
{
if (_hash) {