Commit 00e9be42 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

make messages from dynamic code tell a useful location



"(eval)" does not exactly help to find the error source.

Change-Id: Iecd03e6a4909ca6d7eab846844ca4415ebfa3429
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
parent 26e9f25a
......@@ -40,8 +40,10 @@ using namespace QtSupport;
static QString format(const QString &fileName, int lineNo, const QString &msg)
{
if (lineNo)
if (lineNo > 0)
return QString::fromLatin1("%1(%2): %3").arg(fileName, QString::number(lineNo), msg);
else if (lineNo)
return QString::fromLatin1("%1: %3").arg(fileName, msg);
else
return msg;
}
......
......@@ -1160,8 +1160,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction(
#endif
case T_EVAL: {
VisitReturn ret = ReturnFalse;
ProFile *pro = m_parser->parsedProBlock(fL1S("(eval)"),
args.join(statics.field_sep));
ProFile *pro = m_parser->parsedProBlock(args.join(statics.field_sep),
m_current.pro->fileName(), m_current.line);
if (pro) {
if (m_cumulative || pro->isOk()) {
m_locationStack.push(m_current);
......@@ -1192,7 +1192,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction(
evalError(fL1S("if(condition) requires one argument."));
return ReturnFalse;
}
return returnBool(evaluateConditional(args.at(0).toQString(), fL1S("(if)")));
return returnBool(evaluateConditional(args.at(0).toQString(),
m_current.pro->fileName(), m_current.line));
}
case T_CONFIG: {
if (args.count() < 1 || args.count() > 2) {
......
......@@ -1200,7 +1200,7 @@ void QMakeEvaluator::setupProject()
void QMakeEvaluator::visitCmdLine(const QString &cmds)
{
if (!cmds.isEmpty()) {
if (ProFile *pro = m_parser->parsedProBlock(fL1S("(command line)"), cmds)) {
if (ProFile *pro = m_parser->parsedProBlock(cmds, fL1S("(command line)"), -1)) {
if (pro->isOk()) {
m_locationStack.push(m_current);
visitProBlock(pro, pro->tokPtr());
......@@ -1591,10 +1591,10 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBoolFunction(
return ReturnFalse;
}
bool QMakeEvaluator::evaluateConditional(const QString &cond, const QString &context)
bool QMakeEvaluator::evaluateConditional(const QString &cond, const QString &where, int line)
{
bool ret = false;
ProFile *pro = m_parser->parsedProBlock(context, cond, QMakeParser::TestGrammar);
ProFile *pro = m_parser->parsedProBlock(cond, where, line, QMakeParser::TestGrammar);
if (pro) {
if (pro->isOk()) {
m_locationStack.push(m_current);
......@@ -1611,7 +1611,7 @@ void QMakeEvaluator::checkRequirements(const ProStringList &deps)
{
ProStringList &failed = valuesRef(ProKey("QMAKE_FAILED_REQUIREMENTS"));
foreach (const ProString &dep, deps)
if (!evaluateConditional(dep.toQString(), fL1S("(requires)")))
if (!evaluateConditional(dep.toQString(), m_current.pro->fileName(), m_current.line))
failed << dep;
}
#endif
......
......@@ -172,7 +172,7 @@ public:
ProStringList evaluateExpandFunction(const ProKey &function, const ushort *&tokPtr);
VisitReturn evaluateConditionalFunction(const ProKey &function, const ushort *&tokPtr);
bool evaluateConditional(const QString &cond, const QString &context);
bool evaluateConditional(const QString &cond, const QString &where, int line = -1);
#ifdef PROEVALUATOR_FULL
void checkRequirements(const ProStringList &deps);
#endif
......
......@@ -194,10 +194,11 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache)
return pro;
}
ProFile *QMakeParser::parsedProBlock(const QString &name, const QString &contents, SubGrammar grammar)
ProFile *QMakeParser::parsedProBlock(
const QString &contents, const QString &name, int line, SubGrammar grammar)
{
ProFile *pro = new ProFile(name);
if (!read(pro, contents, grammar)) {
if (!read(pro, contents, line, grammar)) {
delete pro;
pro = 0;
}
......@@ -224,7 +225,7 @@ bool QMakeParser::read(ProFile *pro)
QString content(QString::fromLocal8Bit(bcont));
bcont.clear();
file.close();
return read(pro, content, FullGrammar);
return read(pro, content, 1, FullGrammar);
}
void QMakeParser::putTok(ushort *&tokPtr, ushort tok)
......@@ -264,10 +265,10 @@ void QMakeParser::finalizeHashStr(ushort *buf, uint len)
buf[-2] = (ushort)(hash >> 16);
}
bool QMakeParser::read(ProFile *pro, const QString &in, SubGrammar grammar)
bool QMakeParser::read(ProFile *pro, const QString &in, int line, SubGrammar grammar)
{
m_proFile = pro;
m_lineNo = 1;
m_lineNo = line;
// Final precompiled token stream buffer
QString tokBuff;
......
......@@ -79,7 +79,7 @@ public:
enum SubGrammar { FullGrammar, TestGrammar };
// fileName is expected to be absolute and cleanPath()ed.
ProFile *parsedProFile(const QString &fileName, bool cache = false);
ProFile *parsedProBlock(const QString &name, const QString &contents,
ProFile *parsedProBlock(const QString &contents, const QString &name, int line = 0,
SubGrammar grammar = FullGrammar);
private:
......@@ -109,7 +109,7 @@ private:
};
bool read(ProFile *pro);
bool read(ProFile *pro, const QString &content, SubGrammar grammar);
bool read(ProFile *pro, const QString &content, int line, SubGrammar grammar);
ALWAYS_INLINE void putTok(ushort *&tokPtr, ushort tok);
ALWAYS_INLINE void putBlockLen(ushort *&tokPtr, uint len);
......
......@@ -39,8 +39,10 @@
static void print(const QString &fileName, int lineNo, const QString &msg)
{
if (lineNo)
if (lineNo > 0)
qWarning("%s(%d): %s", qPrintable(fileName), lineNo, qPrintable(msg));
else if (lineNo)
qWarning("%s: %s", qPrintable(fileName), qPrintable(msg));
else
qWarning("%s", qPrintable(msg));
}
......
......@@ -47,8 +47,10 @@ static void print(const QString &fileName, int lineNo, int type, const QString &
{
QString pfx = ((type & QMakeHandler::CategoryMask) == QMakeHandler::WarningMessage)
? QString::fromLatin1("WARNING: ") : QString();
if (lineNo)
if (lineNo > 0)
qWarning("%s%s:%d: %s", qPrintable(pfx), qPrintable(fileName), lineNo, qPrintable(msg));
else if (lineNo)
qWarning("%s%s: %s", qPrintable(pfx), qPrintable(fileName), qPrintable(msg));
else
qWarning("%s%s", qPrintable(pfx), qPrintable(msg));
}
......
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