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,
|
||||
unsigned beginLine,
|
||||
const QVector<MacroArgumentReference> &actuals, bool inCondition)
|
||||
{
|
||||
MacroUse use(macro, offset, offset + length);
|
||||
MacroUse use(macro, offset, offset + length, beginLine);
|
||||
use.setInCondition(inCondition);
|
||||
|
||||
foreach (const MacroArgumentReference &actual, actuals) {
|
||||
@@ -330,6 +331,33 @@ Symbol *Document::findSymbolAt(unsigned line, unsigned column, Scope *scope) con
|
||||
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 doc(new Document(fileName));
|
||||
|
||||
@@ -73,7 +73,8 @@ public:
|
||||
|
||||
void appendMacro(const Macro ¯o);
|
||||
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);
|
||||
|
||||
Control *control() const;
|
||||
@@ -234,14 +235,15 @@ public:
|
||||
Macro _macro;
|
||||
QVector<Block> _arguments;
|
||||
bool _inCondition;
|
||||
unsigned _beginLine;
|
||||
|
||||
public:
|
||||
inline MacroUse(const Macro ¯o,
|
||||
unsigned begin = 0,
|
||||
unsigned end = 0)
|
||||
unsigned begin, unsigned end, unsigned beginLine)
|
||||
: Block(begin, end),
|
||||
_macro(macro),
|
||||
_inCondition(false)
|
||||
_inCondition(false),
|
||||
_beginLine(beginLine)
|
||||
{ }
|
||||
|
||||
const Macro ¯o() const
|
||||
@@ -256,6 +258,9 @@ public:
|
||||
bool isInCondition() const
|
||||
{ return _inCondition; }
|
||||
|
||||
unsigned beginLine() const
|
||||
{ return _beginLine; }
|
||||
|
||||
private:
|
||||
void setArguments(const QVector<Block> &arguments)
|
||||
{ _arguments = arguments; }
|
||||
@@ -275,7 +280,7 @@ public:
|
||||
public:
|
||||
inline UndefinedMacroUse(
|
||||
const QByteArray &name,
|
||||
unsigned begin = 0)
|
||||
unsigned begin)
|
||||
: Block(begin, begin + name.length()),
|
||||
_name(name)
|
||||
{ }
|
||||
@@ -298,6 +303,10 @@ public:
|
||||
QList<UndefinedMacroUse> undefinedMacroUses() const
|
||||
{ return _undefinedMacroUses; }
|
||||
|
||||
const Macro *findMacroDefinitionAt(unsigned line) const;
|
||||
const MacroUse *findMacroUseAt(unsigned offset) const;
|
||||
const UndefinedMacroUse *findUndefinedMacroUseAt(unsigned offset) const;
|
||||
|
||||
private:
|
||||
Symbol *findSymbolAt(unsigned line, unsigned column, Scope *scope) const;
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ Macro::Macro()
|
||||
: _next(0),
|
||||
_hashcode(0),
|
||||
_line(0),
|
||||
_offset(0),
|
||||
_length(0),
|
||||
_state(0)
|
||||
{ }
|
||||
|
||||
|
||||
@@ -92,6 +92,18 @@ public:
|
||||
void setLine(unsigned 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
|
||||
{ return f._hidden; }
|
||||
|
||||
@@ -129,6 +141,8 @@ private:
|
||||
QVector<QByteArray> _formals;
|
||||
QString _fileName;
|
||||
unsigned _line;
|
||||
unsigned _offset;
|
||||
unsigned _length;
|
||||
|
||||
union
|
||||
{
|
||||
|
||||
@@ -1205,6 +1205,8 @@ void Preprocessor::processDefine(TokenIterator firstToken, TokenIterator lastTok
|
||||
macro.setFileName(env->currentFile);
|
||||
macro.setLine(env->currentLine);
|
||||
macro.setName(tokenText(*tk));
|
||||
macro.setOffset(firstToken->offset);
|
||||
macro.setLength(endOfToken(lastToken[- 1]) - startOfToken(*firstToken));
|
||||
++tk; // skip T_IDENTIFIER
|
||||
|
||||
if (tk->is(T_LPAREN) && ! tk->f.whitespace) {
|
||||
|
||||
Reference in New Issue
Block a user