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

preprocessor: save cycles by using ByteArrayRef

Change-Id: I339696763b045ef1bda17dd55746738ef4ddbb67
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 3df5728d
......@@ -64,7 +64,7 @@ public:
virtual void macroAdded(const Macro &) {}
virtual void passedMacroDefinitionCheck(unsigned, const Macro &) {}
virtual void failedMacroDefinitionCheck(unsigned, const QByteArray &) {}
virtual void failedMacroDefinitionCheck(unsigned, const Internal::ByteArrayRef &) {}
virtual void startExpandingMacro(unsigned,
const Macro &,
......
......@@ -22,6 +22,11 @@ public:
, m_length(ref->length())
{}
ByteArrayRef(const char *start, int length)
: m_start(start)
, m_length(length)
{}
ByteArrayRef(const QByteArray *ref, int offset, int length)
: m_start(ref->constData() + offset)
, m_length(length)
......
......@@ -43,6 +43,7 @@ QT_END_NAMESPACE
namespace CPlusPlus {
namespace Internal { class ByteArrayRef; }
class Macro;
class CPLUSPLUS_EXPORT MacroArgumentReference
......@@ -80,7 +81,7 @@ public:
virtual void macroAdded(const Macro &macro) = 0;
virtual void passedMacroDefinitionCheck(unsigned offset, const Macro &macro) = 0;
virtual void failedMacroDefinitionCheck(unsigned offset, const QByteArray &name) = 0;
virtual void failedMacroDefinitionCheck(unsigned offset, const Internal::ByteArrayRef &name) = 0;
virtual void startExpandingMacro(unsigned offset,
const Macro &macro,
......
......@@ -210,7 +210,7 @@ inline bool isValidToken(const PPToken &tk)
return tk.isNot(T_EOF_SYMBOL) && (! tk.newline() || tk.joined());
}
Macro *macroDefinition(const QByteArray &name, unsigned offset, Environment *env, Client *client)
Macro *macroDefinition(const ByteArrayRef &name, unsigned offset, Environment *env, Client *client)
{
Macro *m = env->resolve(name);
if (client) {
......@@ -306,7 +306,7 @@ protected:
{
if ((*_lex)->isNot(T_IDENTIFIER))
return false;
const QByteArray spell = tokenSpell();
const ByteArrayRef spell = tokenSpell();
if (spell.size() != 7)
return false;
return spell == "defined";
......@@ -322,11 +322,9 @@ protected:
return (*_lex)->f.length;
}
QByteArray tokenSpell() const
ByteArrayRef tokenSpell() const
{
const QByteArray text = QByteArray::fromRawData(source.constData() + (*_lex)->offset,
(*_lex)->f.length);
return text;
return ByteArrayRef(tokenPosition(), tokenLength());
}
inline void process_expression()
......@@ -1430,7 +1428,7 @@ void Preprocessor::handleIfDefDirective(bool checkUndefined, PPToken *tk)
if (tk->is(T_IDENTIFIER)) {
bool value = false;
const ByteArrayRef macroName = tk->asByteArrayRef();
if (Macro *macro = macroDefinition(macroName.toByteArray(), tk->offset, m_env, m_client)) {
if (Macro *macro = macroDefinition(macroName, tk->offset, m_env, m_client)) {
value = true;
// the macro is a feature constraint(e.g. QT_NO_XXX)
......
......@@ -508,12 +508,12 @@ void CppPreprocessor::passedMacroDefinitionCheck(unsigned offset, const Macro &m
QVector<MacroArgumentReference>());
}
void CppPreprocessor::failedMacroDefinitionCheck(unsigned offset, const QByteArray &name)
void CppPreprocessor::failedMacroDefinitionCheck(unsigned offset, const CPlusPlus::Internal::ByteArrayRef &name)
{
if (! m_currentDoc)
return;
m_currentDoc->addUndefinedMacroUse(name, offset);
m_currentDoc->addUndefinedMacroUse(QByteArray(name.start(), name.size()), offset);
}
void CppPreprocessor::startExpandingMacro(unsigned offset,
......
......@@ -300,7 +300,7 @@ protected:
virtual void macroAdded(const CPlusPlus::Macro &macro);
virtual void passedMacroDefinitionCheck(unsigned offset, const CPlusPlus::Macro &macro);
virtual void failedMacroDefinitionCheck(unsigned offset, const QByteArray &name);
virtual void failedMacroDefinitionCheck(unsigned offset, const CPlusPlus::Internal::ByteArrayRef &name);
virtual void startExpandingMacro(unsigned offset,
const CPlusPlus::Macro &macro,
const QByteArray &originalText,
......
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