Commit 139087ee authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Introduced Symbol::copy(otherSymbol) and removed some deprecated code.

parent 9a51f684
......@@ -69,9 +69,10 @@ bool ClassOrNamespace::CompareName::operator()(const Name *name, const Name *oth
{
Q_ASSERT(name != 0);
Q_ASSERT(other != 0);
const Identifier *id = name->identifier();
const Identifier *otherId = other->identifier();
return std::lexicographical_compare(id->begin(), id->end(), otherId->begin(), otherId->end());
return strcmp(id->chars(), otherId->chars()) < 0;
}
/////////////////////////////////////////////////////////////////////
......@@ -266,6 +267,11 @@ ClassOrNamespace::ClassOrNamespace(CreateBindings *factory, ClassOrNamespace *pa
{
}
ClassOrNamespace *ClassOrNamespace::parent() const
{
return _parent;
}
QList<ClassOrNamespace *> ClassOrNamespace::usings() const
{
const_cast<ClassOrNamespace *>(this)->flush();
......@@ -401,7 +407,7 @@ void CreateBindings::lookup_helper(const Name *name, Scope *scope,
#if 0
if (templateId && (s->isDeclaration() || s->isFunction())) {
FullySpecifiedType ty = GenTemplateInstance::instantiate(templateId, s, control);
FullySpecifiedType ty = GenTemplateInstance::instantiate(templateId, s, _control);
Overview oo;
oo.setShowFunctionSignatures(true);
......@@ -412,19 +418,15 @@ void CreateBindings::lookup_helper(const Name *name, Scope *scope,
if (Declaration *decl = s->asDeclaration()) {
qDebug() << "instantiate declaration";
qDebug() << "is typedef:" << ty.isTypedef() << s->isTypedef() << s->type().isTypedef();
Declaration *d = control->newDeclaration(0, 0);
d->setStorage(decl->storage());
d->setName(decl->name());
Declaration *d = _control->newDeclaration(0, 0);
d->copy(decl);
d->setType(ty);
d->setScope(decl->scope());
result->append(d);
continue;
} else if (Function *fun = s->asFunction()) {
qDebug() << "instantiate function";
Function *d = ty->asFunctionType();
d->setStorage(fun->storage());
d->setScope(fun->scope());
d->copy(fun);
result->append(d);
continue;
}
......
......@@ -48,6 +48,7 @@ class CPLUSPLUS_EXPORT ClassOrNamespace
public:
ClassOrNamespace(CreateBindings *factory, ClassOrNamespace *parent);
ClassOrNamespace *parent() const;
QList<ClassOrNamespace *> usings() const;
QList<Enum *> enums() const;
QList<Symbol *> symbols() const;
......
......@@ -1115,7 +1115,7 @@ bool CppCodeCompletion::completeMember(const QList<LookupItem> &baseResults,
classObjectCandidates.append(klass);
else if (NamedType *namedTy = ty->asNamedType()) {
if (ClassOrNamespace *b = context.classOrNamespace(namedTy->name(), r.lastVisibleSymbol()->scope())) {
if (ClassOrNamespace *b = context.classOrNamespace(namedTy->name(), r.lastVisibleSymbol())) {
classOrNamespace = b;
break;
......@@ -1342,22 +1342,6 @@ void CppCodeCompletion::completeNamespace(ClassOrNamespace *b, const LookupConte
}
}
void CppCodeCompletion::completeNamespace(const QList<Symbol *> &candidates,
const DeprecatedLookupContext &deprecatedContext)
{
if (candidates.isEmpty())
return;
else if (Namespace *ns = candidates.first()->asNamespace()) {
LookupContext context(deprecatedContext.expressionDocument(),
deprecatedContext.thisDocument(),
deprecatedContext.snapshot());
if (ClassOrNamespace *binding = context.classOrNamespace(ns))
completeNamespace(binding, context);
}
}
void CppCodeCompletion::completeClass(ClassOrNamespace *b, const LookupContext &, bool staticLookup)
{
QSet<ClassOrNamespace *> bindingsVisited;
......@@ -1405,23 +1389,6 @@ void CppCodeCompletion::completeClass(ClassOrNamespace *b, const LookupContext &
}
}
void CppCodeCompletion::completeClass(const QList<Symbol *> &candidates,
const DeprecatedLookupContext &deprecatedContext,
bool staticLookup)
{
if (candidates.isEmpty())
return;
else if (Symbol *klass = candidates.first()) {
LookupContext context(deprecatedContext.expressionDocument(),
deprecatedContext.thisDocument(),
deprecatedContext.snapshot());
if (ClassOrNamespace *binding = context.classOrNamespace(klass))
completeClass(binding, context, staticLookup);
}
}
bool CppCodeCompletion::completeQtMethod(const QList<LookupItem> &results,
const LookupContext &newContext,
bool wantSignals)
......
......@@ -126,17 +126,10 @@ private:
void completeNamespace(CPlusPlus::ClassOrNamespace *binding,
const CPlusPlus::LookupContext &context);
void completeNamespace(const QList<CPlusPlus::Symbol *> &candidates,
const CPlusPlus::DeprecatedLookupContext &context);
void completeClass(CPlusPlus::ClassOrNamespace *b,
const CPlusPlus::LookupContext &context,
bool staticLookup = true);
void completeClass(const QList<CPlusPlus::Symbol *> &candidates,
const CPlusPlus::DeprecatedLookupContext &context,
bool staticLookup = true);
bool completeConstructors(CPlusPlus::Class *klass);
bool completeQtMethod(const QList<CPlusPlus::LookupItem> &results,
......
......@@ -161,7 +161,7 @@ private:
};
Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
: _control(translationUnit->control()),
: _control(0),
_sourceLocation(sourceLocation),
_sourceOffset(0),
_startOffset(0),
......@@ -175,7 +175,11 @@ Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const
_next(0),
_isGenerated(false)
{
setSourceLocation(sourceLocation);
if (translationUnit) {
_control = translationUnit->control();
setSourceLocation(sourceLocation);
}
setName(name);
}
......@@ -504,3 +508,22 @@ bool Symbol::isObjCMethod() const
bool Symbol::isObjCPropertyDeclaration() const
{ return asObjCPropertyDeclaration() != 0; }
void Symbol::copy(Symbol *other)
{
_control = other->_control;
_sourceLocation = other->_sourceLocation;
_sourceOffset = other->_sourceOffset;
_startOffset = other->_startOffset;
_endOffset = other->_endOffset;
_name = other->_name;
_hashCode = other->_hashCode;
_storage = other->_storage;
_visibility = other->_visibility;
_scope = other->_scope;
_index = other->_index;
_next = other->_next;
_isGenerated = other->_isGenerated;
_isDeprecated = other->_isDeprecated;
}
......@@ -317,6 +317,8 @@ public:
void visitSymbol(SymbolVisitor *visitor);
static void visitSymbol(Symbol *symbol, SymbolVisitor *visitor);
virtual void copy(Symbol *other);
protected:
virtual void visitSymbol0(SymbolVisitor *visitor) = 0;
......
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