Reimplemented switch declaration/definition.

This commit is contained in:
Roberto Raggi
2010-05-12 16:36:52 +02:00
parent 3c6ad0d845
commit 5d13a206e2

View File

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