From 6b5c9cc7cb5663c55281b390c6a9402ced5512b2 Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Mon, 2 Mar 2009 18:08:43 +0100 Subject: [PATCH] Cleanup --- .../cplusplus/PreprocessorEnvironment.cpp | 16 +++++++++++----- src/libs/cplusplus/PreprocessorEnvironment.h | 19 +++++++------------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/libs/cplusplus/PreprocessorEnvironment.cpp b/src/libs/cplusplus/PreprocessorEnvironment.cpp index 624c6f33fc4..3320e2e6463 100644 --- a/src/libs/cplusplus/PreprocessorEnvironment.cpp +++ b/src/libs/cplusplus/PreprocessorEnvironment.cpp @@ -97,7 +97,7 @@ Macro *Environment::bind(const Macro &__macro) else _allocated_macros <<= 1; - _macros = (Macro **) realloc(_macros, sizeof(Macro *) * _allocated_macros); + _macros = reinterpret_cast<Macro **>(realloc(_macros, sizeof(Macro *) * _allocated_macros)); } _macros[_macro_count] = m; @@ -147,7 +147,7 @@ void Environment::reset() _hash_count = 401; } -bool Environment::isBuiltinMacro(const QByteArray &s) const +bool Environment::isBuiltinMacro(const QByteArray &s) { if (s.length() != 8) return false; @@ -211,6 +211,12 @@ bool Environment::isBuiltinMacro(const QByteArray &s) const return false; } +Environment::iterator Environment::firstMacro() const +{ return _macros; } + +Environment::iterator Environment::lastMacro() const +{ return _macros + _macro_count + 1; } + Macro *Environment::resolve(const QByteArray &name) const { if (! _macros) @@ -244,10 +250,10 @@ void Environment::rehash() _hash_count <<= 1; } - _hash = (Macro **) calloc(_hash_count, sizeof(Macro *)); + _hash = reinterpret_cast<Macro **>(calloc(_hash_count, sizeof(Macro *))); - for (Macro **it = firstMacro(); it != lastMacro(); ++it) { - Macro *m= *it; + for (iterator it = firstMacro(); it != lastMacro(); ++it) { + Macro *m = *it; const unsigned h = m->_hashcode % _hash_count; m->_next = _hash[h]; _hash[h] = m; diff --git a/src/libs/cplusplus/PreprocessorEnvironment.h b/src/libs/cplusplus/PreprocessorEnvironment.h index 1be77ac3360..231a88af015 100644 --- a/src/libs/cplusplus/PreprocessorEnvironment.h +++ b/src/libs/cplusplus/PreprocessorEnvironment.h @@ -61,6 +61,9 @@ class Macro; class CPLUSPLUS_EXPORT Environment { +public: + typedef Macro **iterator; + public: Environment(); ~Environment(); @@ -72,23 +75,15 @@ public: Macro *remove(const QByteArray &name); Macro *resolve(const QByteArray &name) const; - bool isBuiltinMacro(const QByteArray &name) const; - - const Macro *const *firstMacro() const - { return _macros; } - Macro **firstMacro() - { return _macros; } - - const Macro *const *lastMacro() const - { return _macros + _macro_count + 1; } - - Macro **lastMacro() - { return _macros + _macro_count + 1; } + iterator firstMacro() const; + iterator lastMacro() const; void reset(); void addMacros(const QList<Macro> ¯os); + static bool isBuiltinMacro(const QByteArray &name); + private: static unsigned hashCode(const QByteArray &s); void rehash(); -- GitLab