forked from qt-creator/qt-creator
Enhance data stored for macros and macro uses.
In preparation for finding macro uses. * Macro: add offset and length * MacroUse: add line * Document: add convenience functions for finding a macro definition, use or undefined use at a given location. Reviewed-by: Erik Verbruggen
This commit is contained in:
@@ -194,9 +194,10 @@ void Document::appendMacro(const Macro ¯o)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Document::addMacroUse(const Macro ¯o, unsigned offset, unsigned length,
|
void Document::addMacroUse(const Macro ¯o, unsigned offset, unsigned length,
|
||||||
|
unsigned beginLine,
|
||||||
const QVector<MacroArgumentReference> &actuals, bool inCondition)
|
const QVector<MacroArgumentReference> &actuals, bool inCondition)
|
||||||
{
|
{
|
||||||
MacroUse use(macro, offset, offset + length);
|
MacroUse use(macro, offset, offset + length, beginLine);
|
||||||
use.setInCondition(inCondition);
|
use.setInCondition(inCondition);
|
||||||
|
|
||||||
foreach (const MacroArgumentReference &actual, actuals) {
|
foreach (const MacroArgumentReference &actual, actuals) {
|
||||||
@@ -330,6 +331,33 @@ Symbol *Document::findSymbolAt(unsigned line, unsigned column, Scope *scope) con
|
|||||||
return previousSymbol;
|
return previousSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Macro *Document::findMacroDefinitionAt(unsigned line) const
|
||||||
|
{
|
||||||
|
foreach (const Macro ¯o, _definedMacros) {
|
||||||
|
if (macro.line() == line)
|
||||||
|
return ¯o;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Document::MacroUse *Document::findMacroUseAt(unsigned offset) const
|
||||||
|
{
|
||||||
|
foreach (const Document::MacroUse &use, _macroUses) {
|
||||||
|
if (use.contains(offset))
|
||||||
|
return &use;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Document::UndefinedMacroUse *Document::findUndefinedMacroUseAt(unsigned offset) const
|
||||||
|
{
|
||||||
|
foreach (const Document::UndefinedMacroUse &use, _undefinedMacroUses) {
|
||||||
|
if (use.contains(offset))
|
||||||
|
return &use;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Document::Ptr Document::create(const QString &fileName)
|
Document::Ptr Document::create(const QString &fileName)
|
||||||
{
|
{
|
||||||
Document::Ptr doc(new Document(fileName));
|
Document::Ptr doc(new Document(fileName));
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ public:
|
|||||||
|
|
||||||
void appendMacro(const Macro ¯o);
|
void appendMacro(const Macro ¯o);
|
||||||
void addMacroUse(const Macro ¯o, unsigned offset, unsigned length,
|
void addMacroUse(const Macro ¯o, unsigned offset, unsigned length,
|
||||||
const QVector<MacroArgumentReference> &range, bool inCondition);
|
unsigned beginLine, const QVector<MacroArgumentReference> &range,
|
||||||
|
bool inCondition);
|
||||||
void addUndefinedMacroUse(const QByteArray &name, unsigned offset);
|
void addUndefinedMacroUse(const QByteArray &name, unsigned offset);
|
||||||
|
|
||||||
Control *control() const;
|
Control *control() const;
|
||||||
@@ -234,14 +235,15 @@ public:
|
|||||||
Macro _macro;
|
Macro _macro;
|
||||||
QVector<Block> _arguments;
|
QVector<Block> _arguments;
|
||||||
bool _inCondition;
|
bool _inCondition;
|
||||||
|
unsigned _beginLine;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline MacroUse(const Macro ¯o,
|
inline MacroUse(const Macro ¯o,
|
||||||
unsigned begin = 0,
|
unsigned begin, unsigned end, unsigned beginLine)
|
||||||
unsigned end = 0)
|
|
||||||
: Block(begin, end),
|
: Block(begin, end),
|
||||||
_macro(macro),
|
_macro(macro),
|
||||||
_inCondition(false)
|
_inCondition(false),
|
||||||
|
_beginLine(beginLine)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
const Macro ¯o() const
|
const Macro ¯o() const
|
||||||
@@ -256,6 +258,9 @@ public:
|
|||||||
bool isInCondition() const
|
bool isInCondition() const
|
||||||
{ return _inCondition; }
|
{ return _inCondition; }
|
||||||
|
|
||||||
|
unsigned beginLine() const
|
||||||
|
{ return _beginLine; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setArguments(const QVector<Block> &arguments)
|
void setArguments(const QVector<Block> &arguments)
|
||||||
{ _arguments = arguments; }
|
{ _arguments = arguments; }
|
||||||
@@ -275,7 +280,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
inline UndefinedMacroUse(
|
inline UndefinedMacroUse(
|
||||||
const QByteArray &name,
|
const QByteArray &name,
|
||||||
unsigned begin = 0)
|
unsigned begin)
|
||||||
: Block(begin, begin + name.length()),
|
: Block(begin, begin + name.length()),
|
||||||
_name(name)
|
_name(name)
|
||||||
{ }
|
{ }
|
||||||
@@ -298,6 +303,10 @@ public:
|
|||||||
QList<UndefinedMacroUse> undefinedMacroUses() const
|
QList<UndefinedMacroUse> undefinedMacroUses() const
|
||||||
{ return _undefinedMacroUses; }
|
{ return _undefinedMacroUses; }
|
||||||
|
|
||||||
|
const Macro *findMacroDefinitionAt(unsigned line) const;
|
||||||
|
const MacroUse *findMacroUseAt(unsigned offset) const;
|
||||||
|
const UndefinedMacroUse *findUndefinedMacroUseAt(unsigned offset) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Symbol *findSymbolAt(unsigned line, unsigned column, Scope *scope) const;
|
Symbol *findSymbolAt(unsigned line, unsigned column, Scope *scope) const;
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ Macro::Macro()
|
|||||||
: _next(0),
|
: _next(0),
|
||||||
_hashcode(0),
|
_hashcode(0),
|
||||||
_line(0),
|
_line(0),
|
||||||
|
_offset(0),
|
||||||
|
_length(0),
|
||||||
_state(0)
|
_state(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,18 @@ public:
|
|||||||
void setLine(unsigned line)
|
void setLine(unsigned line)
|
||||||
{ _line = line; }
|
{ _line = line; }
|
||||||
|
|
||||||
|
unsigned offset() const
|
||||||
|
{ return _offset; }
|
||||||
|
|
||||||
|
void setOffset(unsigned offset)
|
||||||
|
{ _offset = offset; }
|
||||||
|
|
||||||
|
unsigned length() const
|
||||||
|
{ return _length; }
|
||||||
|
|
||||||
|
void setLength(unsigned length)
|
||||||
|
{ _length = length; }
|
||||||
|
|
||||||
bool isHidden() const
|
bool isHidden() const
|
||||||
{ return f._hidden; }
|
{ return f._hidden; }
|
||||||
|
|
||||||
@@ -129,6 +141,8 @@ private:
|
|||||||
QVector<QByteArray> _formals;
|
QVector<QByteArray> _formals;
|
||||||
QString _fileName;
|
QString _fileName;
|
||||||
unsigned _line;
|
unsigned _line;
|
||||||
|
unsigned _offset;
|
||||||
|
unsigned _length;
|
||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1205,6 +1205,8 @@ void Preprocessor::processDefine(TokenIterator firstToken, TokenIterator lastTok
|
|||||||
macro.setFileName(env->currentFile);
|
macro.setFileName(env->currentFile);
|
||||||
macro.setLine(env->currentLine);
|
macro.setLine(env->currentLine);
|
||||||
macro.setName(tokenText(*tk));
|
macro.setName(tokenText(*tk));
|
||||||
|
macro.setOffset(firstToken->offset);
|
||||||
|
macro.setLength(endOfToken(lastToken[- 1]) - startOfToken(*firstToken));
|
||||||
++tk; // skip T_IDENTIFIER
|
++tk; // skip T_IDENTIFIER
|
||||||
|
|
||||||
if (tk->is(T_LPAREN) && ! tk->f.whitespace) {
|
if (tk->is(T_LPAREN) && ! tk->f.whitespace) {
|
||||||
|
|||||||
@@ -1363,17 +1363,16 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Handle macro uses
|
// Handle macro uses
|
||||||
foreach (const Document::MacroUse use, doc->macroUses()) {
|
const Document::MacroUse *use = doc->findMacroUseAt(endOfName - 1);
|
||||||
if (use.contains(endOfName - 1)) {
|
if (use) {
|
||||||
const Macro ¯o = use.macro();
|
const Macro ¯o = use->macro();
|
||||||
link.fileName = macro.fileName();
|
link.fileName = macro.fileName();
|
||||||
link.line = macro.line();
|
link.line = macro.line();
|
||||||
link.pos = use.begin();
|
link.pos = use->begin();
|
||||||
link.length = use.end() - use.begin();
|
link.length = use->end() - use->begin();
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -455,7 +455,7 @@ void CppPreprocessor::passedMacroDefinitionCheck(unsigned offset, const Macro &m
|
|||||||
if (! m_currentDoc)
|
if (! m_currentDoc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_currentDoc->addMacroUse(macro, offset, macro.name().length(),
|
m_currentDoc->addMacroUse(macro, offset, macro.name().length(), env.currentLine,
|
||||||
QVector<MacroArgumentReference>(), true);
|
QVector<MacroArgumentReference>(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,7 +477,8 @@ void CppPreprocessor::startExpandingMacro(unsigned offset,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
//qDebug() << "start expanding:" << macro.name() << "text:" << originalText;
|
//qDebug() << "start expanding:" << macro.name() << "text:" << originalText;
|
||||||
m_currentDoc->addMacroUse(macro, offset, originalText.length(), actuals, inCondition);
|
m_currentDoc->addMacroUse(macro, offset, originalText.length(), env.currentLine,
|
||||||
|
actuals, inCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppPreprocessor::stopExpandingMacro(unsigned, const Macro &)
|
void CppPreprocessor::stopExpandingMacro(unsigned, const Macro &)
|
||||||
|
|||||||
Reference in New Issue
Block a user