Commit aab9c520 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

More work on template instantiation.

parent 05984e71
......@@ -381,6 +381,8 @@ void CreateBindings::lookup_helper(const Name *name, Scope *scope,
}
} else if (const Identifier *id = name->identifier()) {
Control *control = new Control();
for (Symbol *s = scope->lookat(id); s; s = s->next()) {
if (! s->name())
continue;
......@@ -396,6 +398,39 @@ void CreateBindings::lookup_helper(const Name *name, Scope *scope,
continue;
}
if (templateId && (s->isDeclaration() || s->isFunction())) {
FullySpecifiedType ty = GenTemplateInstance::instantiate(templateId, s, control);
Overview oo;
oo.setShowFunctionSignatures(true);
oo.setShowReturnTypes(true);
qDebug() << "TODO: instantiate:" << oo(s->type(), s->name()) << "using:" << oo(templateId)
<< oo(ty);
#if 0
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());
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());
result->append(d);
continue;
}
#endif
}
result->append(s);
}
......@@ -524,21 +559,15 @@ ClassOrNamespace *ClassOrNamespace::nestedClassOrNamespace(const Name *name) con
ClassOrNamespace *c = it->second;
if (const TemplateNameId *templId = name->asTemplateNameId()) {
Overview oo;
qDebug() << "search for:" << oo(templId);
foreach (ClassOrNamespace *i, c->_instantiations) {
if (templId->isEqualTo(i->_templateId)) {
qDebug() << "*** got a match";
if (templId->isEqualTo(i->_templateId))
return i;
}
}
ClassOrNamespace *i = _factory->allocClassOrNamespace(c);
i->_templateId = templId;
i->_usings.append(c);
c->_instantiations.append(i);
qDebug() << "created a new instantiation" << i;
return i;
}
......@@ -601,11 +630,6 @@ ClassOrNamespace *ClassOrNamespace::findOrCreate(const Name *name)
if (! e) {
e = _factory->allocClassOrNamespace(this);
if (const TemplateNameId *templId = name->asTemplateNameId()) {
Overview oo;
qDebug() << "find or create:" << oo(templId);
}
_classOrNamespaces[name] = e;
}
......
......@@ -588,8 +588,54 @@ ResolveExpression::resolveBaseExpression(const QList<LookupItem> &baseResults, i
if (accessOp == T_ARROW) {
if (NamedType *namedTy = ty->asNamedType()) {
Overview oo;
qDebug() << "got here:" << oo(namedTy->name());
const Name *arrowAccessOp = control()->operatorNameId(OperatorNameId::ArrowOp);
#if 0
qDebug() << "last visible symbol is:" << result.lastVisibleSymbol()->fileName()
<< result.lastVisibleSymbol()->line()
<< result.lastVisibleSymbol()->column();
#endif
#if 0
if (const QualifiedNameId *q = namedTy->name()->asQualifiedNameId()) {
QList<const Name *> names;
for (unsigned i = 0; i < q->nameCount() - 1; ++i)
names.append(q->nameAt(i));
if (ClassOrNamespace *b = _context.globalNamespace()->findClassOrNamespace(names)) {
qDebug() << "yuppi du" << b << oo(b->_templateId);
foreach (Symbol *s, b->lookup(q->unqualifiedNameId())) {
qDebug() << "r:" << oo(s->type(), s->name());
}
}
}
#endif
foreach (Symbol *s, _context.lookup(namedTy->name(), result.lastVisibleSymbol())) {
qDebug() << "r:" << oo(s->type(), s->name());
if (PointerType *ptrTy = s->type()->asPointerType()) {
FullySpecifiedType elementTy = ptrTy->elementType().simplified();
if (elementTy->isNamedType() || elementTy->isClassType())
results.append(LookupItem(elementTy, lastVisibleSymbol));
} else if (const NamedType *nt = s->type()->asNamedType()) {
qDebug() << "f***";
Symbol *l = _context.lookup(nt->name(), result.lastVisibleSymbol()).first();
qDebug() << "l" << oo(l->type(), l->name());
if (PointerType *ptrTy = l->type()->asPointerType()) {
FullySpecifiedType elementTy = ptrTy->elementType().simplified();
if (elementTy->isNamedType() || elementTy->isClassType())
results.append(LookupItem(elementTy, lastVisibleSymbol));
}
}
}
if (ClassOrNamespace *b = _context.classOrNamespace(namedTy->name(), result.lastVisibleSymbol())) {
foreach (Symbol *overload, b->lookup(arrowAccessOp)) {
if (Function *funTy = overload->type()->asFunctionType()) {
......
......@@ -1105,6 +1105,8 @@ bool CppCodeCompletion::completeMember(const QList<LookupItem> &baseResults,
m_completionOperator,
&replacedDotOperator);
qDebug() << "results:" << classObjectResults.size() << "repl:" << replacedDotOperator;
ClassOrNamespace *classOrNamespace = 0;
QList<Symbol *> classObjectCandidates;
......
......@@ -242,6 +242,8 @@ void Symbol::setSourceLocation(unsigned sourceLocation)
unsigned Symbol::line() const
{
assert(_sourceOffset != 0);
unsigned line = 0, column = 0;
const StringLiteral *fileId = 0;
translationUnit()->getPosition(_sourceOffset, &line, &column, &fileId);
......@@ -250,6 +252,8 @@ unsigned Symbol::line() const
unsigned Symbol::column() const
{
assert(_sourceOffset != 0);
unsigned line = 0, column = 0;
const StringLiteral *fileId = 0;
translationUnit()->getPosition(_sourceOffset, &line, &column, &fileId);
......@@ -258,6 +262,8 @@ unsigned Symbol::column() const
const StringLiteral *Symbol::fileId() const
{
assert(_sourceOffset != 0);
unsigned line = 0, column = 0;
const StringLiteral *fileId = 0;
translationUnit()->getPosition(_sourceOffset, &line, &column, &fileId);
......
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