Commit bdd8cf30 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

introduce ProKey class



while this is actually just an alias for ProString (with explicit
zero-cost conversions only), it nicely illustrates the use of particular
variables. it also serves to hide the NoHash hack from public view.

Change-Id: Iaf9283c64f320ad84a77d9573d1fde6d401c49df
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@nokia.com>
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@nokia.com>
parent c07695a4
......@@ -57,7 +57,7 @@ ProFileEvaluator::~ProFileEvaluator()
bool ProFileEvaluator::contains(const QString &variableName) const
{
return d->m_valuemapStack.top().contains(ProString(variableName));
return d->m_valuemapStack.top().contains(ProKey(variableName));
}
QString ProFileEvaluator::value(const QString &variable) const
......@@ -71,7 +71,7 @@ QString ProFileEvaluator::value(const QString &variable) const
QStringList ProFileEvaluator::values(const QString &variableName) const
{
const ProStringList &values = d->values(ProString(variableName));
const ProStringList &values = d->values(ProKey(variableName));
QStringList ret;
ret.reserve(values.size());
foreach (const ProString &str, values)
......@@ -82,7 +82,7 @@ QStringList ProFileEvaluator::values(const QString &variableName) const
QStringList ProFileEvaluator::values(const QString &variableName, const ProFile *pro) const
{
// It makes no sense to put any kind of magic into expanding these
const ProStringList &values = d->m_valuemapStack.at(0).value(ProString(variableName));
const ProStringList &values = d->m_valuemapStack.at(0).value(ProKey(variableName));
QStringList ret;
ret.reserve(values.size());
foreach (const ProString &str, values)
......@@ -167,7 +167,7 @@ QStringList ProFileEvaluator::absoluteFileValues(
ProFileEvaluator::TemplateType ProFileEvaluator::templateType() const
{
const ProStringList &templ = d->values(ProString("TEMPLATE"));
const ProStringList &templ = d->values(ProKey("TEMPLATE"));
if (templ.count() >= 1) {
const QString &t = templ.at(0).toQString();
if (!t.compare(QLatin1String("app"), Qt::CaseInsensitive))
......@@ -191,7 +191,7 @@ bool ProFileEvaluator::accept(ProFile *pro, QMakeEvaluator::LoadFlags flags)
QString ProFileEvaluator::propertyValue(const QString &name) const
{
return d->m_option->propertyValue(ProString(name)).toQString();
return d->m_option->propertyValue(ProKey(name)).toQString();
}
#ifdef PROEVALUATOR_CUMULATIVE
......
......@@ -36,8 +36,6 @@
QT_BEGIN_NAMESPACE
using namespace ProStringConstants;
// from qhash.cpp
uint ProString::hash(const QChar *p, int n)
{
......@@ -66,29 +64,29 @@ ProString::ProString(const ProString &other, OmitPreHashing) :
{
}
ProString::ProString(const QString &str) :
ProString::ProString(const QString &str, DoPreHashing) :
m_string(str), m_offset(0), m_length(str.length()), m_file(0)
{
updatedHash();
}
ProString::ProString(const QString &str, OmitPreHashing) :
ProString::ProString(const QString &str) :
m_string(str), m_offset(0), m_length(str.length()), m_file(0), m_hash(0x80000000)
{
}
ProString::ProString(const char *str) :
ProString::ProString(const char *str, DoPreHashing) :
m_string(QString::fromLatin1(str)), m_offset(0), m_length(qstrlen(str)), m_file(0)
{
updatedHash();
}
ProString::ProString(const char *str, OmitPreHashing) :
ProString::ProString(const char *str) :
m_string(QString::fromLatin1(str)), m_offset(0), m_length(qstrlen(str)), m_file(0), m_hash(0x80000000)
{
}
ProString::ProString(const QString &str, int offset, int length) :
ProString::ProString(const QString &str, int offset, int length, DoPreHashing) :
m_string(str), m_offset(offset), m_length(length), m_file(0)
{
updatedHash();
......@@ -99,18 +97,12 @@ ProString::ProString(const QString &str, int offset, int length, uint hash) :
{
}
ProString::ProString(const QString &str, int offset, int length, ProStringConstants::OmitPreHashing) :
ProString::ProString(const QString &str, int offset, int length) :
m_string(str), m_offset(offset), m_length(length), m_file(0), m_hash(0x80000000)
{
}
void ProString::setValue(const QString &str)
{
m_string = str, m_offset = 0, m_length = str.length();
updatedHash();
}
void ProString::setValue(const QString &str, OmitPreHashing)
{
m_string = str, m_offset = 0, m_length = str.length(), m_hash = 0x80000000;
}
......@@ -127,6 +119,32 @@ uint qHash(const ProString &str)
return str.updatedHash();
}
ProKey::ProKey(const QString &str) :
ProString(str, DoHash)
{
}
ProKey::ProKey(const char *str) :
ProString(str, DoHash)
{
}
ProKey::ProKey(const QString &str, int off, int len) :
ProString(str, off, len, DoHash)
{
}
ProKey::ProKey(const QString &str, int off, int len, uint hash) :
ProString(str, off, len, hash)
{
}
void ProKey::setValue(const QString &str)
{
m_string = str, m_offset = 0, m_length = str.length();
updatedHash();
}
QString ProString::toQString() const
{
return m_string.mid(m_offset, m_length);
......@@ -188,7 +206,7 @@ QChar *ProString::prepareAppend(int extraLen)
QChar *ptr = (QChar *)neu.constData();
memcpy(ptr, m_string.constData() + m_offset, m_length * 2);
ptr += m_length;
*this = ProString(neu, NoHash);
*this = ProString(neu);
return ptr;
}
}
......
......@@ -52,10 +52,7 @@ private:
};
#endif
namespace ProStringConstants {
enum OmitPreHashing { NoHash };
}
class ProKey;
class ProStringList;
class ProFile;
......@@ -63,16 +60,10 @@ class ProString {
public:
ProString();
ProString(const ProString &other);
ProString(const ProString &other, ProStringConstants::OmitPreHashing);
explicit ProString(const QString &str);
ProString(const QString &str, ProStringConstants::OmitPreHashing);
explicit ProString(const char *str);
ProString(const char *str, ProStringConstants::OmitPreHashing);
ProString(const QString &str, int offset, int length);
ProString(const QString &str, int offset, int length, uint hash);
ProString(const QString &str, int offset, int length, ProStringConstants::OmitPreHashing);
void setValue(const QString &str);
void setValue(const QString &str, ProStringConstants::OmitPreHashing);
ProString &setSource(const ProString &other) { m_file = other.m_file; return *this; }
ProString &setSource(const ProFile *pro) { m_file = pro; return *this; }
const ProFile *sourceFile() const { return m_file; }
......@@ -99,7 +90,22 @@ public:
static uint hash(const QChar *p, int n);
ALWAYS_INLINE ProKey &toKey() { return *(ProKey *)this; }
ALWAYS_INLINE const ProKey &toKey() const { return *(const ProKey *)this; }
private:
ProString(const ProKey &other);
ProString &operator=(const ProKey &other);
enum OmitPreHashing { NoHash };
ProString(const ProString &other, OmitPreHashing);
enum DoPreHashing { DoHash };
ALWAYS_INLINE ProString(const QString &str, DoPreHashing);
ALWAYS_INLINE ProString(const char *str, DoPreHashing);
ALWAYS_INLINE ProString(const QString &str, int offset, int length, DoPreHashing);
ALWAYS_INLINE ProString(const QString &str, int offset, int length, uint hash);
QString m_string;
int m_offset, m_length;
const ProFile *m_file;
......@@ -108,15 +114,33 @@ private:
uint updatedHash() const;
friend uint qHash(const ProString &str);
friend QString operator+(const ProString &one, const ProString &two);
friend class ProKey;
};
Q_DECLARE_TYPEINFO(ProString, Q_MOVABLE_TYPE);
class ProKey : public ProString {
public:
ALWAYS_INLINE ProKey() : ProString() {}
explicit ProKey(const QString &str);
explicit ProKey(const char *str);
ProKey(const QString &str, int off, int len);
ProKey(const QString &str, int off, int len, uint hash);
void setValue(const QString &str);
ALWAYS_INLINE ProString &toString() { return *(ProString *)this; }
ALWAYS_INLINE const ProString &toString() const { return *(const ProString *)this; }
private:
ProKey(const ProString &other);
};
Q_DECLARE_TYPEINFO(ProKey, Q_MOVABLE_TYPE);
uint qHash(const ProString &str);
QString operator+(const ProString &one, const ProString &two);
inline QString operator+(const ProString &one, const QString &two)
{ return one + ProString(two, ProStringConstants::NoHash); }
{ return one + ProString(two); }
inline QString operator+(const QString &one, const ProString &two)
{ return ProString(one, ProStringConstants::NoHash) + two; }
{ return ProString(one) + two; }
class ProStringList : public QVector<ProString> {
public:
......@@ -127,7 +151,7 @@ public:
QStringList toQStringList() const;
};
typedef QHash<ProString, ProStringList> ProValueMap;
typedef QHash<ProKey, ProStringList> ProValueMap;
// These token definitions affect both ProFileEvaluator and ProWriter
enum ProToken {
......@@ -250,8 +274,8 @@ private:
Q_DECLARE_TYPEINFO(ProFunctionDef, Q_MOVABLE_TYPE);
struct ProFunctionDefs {
QHash<ProString, ProFunctionDef> testFunctions;
QHash<ProString, ProFunctionDef> replaceFunctions;
QHash<ProKey, ProFunctionDef> testFunctions;
QHash<ProKey, ProFunctionDef> replaceFunctions;
};
QT_END_NAMESPACE
......
This diff is collapsed.
This diff is collapsed.
......@@ -89,10 +89,10 @@ public:
QMakeHandler *handler);
~QMakeEvaluator();
ProStringList values(const ProString &variableName) const;
ProStringList &valuesRef(const ProString &variableName);
ProString first(const ProString &variableName) const;
ProString propertyValue(const ProString &val) const;
ProStringList values(const ProKey &variableName) const;
ProStringList &valuesRef(const ProKey &variableName);
ProString first(const ProKey &variableName) const;
ProString propertyValue(const ProKey &val) const;
enum VisitReturn {
ReturnFalse,
......@@ -108,7 +108,7 @@ public:
static ALWAYS_INLINE uint getBlockLen(const ushort *&tokPtr);
ProString getStr(const ushort *&tokPtr);
ProString getHashStr(const ushort *&tokPtr);
ProKey getHashStr(const ushort *&tokPtr);
void evaluateExpression(const ushort *&tokPtr, ProStringList *ret, bool joined);
static ALWAYS_INLINE void skipStr(const ushort *&tokPtr);
static ALWAYS_INLINE void skipHashStr(const ushort *&tokPtr);
......@@ -124,13 +124,14 @@ public:
LoadFlags flags);
VisitReturn visitProBlock(ProFile *pro, const ushort *tokPtr);
VisitReturn visitProBlock(const ushort *tokPtr);
VisitReturn visitProLoop(const ProString &variable, const ushort *exprPtr,
VisitReturn visitProLoop(const ProKey &variable, const ushort *exprPtr,
const ushort *tokPtr);
void visitProFunctionDef(ushort tok, const ProString &name, const ushort *tokPtr);
void visitProFunctionDef(ushort tok, const ProKey &name, const ushort *tokPtr);
void visitProVariable(ushort tok, const ProStringList &curr, const ushort *&tokPtr);
const ProString &map(const ProString &var);
ProValueMap *findValues(const ProString &variableName, ProValueMap::Iterator *it);
ALWAYS_INLINE const ProKey &map(const ProString &var) { return map(var.toKey()); }
const ProKey &map(const ProKey &var);
ProValueMap *findValues(const ProKey &variableName, ProValueMap::Iterator *it);
void setTemplate();
......@@ -167,8 +168,8 @@ public:
const QList<ProStringList> &argumentsList,
const ProString &function);
ProStringList evaluateExpandFunction(const ProString &function, const ushort *&tokPtr);
VisitReturn evaluateConditionalFunction(const ProString &function, const ushort *&tokPtr);
ProStringList evaluateExpandFunction(const ProKey &function, const ushort *&tokPtr);
VisitReturn evaluateConditionalFunction(const ProKey &function, const ushort *&tokPtr);
bool evaluateConditional(const QString &cond, const QString &context);
#ifdef PROEVALUATOR_FULL
......@@ -182,7 +183,7 @@ public:
void populateDeps(
const ProStringList &deps, const ProString &prefix,
QHash<ProString, QSet<ProString> > &dependencies,
QHash<ProKey, QSet<ProKey> > &dependencies,
ProValueMap &dependees, ProStringList &rootSet) const;
VisitReturn writeFile(const QString &ctx, const QString &fn, QIODevice::OpenMode mode,
......
......@@ -43,20 +43,20 @@ struct QMakeStatics {
QString field_sep;
QString strtrue;
QString strfalse;
ProString strCONFIG;
ProString strARGS;
ProKey strCONFIG;
ProKey strARGS;
QString strDot;
QString strDotDot;
QString strever;
QString strforever;
QString strhost_build;
ProString strTEMPLATE;
ProKey strTEMPLATE;
#ifdef PROEVALUATOR_FULL
ProString strREQUIRES;
ProKey strREQUIRES;
#endif
QHash<ProString, int> expands;
QHash<ProString, int> functions;
QHash<ProString, ProString> varMap;
QHash<ProKey, int> expands;
QHash<ProKey, int> functions;
QHash<ProKey, ProKey> varMap;
ProStringList fakeValue;
};
......
......@@ -229,25 +229,25 @@ bool QMakeGlobals::initProperties()
line.chop(1);
QString name = QString::fromLatin1(line.left(off));
ProString value = ProString(QDir::fromNativeSeparators(
QString::fromLocal8Bit(line.mid(off + 1))), ProStringConstants::NoHash);
properties.insert(ProString(name), value);
QString::fromLocal8Bit(line.mid(off + 1))));
properties.insert(ProKey(name), value);
if (name.startsWith(QLatin1String("QT_")) && !name.contains(QLatin1Char('/'))) {
if (name.startsWith(QLatin1String("QT_INSTALL_"))) {
properties.insert(ProString(name + QLatin1String("/raw")), value);
properties.insert(ProString(name + QLatin1String("/get")), value);
properties.insert(ProKey(name + QLatin1String("/raw")), value);
properties.insert(ProKey(name + QLatin1String("/get")), value);
if (name == QLatin1String("QT_INSTALL_PREFIX")
|| name == QLatin1String("QT_INSTALL_DATA")
|| name == QLatin1String("QT_INSTALL_BINS")) {
name.replace(3, 7, QLatin1String("HOST"));
properties.insert(ProString(name), value);
properties.insert(ProString(name + QLatin1String("/get")), value);
properties.insert(ProKey(name), value);
properties.insert(ProKey(name + QLatin1String("/get")), value);
}
} else if (name.startsWith(QLatin1String("QT_HOST_"))) {
properties.insert(ProString(name + QLatin1String("/get")), value);
properties.insert(ProKey(name + QLatin1String("/get")), value);
}
}
}
properties.insert(ProString("QMAKE_VERSION"), ProString("2.01a", ProStringConstants::NoHash));
properties.insert(ProKey("QMAKE_VERSION"), ProString("2.01a"));
return true;
}
#else
......@@ -255,7 +255,7 @@ void QMakeGlobals::setProperties(const QHash<QString, QString> &props)
{
QHash<QString, QString>::ConstIterator it = props.constBegin(), eit = props.constEnd();
for (; it != eit; ++it)
properties.insert(ProString(it.key()), ProString(it.value(), ProStringConstants::NoHash));
properties.insert(ProKey(it.key()), ProString(it.value()));
}
#endif
......
......@@ -105,7 +105,7 @@ public:
#else
void setProperties(const QHash<QString, QString> &props);
#endif
ProString propertyValue(const ProString &name) const { return properties.value(name); }
ProString propertyValue(const ProKey &name) const { return properties.value(name); }
QString expandEnvVars(const QString &str) const;
......@@ -116,7 +116,7 @@ private:
QString source_root, build_root;
QString precmds, postcmds;
QHash<ProString, ProString> properties;
QHash<ProKey, ProString> properties;
#ifdef PROEVALUATOR_THREAD_SAFE
QMutex mutex;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment