move get{,Hash}Str from QMakeEvaluator to ProFile

this makes it possible to use these functions without an evaluator.

Change-Id: I23e4ec141b427f4c3c8b647305532be179058c07
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
Oswald Buddenhagen 2015-03-04 21:38:31 +01:00
parent 637a0889b2
commit df43683975
4 changed files with 32 additions and 28 deletions

View File

@ -485,4 +485,23 @@ ProFile::~ProFile()
{
}
ProString ProFile::getStr(const ushort *&tPtr)
{
uint len = *tPtr++;
ProString ret(items(), tPtr - tokPtr(), len);
ret.setSource(this);
tPtr += len;
return ret;
}
ProKey ProFile::getHashStr(const ushort *&tPtr)
{
uint hash = *tPtr++;
hash |= (uint)*tPtr++ << 16;
uint len = *tPtr++;
ProKey ret(items(), tPtr - tokPtr(), len, hash);
tPtr += len;
return ret;
}
QT_END_NAMESPACE

View File

@ -352,6 +352,9 @@ public:
bool isHostBuild() const { return m_hostBuild; }
void setHostBuild(bool host_build) { m_hostBuild = host_build; }
ProString getStr(const ushort *&tPtr);
ProKey getHashStr(const ushort *&tPtr);
private:
ProItemRefCount m_refCount;
QString m_proitems;

View File

@ -258,24 +258,6 @@ uint QMakeEvaluator::getBlockLen(const ushort *&tokPtr)
return len;
}
ProString QMakeEvaluator::getStr(const ushort *&tokPtr)
{
uint len = *tokPtr++;
ProString ret(m_current.pro->items(), tokPtr - m_current.pro->tokPtr(), len);
ret.setSource(m_current.pro);
tokPtr += len;
return ret;
}
ProKey QMakeEvaluator::getHashStr(const ushort *&tokPtr)
{
uint hash = getBlockLen(tokPtr);
uint len = *tokPtr++;
ProKey ret(m_current.pro->items(), tokPtr - m_current.pro->tokPtr(), len, hash);
tokPtr += len;
return ret;
}
void QMakeEvaluator::skipStr(const ushort *&tokPtr)
{
uint len = *tokPtr++;
@ -430,6 +412,7 @@ void QMakeEvaluator::evaluateExpression(
const ushort *&tokPtr, ProStringList *ret, bool joined)
{
debugMsg(2, joined ? "evaluating joined expression" : "evaluating expression");
ProFile *pro = m_current.pro;
if (joined)
*ret << ProString();
bool pending = false;
@ -445,35 +428,35 @@ void QMakeEvaluator::evaluateExpression(
m_current.line = *tokPtr++;
break;
case TokLiteral: {
const ProString &val = getStr(tokPtr);
const ProString &val = pro->getStr(tokPtr);
debugMsg(2, "literal %s", dbgStr(val));
addStr(val, ret, pending, joined);
break; }
case TokHashLiteral: {
const ProKey &val = getHashStr(tokPtr);
const ProKey &val = pro->getHashStr(tokPtr);
debugMsg(2, "hashed literal %s", dbgStr(val.toString()));
addStr(val, ret, pending, joined);
break; }
case TokVariable: {
const ProKey &var = getHashStr(tokPtr);
const ProKey &var = pro->getHashStr(tokPtr);
const ProStringList &val = values(map(var));
debugMsg(2, "variable %s => %s", dbgKey(var), dbgStrList(val));
addStrList(val, tok, ret, pending, joined);
break; }
case TokProperty: {
const ProKey &var = getHashStr(tokPtr);
const ProKey &var = pro->getHashStr(tokPtr);
const ProString &val = propertyValue(var);
debugMsg(2, "property %s => %s", dbgKey(var), dbgStr(val));
addStr(val, ret, pending, joined);
break; }
case TokEnvVar: {
const ProString &var = getStr(tokPtr);
const ProString &var = pro->getStr(tokPtr);
const ProString &val = ProString(m_option->getEnv(var.toQString(m_tmp1)));
debugMsg(2, "env var %s => %s", dbgStr(var), dbgStr(val));
addStr(val, ret, pending, joined);
break; }
case TokFuncName: {
const ProKey &func = getHashStr(tokPtr);
const ProKey &func = pro->getHashStr(tokPtr);
debugMsg(2, "function %s", dbgKey(func));
addStrList(evaluateExpandFunction(func, tokPtr), tok, ret, pending, joined);
break; }
@ -538,6 +521,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProBlock(
{
traceMsg("entering block");
ProStringList curr;
ProFile *pro = m_current.pro;
bool okey = true, or_op = false, invert = false;
uint blockLen;
while (ushort tok = *tokPtr++) {
@ -597,7 +581,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProBlock(
blockLen = getBlockLen(tokPtr);
ret = visitProBlock(tokPtr);
} else if (okey != or_op) {
const ProKey &variable = getHashStr(tokPtr);
const ProKey &variable = pro->getHashStr(tokPtr);
uint exprLen = getBlockLen(tokPtr);
const ushort *exprPtr = tokPtr;
tokPtr += exprLen;
@ -617,7 +601,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProBlock(
case TokTestDef:
case TokReplaceDef:
if (m_cumulative || okey != or_op) {
const ProKey &name = getHashStr(tokPtr);
const ProKey &name = pro->getHashStr(tokPtr);
blockLen = getBlockLen(tokPtr);
visitProFunctionDef(tok, name, tokPtr);
traceMsg("defined %s function %s",

View File

@ -150,8 +150,6 @@ public:
{ return b ? ReturnTrue : ReturnFalse; }
static ALWAYS_INLINE uint getBlockLen(const ushort *&tokPtr);
ProString getStr(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);