Commit 5d13a206 authored by Roberto Raggi's avatar Roberto Raggi

Reimplemented switch declaration/definition.

parent 3c6ad0d8
......@@ -1227,56 +1227,45 @@ static bool isCompatible(Function *definition, Symbol *declaration,
void CPPEditor::switchDeclarationDefinition()
{
int line = 0, column = 0;
convertPosition(position(), &line, &column);
if (!m_modelManager)
if (! m_modelManager)
return;
#warning implement CPPEditor::switchDeclarationDefinition
qWarning() << Q_FUNC_INFO << __LINE__;
#if 0
const Snapshot snapshot = m_modelManager->snapshot();
Document::Ptr doc = snapshot.document(file()->fileName());
if (!doc)
return;
Symbol *lastSymbol = doc->findSymbolAt(line, column);
if (!lastSymbol || !lastSymbol->scope())
return;
if (Document::Ptr thisDocument = snapshot.document(file()->fileName())) {
int line = 0, column = 0;
convertPosition(position(), &line, &column);
Function *f = lastSymbol->asFunction();
if (!f) {
Scope *fs = lastSymbol->scope();
if (!fs->isFunctionScope())
fs = fs->enclosingFunctionScope();
if (fs)
f = fs->owner()->asFunction();
}
if (f) {
LookupContext context(doc, snapshot);
Scope *scope = thisDocument->scopeAt(line, column);
Symbol *lastVisibleSymbol = thisDocument->findSymbolAt(line, column);
const QualifiedNameId *q = qualifiedNameIdForSymbol(f, context.control());
const QList<Symbol *> symbols = context.lookup(q, lastSymbol); // ### FIXME
Scope *functionScope = 0;
if (scope->isFunctionScope())
functionScope = scope;
else
functionScope = scope->enclosingFunctionScope();
Symbol *declaration = 0;
foreach (declaration, symbols) {
if (isCompatible(f, declaration, q))
break;
if (! functionScope && lastVisibleSymbol) {
if (Function *def = lastVisibleSymbol->asFunction())
functionScope = def->members();
}
if (! declaration && ! symbols.isEmpty())
declaration = symbols.first();
if (functionScope) {
LookupContext context(thisDocument, snapshot);
if (declaration)
openCppEditorAt(linkToSymbol(declaration));
} else if (lastSymbol->type()->isFunctionType()) {
if (Symbol *def = findDefinition(lastSymbol, snapshot))
openCppEditorAt(linkToSymbol(def));
Function *functionDefinition = functionScope->owner()->asFunction();
const QList<Symbol *> declarations = context.lookup(functionDefinition->name(), functionDefinition->scope());
foreach (Symbol *decl, declarations) {
// TODO: check decl.
openCppEditorAt(linkToSymbol(decl));
break;
}
} else if (lastVisibleSymbol && lastVisibleSymbol->isDeclaration() && lastVisibleSymbol->type()->isFunctionType()) {
if (Symbol *def = snapshot.findMatchingDefinition(lastVisibleSymbol))
openCppEditorAt(linkToSymbol(def));
}
}
#endif
}
static inline LookupItem skipForwardDeclarations(const QList<LookupItem> &resolvedSymbols)
......
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