Commit acf6f8f0 authored by hjk's avatar hjk Committed by hjk

preprocessor: make Environment::{resolve,remove} work on ByteArrayRefs only

Change-Id: Idb93d359bd45696a38cb863dcea30c5c377eeabb
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 34282402
......@@ -68,7 +68,7 @@ public:
virtual void startExpandingMacro(unsigned,
const Macro &,
const QByteArray &,
const ByteArrayRef &,
const QVector<MacroArgumentReference> &) {}
virtual void stopExpandingMacro(unsigned, const Macro &) {}
......
......@@ -85,7 +85,7 @@ public:
virtual void startExpandingMacro(unsigned offset,
const Macro &macro,
const QByteArray &originalText,
const ByteArrayRef &originalText,
const QVector<MacroArgumentReference> &actuals
= QVector<MacroArgumentReference>()) = 0;
......
......@@ -123,10 +123,10 @@ void Environment::addMacros(const QList<Macro> &macros)
}
}
Macro *Environment::remove(const QByteArray &name)
Macro *Environment::remove(const ByteArrayRef &name)
{
Macro macro;
macro.setName(name);
macro.setName(name.toByteArray());
macro.setHidden(true);
macro.setFileName(currentFile);
macro.setLine(currentLine);
......@@ -220,22 +220,6 @@ Environment::iterator Environment::firstMacro() const
Environment::iterator Environment::lastMacro() const
{ return _macros + _macro_count + 1; }
Macro *Environment::resolve(const QByteArray &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;
}
Macro *Environment::resolve(const ByteArrayRef &name) const
{
if (! _macros)
......
......@@ -76,9 +76,7 @@ public:
Macro *macroAt(unsigned index) const;
Macro *bind(const Macro &macro);
Macro *remove(const QByteArray &name);
Macro *resolve(const QByteArray &name) const;
Macro *remove(const ByteArrayRef &name);
Macro *resolve(const ByteArrayRef &name) const;
iterator firstMacro() const;
......
......@@ -795,8 +795,7 @@ bool Preprocessor::handleIdentifier(PPToken *tk)
}
}
const QByteArray macroName = macroNameRef.toByteArray();
Macro *macro = m_env->resolve(macroName);
Macro *macro = m_env->resolve(macroNameRef);
if (!macro)
return false;
if (tk->generated() && m_state.m_tokenBuffer && m_state.m_tokenBuffer->isBlocked(macro))
......@@ -804,7 +803,7 @@ bool Preprocessor::handleIdentifier(PPToken *tk)
// qDebug() << "expanding" << macro->name() << "on line" << tk->lineno;
if (m_client && !tk->generated())
m_client->startExpandingMacro(tk->offset, *macro, macroName);
m_client->startExpandingMacro(tk->offset, *macro, macroNameRef);
QVector<PPToken> body = macro->definitionTokens();
if (macro->isFunctionLike()) {
......@@ -1470,7 +1469,7 @@ void Preprocessor::handleUndefDirective(PPToken *tk)
lex(tk); // consume "undef" token
if (tk->is(T_IDENTIFIER)) {
const ByteArrayRef macroName = tk->asByteArrayRef();
const Macro *macro = m_env->remove(macroName.toByteArray());
const Macro *macro = m_env->remove(macroName);
if (m_client && macro)
m_client->macroAdded(*macro);
......
......@@ -518,7 +518,7 @@ void CppPreprocessor::failedMacroDefinitionCheck(unsigned offset, const ByteArra
void CppPreprocessor::startExpandingMacro(unsigned offset,
const Macro &macro,
const QByteArray &originalText,
const ByteArrayRef &originalText,
const QVector<MacroArgumentReference> &actuals)
{
if (! m_currentDoc)
......
......@@ -303,7 +303,7 @@ protected:
virtual void failedMacroDefinitionCheck(unsigned offset, const CPlusPlus::ByteArrayRef &name);
virtual void startExpandingMacro(unsigned offset,
const CPlusPlus::Macro &macro,
const QByteArray &originalText,
const CPlusPlus::ByteArrayRef &originalText,
const QVector<CPlusPlus::MacroArgumentReference> &actuals);
virtual void stopExpandingMacro(unsigned offset, const CPlusPlus::Macro &macro);
virtual void startSkippingBlocks(unsigned offset);
......
......@@ -111,15 +111,15 @@ public:
}
virtual void passedMacroDefinitionCheck(unsigned /*offset*/, const Macro &/*macro*/) {}
virtual void failedMacroDefinitionCheck(unsigned /*offset*/, const QByteArray &/*name*/) {}
virtual void failedMacroDefinitionCheck(unsigned /*offset*/, const ByteArrayRef &/*name*/) {}
virtual void startExpandingMacro(unsigned offset,
const Macro &/*macro*/,
const QByteArray &originalText,
const ByteArrayRef &originalText,
const QVector<MacroArgumentReference> &/*actuals*/
= QVector<MacroArgumentReference>())
{
m_expandedMacros.append(originalText);
m_expandedMacros.append(QByteArray(originalText.start(), originalText.length()));
m_expandedMacrosOffset.append(offset);
}
......
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