forked from qt-creator/qt-creator
Merge commit 'origin/1.3'
Conflicts:
src/plugins/debugger/gdb/gdbengine.cpp
Needed changes:
src/plugins/qt4projectmanager/qtversionmanager.cpp
This commit is contained in:
446
src/libs/cplusplus/FindUsages.cpp
Normal file
446
src/libs/cplusplus/FindUsages.cpp
Normal file
@@ -0,0 +1,446 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "FindUsages.h"
|
||||
#include "TypeOfExpression.h"
|
||||
|
||||
#include <Control.h>
|
||||
#include <Literals.h>
|
||||
#include <Names.h>
|
||||
#include <Symbols.h>
|
||||
#include <AST.h>
|
||||
|
||||
#include <QtCore/QDir>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
FindUsages::FindUsages(Document::Ptr doc, const Snapshot &snapshot, QFutureInterface<Usage> *future)
|
||||
: ASTVisitor(doc->control()),
|
||||
_future(future),
|
||||
_doc(doc),
|
||||
_snapshot(snapshot),
|
||||
_source(_doc->source()),
|
||||
_sem(doc->control()),
|
||||
_inSimpleDeclaration(0)
|
||||
{
|
||||
_snapshot.insert(_doc);
|
||||
}
|
||||
|
||||
void FindUsages::setGlobalNamespaceBinding(NamespaceBindingPtr globalNamespaceBinding)
|
||||
{
|
||||
_globalNamespaceBinding = globalNamespaceBinding;
|
||||
}
|
||||
|
||||
QList<int> FindUsages::operator()(Symbol *symbol, Identifier *id, AST *ast)
|
||||
{
|
||||
_references.clear();
|
||||
_declSymbol = symbol;
|
||||
_id = id;
|
||||
_exprDoc = Document::create("<references>");
|
||||
accept(ast);
|
||||
return _references;
|
||||
}
|
||||
|
||||
QString FindUsages::matchingLine(const Token &tk) const
|
||||
{
|
||||
const char *beg = _source.constData();
|
||||
const char *cp = beg + tk.offset;
|
||||
for (; cp != beg - 1; --cp) {
|
||||
if (*cp == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
++cp;
|
||||
|
||||
const char *lineEnd = cp + 1;
|
||||
for (; *lineEnd; ++lineEnd) {
|
||||
if (*lineEnd == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
const QString matchingLine = QString::fromUtf8(cp, lineEnd - cp);
|
||||
return matchingLine;
|
||||
}
|
||||
|
||||
void FindUsages::reportResult(unsigned tokenIndex, const QList<Symbol *> &candidates)
|
||||
{
|
||||
const bool isStrongResult = checkCandidates(candidates);
|
||||
|
||||
if (isStrongResult)
|
||||
reportResult(tokenIndex);
|
||||
}
|
||||
|
||||
void FindUsages::reportResult(unsigned tokenIndex)
|
||||
{
|
||||
const Token &tk = tokenAt(tokenIndex);
|
||||
const QString lineText = matchingLine(tk);
|
||||
|
||||
unsigned line, col;
|
||||
getTokenStartPosition(tokenIndex, &line, &col);
|
||||
|
||||
if (col)
|
||||
--col; // adjust the column position.
|
||||
|
||||
const int len = tk.f.length;
|
||||
|
||||
if (_future) {
|
||||
const QString path = QDir::toNativeSeparators(_doc->fileName());
|
||||
_future->reportResult(Usage(path, line, lineText, col, len));
|
||||
}
|
||||
|
||||
_references.append(tokenIndex);
|
||||
}
|
||||
|
||||
bool FindUsages::checkCandidates(const QList<Symbol *> &candidates) const
|
||||
{
|
||||
if (Symbol *canonicalSymbol = LookupContext::canonicalSymbol(candidates, _globalNamespaceBinding.data())) {
|
||||
|
||||
#if 0
|
||||
Symbol *c = candidates.first();
|
||||
qDebug() << "*** canonical symbol:" << canonicalSymbol->fileName()
|
||||
<< canonicalSymbol->line() << canonicalSymbol->column()
|
||||
<< "candidates:" << candidates.size()
|
||||
<< c->fileName() << c->line() << c->column();
|
||||
#endif
|
||||
|
||||
return checkSymbol(canonicalSymbol);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FindUsages::checkScope(Symbol *symbol, Symbol *otherSymbol) const
|
||||
{
|
||||
if (! (symbol && otherSymbol))
|
||||
return false;
|
||||
|
||||
else if (symbol->scope() == otherSymbol->scope())
|
||||
return true;
|
||||
|
||||
else if (symbol->name() && otherSymbol->name()) {
|
||||
|
||||
if (! symbol->name()->isEqualTo(otherSymbol->name()))
|
||||
return false;
|
||||
|
||||
} else if (symbol->name() != otherSymbol->name()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return checkScope(symbol->enclosingSymbol(), otherSymbol->enclosingSymbol());
|
||||
}
|
||||
|
||||
bool FindUsages::checkSymbol(Symbol *symbol) const
|
||||
{
|
||||
if (! symbol) {
|
||||
return false;
|
||||
|
||||
} else if (symbol == _declSymbol) {
|
||||
return true;
|
||||
|
||||
} else if (symbol->line() == _declSymbol->line() && symbol->column() == _declSymbol->column()) {
|
||||
if (! qstrcmp(symbol->fileName(), _declSymbol->fileName()))
|
||||
return true;
|
||||
|
||||
} else if (symbol->isForwardClassDeclaration() && (_declSymbol->isClass() ||
|
||||
_declSymbol->isForwardClassDeclaration())) {
|
||||
return checkScope(symbol, _declSymbol);
|
||||
|
||||
} else if (_declSymbol->isForwardClassDeclaration() && (symbol->isClass() ||
|
||||
symbol->isForwardClassDeclaration())) {
|
||||
return checkScope(symbol, _declSymbol);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
LookupContext FindUsages::currentContext(AST *ast)
|
||||
{
|
||||
unsigned line, column;
|
||||
getTokenStartPosition(ast->firstToken(), &line, &column);
|
||||
Symbol *lastVisibleSymbol = _doc->findSymbolAt(line, column);
|
||||
|
||||
if (lastVisibleSymbol && lastVisibleSymbol == _previousContext.symbol())
|
||||
return _previousContext;
|
||||
|
||||
LookupContext ctx(lastVisibleSymbol, _exprDoc, _doc, _snapshot);
|
||||
_previousContext = ctx;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void FindUsages::ensureNameIsValid(NameAST *ast)
|
||||
{
|
||||
if (ast && ! ast->name)
|
||||
ast->name = _sem.check(ast, /*scope = */ 0);
|
||||
}
|
||||
|
||||
bool FindUsages::visit(MemInitializerAST *ast)
|
||||
{
|
||||
if (ast->name && ast->name->asSimpleName() != 0) {
|
||||
ensureNameIsValid(ast->name);
|
||||
|
||||
SimpleNameAST *simple = ast->name->asSimpleName();
|
||||
if (identifier(simple->identifier_token) == _id) {
|
||||
LookupContext context = currentContext(ast);
|
||||
const QList<Symbol *> candidates = context.resolve(simple->name);
|
||||
reportResult(simple->identifier_token, candidates);
|
||||
}
|
||||
}
|
||||
accept(ast->expression);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FindUsages::visit(PostfixExpressionAST *ast)
|
||||
{
|
||||
_postfixExpressionStack.append(ast);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FindUsages::endVisit(PostfixExpressionAST *)
|
||||
{
|
||||
_postfixExpressionStack.removeLast();
|
||||
}
|
||||
|
||||
bool FindUsages::visit(MemberAccessAST *ast)
|
||||
{
|
||||
if (ast->member_name) {
|
||||
if (SimpleNameAST *simple = ast->member_name->asSimpleName()) {
|
||||
if (identifier(simple->identifier_token) == _id) {
|
||||
Q_ASSERT(! _postfixExpressionStack.isEmpty());
|
||||
|
||||
checkExpression(_postfixExpressionStack.last()->firstToken(),
|
||||
simple->identifier_token);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FindUsages::checkExpression(unsigned startToken, unsigned endToken)
|
||||
{
|
||||
const unsigned begin = tokenAt(startToken).begin();
|
||||
const unsigned end = tokenAt(endToken).end();
|
||||
|
||||
const QString expression = _source.mid(begin, end - begin);
|
||||
// qDebug() << "*** check expression:" << expression;
|
||||
|
||||
TypeOfExpression typeofExpression;
|
||||
typeofExpression.setSnapshot(_snapshot);
|
||||
|
||||
unsigned line, column;
|
||||
getTokenStartPosition(startToken, &line, &column);
|
||||
Symbol *lastVisibleSymbol = _doc->findSymbolAt(line, column);
|
||||
|
||||
const QList<TypeOfExpression::Result> results =
|
||||
typeofExpression(expression, _doc, lastVisibleSymbol,
|
||||
TypeOfExpression::Preprocess);
|
||||
|
||||
QList<Symbol *> candidates;
|
||||
|
||||
foreach (TypeOfExpression::Result r, results) {
|
||||
FullySpecifiedType ty = r.first;
|
||||
Symbol *lastVisibleSymbol = r.second;
|
||||
|
||||
candidates.append(lastVisibleSymbol);
|
||||
}
|
||||
|
||||
reportResult(endToken, candidates);
|
||||
}
|
||||
|
||||
bool FindUsages::visit(QualifiedNameAST *ast)
|
||||
{
|
||||
for (NestedNameSpecifierAST *nested_name_specifier = ast->nested_name_specifier;
|
||||
nested_name_specifier; nested_name_specifier = nested_name_specifier->next) {
|
||||
|
||||
if (NameAST *class_or_namespace_name = nested_name_specifier->class_or_namespace_name) {
|
||||
SimpleNameAST *simple_name = class_or_namespace_name->asSimpleName();
|
||||
|
||||
TemplateIdAST *template_id = 0;
|
||||
if (! simple_name) {
|
||||
template_id = class_or_namespace_name->asTemplateId();
|
||||
|
||||
if (template_id) {
|
||||
for (TemplateArgumentListAST *template_arguments = template_id->template_arguments;
|
||||
template_arguments; template_arguments = template_arguments->next) {
|
||||
accept(template_arguments->template_argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (simple_name || template_id) {
|
||||
const unsigned identifier_token = simple_name
|
||||
? simple_name->identifier_token
|
||||
: template_id->identifier_token;
|
||||
|
||||
if (identifier(identifier_token) == _id)
|
||||
checkExpression(ast->firstToken(), identifier_token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NameAST *unqualified_name = ast->unqualified_name) {
|
||||
unsigned identifier_token = 0;
|
||||
|
||||
if (SimpleNameAST *simple_name = unqualified_name->asSimpleName())
|
||||
identifier_token = simple_name->identifier_token;
|
||||
|
||||
else if (DestructorNameAST *dtor_name = unqualified_name->asDestructorName())
|
||||
identifier_token = dtor_name->identifier_token;
|
||||
|
||||
TemplateIdAST *template_id = 0;
|
||||
if (! identifier_token) {
|
||||
template_id = unqualified_name->asTemplateId();
|
||||
|
||||
if (template_id) {
|
||||
identifier_token = template_id->identifier_token;
|
||||
|
||||
for (TemplateArgumentListAST *template_arguments = template_id->template_arguments;
|
||||
template_arguments; template_arguments = template_arguments->next) {
|
||||
accept(template_arguments->template_argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (identifier_token && identifier(identifier_token) == _id)
|
||||
checkExpression(ast->firstToken(), identifier_token);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FindUsages::visit(EnumeratorAST *ast)
|
||||
{
|
||||
Identifier *id = identifier(ast->identifier_token);
|
||||
if (id == _id) {
|
||||
LookupContext context = currentContext(ast);
|
||||
const QList<Symbol *> candidates = context.resolve(control()->nameId(id));
|
||||
reportResult(ast->identifier_token, candidates);
|
||||
}
|
||||
|
||||
accept(ast->expression);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FindUsages::visit(SimpleNameAST *ast)
|
||||
{
|
||||
Identifier *id = identifier(ast->identifier_token);
|
||||
if (id == _id) {
|
||||
LookupContext context = currentContext(ast);
|
||||
const QList<Symbol *> candidates = context.resolve(ast->name);
|
||||
reportResult(ast->identifier_token, candidates);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FindUsages::visit(DestructorNameAST *ast)
|
||||
{
|
||||
Identifier *id = identifier(ast->identifier_token);
|
||||
if (id == _id) {
|
||||
LookupContext context = currentContext(ast);
|
||||
const QList<Symbol *> candidates = context.resolve(ast->name);
|
||||
reportResult(ast->identifier_token, candidates);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FindUsages::visit(TemplateIdAST *ast)
|
||||
{
|
||||
if (_id == identifier(ast->identifier_token)) {
|
||||
LookupContext context = currentContext(ast);
|
||||
const QList<Symbol *> candidates = context.resolve(ast->name);
|
||||
reportResult(ast->identifier_token, candidates);
|
||||
}
|
||||
|
||||
for (TemplateArgumentListAST *template_arguments = ast->template_arguments;
|
||||
template_arguments; template_arguments = template_arguments->next) {
|
||||
accept(template_arguments->template_argument);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FindUsages::visit(ParameterDeclarationAST *ast)
|
||||
{
|
||||
for (SpecifierAST *spec = ast->type_specifier; spec; spec = spec->next)
|
||||
accept(spec);
|
||||
|
||||
if (DeclaratorAST *declarator = ast->declarator) {
|
||||
for (SpecifierAST *attr = declarator->attributes; attr; attr = attr->next)
|
||||
accept(attr);
|
||||
|
||||
for (PtrOperatorAST *ptr_op = declarator->ptr_operators; ptr_op; ptr_op = ptr_op->next)
|
||||
accept(ptr_op);
|
||||
|
||||
if (! _inSimpleDeclaration) // visit the core declarator only if we are not in simple-declaration.
|
||||
accept(declarator->core_declarator);
|
||||
|
||||
for (PostfixDeclaratorAST *fx_op = declarator->postfix_declarators; fx_op; fx_op = fx_op->next)
|
||||
accept(fx_op);
|
||||
|
||||
for (SpecifierAST *spec = declarator->post_attributes; spec; spec = spec->next)
|
||||
accept(spec);
|
||||
|
||||
accept(declarator->initializer);
|
||||
}
|
||||
|
||||
accept(ast->expression);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FindUsages::visit(ExpressionOrDeclarationStatementAST *ast)
|
||||
{
|
||||
accept(ast->declaration);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FindUsages::visit(FunctionDeclaratorAST *ast)
|
||||
{
|
||||
accept(ast->parameters);
|
||||
|
||||
for (SpecifierAST *spec = ast->cv_qualifier_seq; spec; spec = spec->next)
|
||||
accept(spec);
|
||||
|
||||
accept(ast->exception_specification);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FindUsages::visit(SimpleDeclarationAST *)
|
||||
{
|
||||
++_inSimpleDeclaration;
|
||||
return true;
|
||||
}
|
||||
|
||||
void FindUsages::endVisit(SimpleDeclarationAST *)
|
||||
{ --_inSimpleDeclaration; }
|
||||
121
src/libs/cplusplus/FindUsages.h
Normal file
121
src/libs/cplusplus/FindUsages.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef FINDUSAGES_H
|
||||
#define FINDUSAGES_H
|
||||
|
||||
#include "LookupContext.h"
|
||||
#include "CppDocument.h"
|
||||
#include "CppBindings.h"
|
||||
#include "Semantic.h"
|
||||
|
||||
#include <ASTVisitor.h>
|
||||
#include <QtCore/QFutureInterface>
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
class CPLUSPLUS_EXPORT Usage
|
||||
{
|
||||
public:
|
||||
Usage()
|
||||
: line(0), col(0), len(0) {}
|
||||
|
||||
Usage(const QString &path, int line, const QString &lineText, int col, int len)
|
||||
: path(path), line(line), lineText(lineText), col(col), len(len) {}
|
||||
|
||||
public:
|
||||
QString path;
|
||||
int line;
|
||||
QString lineText;
|
||||
int col;
|
||||
int len;
|
||||
};
|
||||
|
||||
class CPLUSPLUS_EXPORT FindUsages: protected ASTVisitor
|
||||
{
|
||||
public:
|
||||
FindUsages(Document::Ptr doc, const Snapshot &snapshot, QFutureInterface<Usage> *future);
|
||||
|
||||
void setGlobalNamespaceBinding(NamespaceBindingPtr globalNamespaceBinding);
|
||||
|
||||
QList<int> operator()(Symbol *symbol, Identifier *id, AST *ast);
|
||||
|
||||
protected:
|
||||
using ASTVisitor::visit;
|
||||
using ASTVisitor::endVisit;
|
||||
|
||||
QString matchingLine(const Token &tk) const;
|
||||
|
||||
void reportResult(unsigned tokenIndex, const QList<Symbol *> &candidates);
|
||||
void reportResult(unsigned tokenIndex);
|
||||
|
||||
bool checkSymbol(Symbol *symbol) const;
|
||||
bool checkCandidates(const QList<Symbol *> &candidates) const;
|
||||
bool checkScope(Symbol *symbol, Symbol *otherSymbol) const;
|
||||
void checkExpression(unsigned startToken, unsigned endToken);
|
||||
|
||||
LookupContext currentContext(AST *ast);
|
||||
|
||||
void ensureNameIsValid(NameAST *ast);
|
||||
|
||||
virtual bool visit(MemInitializerAST *ast);
|
||||
virtual bool visit(PostfixExpressionAST *ast);
|
||||
virtual void endVisit(PostfixExpressionAST *);
|
||||
virtual bool visit(MemberAccessAST *ast);
|
||||
virtual bool visit(QualifiedNameAST *ast);
|
||||
virtual bool visit(EnumeratorAST *ast);
|
||||
virtual bool visit(SimpleNameAST *ast);
|
||||
virtual bool visit(DestructorNameAST *ast);
|
||||
virtual bool visit(TemplateIdAST *ast);
|
||||
virtual bool visit(ParameterDeclarationAST *ast);
|
||||
virtual bool visit(ExpressionOrDeclarationStatementAST *ast);
|
||||
virtual bool visit(FunctionDeclaratorAST *ast);
|
||||
virtual bool visit(SimpleDeclarationAST *);
|
||||
virtual void endVisit(SimpleDeclarationAST *);
|
||||
|
||||
private:
|
||||
QFutureInterface<Usage> *_future;
|
||||
Identifier *_id;
|
||||
Symbol *_declSymbol;
|
||||
Document::Ptr _doc;
|
||||
Snapshot _snapshot;
|
||||
QByteArray _source;
|
||||
Document::Ptr _exprDoc;
|
||||
Semantic _sem;
|
||||
NamespaceBindingPtr _globalNamespaceBinding;
|
||||
QList<PostfixExpressionAST *> _postfixExpressionStack;
|
||||
QList<QualifiedNameAST *> _qualifiedNameStack;
|
||||
QList<int> _references;
|
||||
LookupContext _previousContext;
|
||||
int _inSimpleDeclaration;
|
||||
};
|
||||
|
||||
} // end of namespace CPlusPlus
|
||||
|
||||
#endif // FINDUSAGES_H
|
||||
@@ -1,145 +1,377 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "GenTemplateInstance.h"
|
||||
#include "Overview.h"
|
||||
|
||||
#include <Control.h>
|
||||
#include <Scope.h>
|
||||
#include <Names.h>
|
||||
#include <Symbols.h>
|
||||
#include <CoreTypes.h>
|
||||
#include <Literals.h>
|
||||
|
||||
#include <QtCore/QVarLengthArray>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
GenTemplateInstance::GenTemplateInstance(Control *control, const Substitution &substitution)
|
||||
: _control(control),
|
||||
namespace {
|
||||
|
||||
class ApplySubstitution
|
||||
{
|
||||
public:
|
||||
ApplySubstitution(const LookupContext &context, Symbol *symbol, const GenTemplateInstance::Substitution &substitution);
|
||||
~ApplySubstitution();
|
||||
|
||||
Control *control() const { return context.control(); }
|
||||
|
||||
FullySpecifiedType apply(Name *name);
|
||||
FullySpecifiedType apply(const FullySpecifiedType &type);
|
||||
|
||||
int findSubstitution(Identifier *id) const;
|
||||
FullySpecifiedType applySubstitution(int index) const;
|
||||
|
||||
private:
|
||||
class ApplyToType: protected TypeVisitor
|
||||
{
|
||||
public:
|
||||
ApplyToType(ApplySubstitution *q)
|
||||
: q(q) {}
|
||||
|
||||
FullySpecifiedType operator()(const FullySpecifiedType &ty)
|
||||
{
|
||||
FullySpecifiedType previousType = switchType(ty);
|
||||
accept(ty.type());
|
||||
return switchType(previousType);
|
||||
}
|
||||
|
||||
protected:
|
||||
using TypeVisitor::visit;
|
||||
|
||||
Control *control() const
|
||||
{ return q->control(); }
|
||||
|
||||
FullySpecifiedType switchType(const FullySpecifiedType &type)
|
||||
{
|
||||
FullySpecifiedType previousType = _type;
|
||||
_type = type;
|
||||
return previousType;
|
||||
}
|
||||
|
||||
virtual void visit(VoidType *)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
virtual void visit(IntegerType *)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
virtual void visit(FloatType *)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
virtual void visit(PointerToMemberType *)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO; // ### TODO
|
||||
}
|
||||
|
||||
virtual void visit(PointerType *ptrTy)
|
||||
{
|
||||
_type.setType(control()->pointerType(q->apply(ptrTy->elementType())));
|
||||
}
|
||||
|
||||
virtual void visit(ReferenceType *refTy)
|
||||
{
|
||||
_type.setType(control()->referenceType(q->apply(refTy->elementType())));
|
||||
}
|
||||
|
||||
virtual void visit(ArrayType *arrayTy)
|
||||
{
|
||||
_type.setType(control()->arrayType(q->apply(arrayTy->elementType()), arrayTy->size()));
|
||||
}
|
||||
|
||||
virtual void visit(NamedType *ty)
|
||||
{
|
||||
FullySpecifiedType n = q->apply(ty->name());
|
||||
_type.setType(n.type());
|
||||
}
|
||||
|
||||
virtual void visit(Function *funTy)
|
||||
{
|
||||
Function *fun = control()->newFunction(/*sourceLocation=*/ 0, funTy->name());
|
||||
fun->setScope(funTy->scope());
|
||||
fun->setConst(funTy->isConst());
|
||||
fun->setVolatile(funTy->isVolatile());
|
||||
fun->setVirtual(funTy->isVirtual());
|
||||
fun->setAmbiguous(funTy->isAmbiguous());
|
||||
fun->setVariadic(funTy->isVariadic());
|
||||
|
||||
fun->setReturnType(q->apply(funTy->returnType()));
|
||||
|
||||
for (unsigned i = 0; i < funTy->argumentCount(); ++i) {
|
||||
Argument *originalArgument = funTy->argumentAt(i)->asArgument();
|
||||
Argument *arg = control()->newArgument(/*sourceLocation*/ 0,
|
||||
originalArgument->name());
|
||||
|
||||
arg->setType(q->apply(originalArgument->type()));
|
||||
arg->setInitializer(originalArgument->hasInitializer());
|
||||
fun->arguments()->enterSymbol(arg);
|
||||
}
|
||||
|
||||
_type.setType(fun);
|
||||
}
|
||||
|
||||
virtual void visit(Namespace *)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
virtual void visit(Class *)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
virtual void visit(Enum *)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
virtual void visit(ForwardClassDeclaration *)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
virtual void visit(ObjCClass *)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
virtual void visit(ObjCProtocol *)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
virtual void visit(ObjCMethod *)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
virtual void visit(ObjCForwardClassDeclaration *)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
virtual void visit(ObjCForwardProtocolDeclaration *)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
private:
|
||||
ApplySubstitution *q;
|
||||
FullySpecifiedType _type;
|
||||
QHash<Symbol *, FullySpecifiedType> _processed;
|
||||
};
|
||||
|
||||
class ApplyToName: protected NameVisitor
|
||||
{
|
||||
public:
|
||||
ApplyToName(ApplySubstitution *q): q(q) {}
|
||||
|
||||
FullySpecifiedType operator()(Name *name)
|
||||
{
|
||||
FullySpecifiedType previousType = switchType(FullySpecifiedType());
|
||||
accept(name);
|
||||
return switchType(previousType);
|
||||
}
|
||||
|
||||
protected:
|
||||
Control *control() const
|
||||
{ return q->control(); }
|
||||
|
||||
int findSubstitution(Identifier *id) const
|
||||
{ return q->findSubstitution(id); }
|
||||
|
||||
FullySpecifiedType applySubstitution(int index) const
|
||||
{ return q->applySubstitution(index); }
|
||||
|
||||
FullySpecifiedType switchType(const FullySpecifiedType &type)
|
||||
{
|
||||
FullySpecifiedType previousType = _type;
|
||||
_type = type;
|
||||
return previousType;
|
||||
}
|
||||
|
||||
virtual void visit(NameId *name)
|
||||
{
|
||||
int index = findSubstitution(name->identifier());
|
||||
|
||||
if (index != -1)
|
||||
_type = applySubstitution(index);
|
||||
|
||||
else
|
||||
_type = control()->namedType(name);
|
||||
}
|
||||
|
||||
virtual void visit(TemplateNameId *name)
|
||||
{
|
||||
QVarLengthArray<FullySpecifiedType, 8> arguments(name->templateArgumentCount());
|
||||
for (unsigned i = 0; i < name->templateArgumentCount(); ++i) {
|
||||
FullySpecifiedType argTy = name->templateArgumentAt(i);
|
||||
arguments[i] = q->apply(argTy);
|
||||
}
|
||||
|
||||
TemplateNameId *templId = control()->templateNameId(name->identifier(), arguments.data(), arguments.size());
|
||||
_type = control()->namedType(templId);
|
||||
}
|
||||
|
||||
virtual void visit(QualifiedNameId *name)
|
||||
{
|
||||
QVarLengthArray<Name *, 8> names(name->nameCount());
|
||||
for (unsigned i = 0; i < name->nameCount(); ++i) {
|
||||
Name *n = name->nameAt(i);
|
||||
|
||||
if (TemplateNameId *templId = n->asTemplateNameId()) {
|
||||
QVarLengthArray<FullySpecifiedType, 8> arguments(templId->templateArgumentCount());
|
||||
for (unsigned templateArgIndex = 0; templateArgIndex < templId->templateArgumentCount(); ++templateArgIndex) {
|
||||
FullySpecifiedType argTy = templId->templateArgumentAt(templateArgIndex);
|
||||
arguments[templateArgIndex] = q->apply(argTy);
|
||||
}
|
||||
|
||||
n = control()->templateNameId(templId->identifier(), arguments.data(), arguments.size());
|
||||
}
|
||||
|
||||
names[i] = n;
|
||||
}
|
||||
|
||||
QualifiedNameId *q = control()->qualifiedNameId(names.data(), names.size(), name->isGlobal());
|
||||
_type = control()->namedType(q);
|
||||
}
|
||||
|
||||
virtual void visit(DestructorNameId *name)
|
||||
{
|
||||
Overview oo;
|
||||
qWarning() << "ignored name:" << oo(name);
|
||||
}
|
||||
|
||||
virtual void visit(OperatorNameId *name)
|
||||
{
|
||||
Overview oo;
|
||||
qWarning() << "ignored name:" << oo(name);
|
||||
}
|
||||
|
||||
virtual void visit(ConversionNameId *name)
|
||||
{
|
||||
Overview oo;
|
||||
qWarning() << "ignored name:" << oo(name);
|
||||
}
|
||||
|
||||
virtual void visit(SelectorNameId *name)
|
||||
{
|
||||
Overview oo;
|
||||
qWarning() << "ignored name:" << oo(name);
|
||||
}
|
||||
|
||||
private:
|
||||
ApplySubstitution *q;
|
||||
FullySpecifiedType _type;
|
||||
};
|
||||
|
||||
public: // attributes
|
||||
LookupContext context;
|
||||
Symbol *symbol;
|
||||
GenTemplateInstance::Substitution substitution;
|
||||
ApplyToType applyToType;
|
||||
ApplyToName applyToName;
|
||||
};
|
||||
|
||||
ApplySubstitution::ApplySubstitution(const LookupContext &context, Symbol *symbol,
|
||||
const GenTemplateInstance::Substitution &substitution)
|
||||
: context(context), symbol(symbol),
|
||||
substitution(substitution),
|
||||
applyToType(this), applyToName(this)
|
||||
{ }
|
||||
|
||||
ApplySubstitution::~ApplySubstitution()
|
||||
{
|
||||
}
|
||||
|
||||
FullySpecifiedType ApplySubstitution::apply(Name *name)
|
||||
{
|
||||
FullySpecifiedType ty = applyToName(name);
|
||||
return ty;
|
||||
}
|
||||
|
||||
FullySpecifiedType ApplySubstitution::apply(const FullySpecifiedType &type)
|
||||
{
|
||||
FullySpecifiedType ty = applyToType(type);
|
||||
return ty;
|
||||
}
|
||||
|
||||
int ApplySubstitution::findSubstitution(Identifier *id) const
|
||||
{
|
||||
Q_ASSERT(id != 0);
|
||||
|
||||
for (int index = 0; index < substitution.size(); ++index) {
|
||||
QPair<Identifier *, FullySpecifiedType> s = substitution.at(index);
|
||||
|
||||
if (id->isEqualTo(s.first))
|
||||
return index;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
FullySpecifiedType ApplySubstitution::applySubstitution(int index) const
|
||||
{
|
||||
Q_ASSERT(index != -1);
|
||||
Q_ASSERT(index < substitution.size());
|
||||
|
||||
return substitution.at(index).second;
|
||||
}
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
||||
GenTemplateInstance::GenTemplateInstance(const LookupContext &context, const Substitution &substitution)
|
||||
: _symbol(0),
|
||||
_context(context),
|
||||
_substitution(substitution)
|
||||
{ }
|
||||
|
||||
FullySpecifiedType GenTemplateInstance::operator()(const FullySpecifiedType &ty)
|
||||
{ return subst(ty); }
|
||||
|
||||
FullySpecifiedType GenTemplateInstance::subst(Name *name)
|
||||
FullySpecifiedType GenTemplateInstance::operator()(Symbol *symbol)
|
||||
{
|
||||
if (TemplateNameId *t = name->asTemplateNameId()) {
|
||||
QVarLengthArray<FullySpecifiedType, 8> args(t->templateArgumentCount());
|
||||
|
||||
for (unsigned i = 0; i < t->templateArgumentCount(); ++i)
|
||||
args[i] = subst(t->templateArgumentAt(i));
|
||||
|
||||
TemplateNameId *n = _control->templateNameId(t->identifier(),
|
||||
args.data(), args.size());
|
||||
|
||||
return FullySpecifiedType(_control->namedType(n));
|
||||
} else if (name->isQualifiedNameId()) {
|
||||
// ### implement me
|
||||
}
|
||||
|
||||
for (int i = 0; i < _substitution.size(); ++i) {
|
||||
const QPair<Name *, FullySpecifiedType> s = _substitution.at(i);
|
||||
if (name->isEqualTo(s.first))
|
||||
return s.second;
|
||||
}
|
||||
|
||||
return FullySpecifiedType(_control->namedType(name));
|
||||
ApplySubstitution o(_context, symbol, _substitution);
|
||||
return o.apply(symbol->type());
|
||||
}
|
||||
|
||||
FullySpecifiedType GenTemplateInstance::subst(const FullySpecifiedType &ty)
|
||||
{
|
||||
FullySpecifiedType previousType = switchType(ty);
|
||||
TypeVisitor::accept(ty.type());
|
||||
return switchType(previousType);
|
||||
}
|
||||
|
||||
FullySpecifiedType GenTemplateInstance::switchType(const FullySpecifiedType &type)
|
||||
{
|
||||
FullySpecifiedType previousType = _type;
|
||||
_type = type;
|
||||
return previousType;
|
||||
}
|
||||
|
||||
// types
|
||||
void GenTemplateInstance::visit(PointerToMemberType * /*ty*/)
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
void GenTemplateInstance::visit(PointerType *ty)
|
||||
{
|
||||
FullySpecifiedType elementType = subst(ty->elementType());
|
||||
_type.setType(_control->pointerType(elementType));
|
||||
}
|
||||
|
||||
void GenTemplateInstance::visit(ReferenceType *ty)
|
||||
{
|
||||
FullySpecifiedType elementType = subst(ty->elementType());
|
||||
_type.setType(_control->referenceType(elementType));
|
||||
}
|
||||
|
||||
void GenTemplateInstance::visit(ArrayType *ty)
|
||||
{
|
||||
FullySpecifiedType elementType = subst(ty->elementType());
|
||||
_type.setType(_control->arrayType(elementType, ty->size()));
|
||||
}
|
||||
|
||||
void GenTemplateInstance::visit(NamedType *ty)
|
||||
{
|
||||
Name *name = ty->name();
|
||||
_type.setType(subst(name).type());
|
||||
}
|
||||
|
||||
void GenTemplateInstance::visit(Function *ty)
|
||||
{
|
||||
Name *name = ty->name();
|
||||
FullySpecifiedType returnType = subst(ty->returnType());
|
||||
|
||||
Function *fun = _control->newFunction(0, name);
|
||||
fun->setScope(ty->scope());
|
||||
fun->setConst(ty->isConst());
|
||||
fun->setVolatile(ty->isVolatile());
|
||||
fun->setReturnType(returnType);
|
||||
for (unsigned i = 0; i < ty->argumentCount(); ++i) {
|
||||
Symbol *arg = ty->argumentAt(i);
|
||||
FullySpecifiedType argTy = subst(arg->type());
|
||||
Argument *newArg = _control->newArgument(0, arg->name());
|
||||
newArg->setType(argTy);
|
||||
fun->arguments()->enterSymbol(newArg);
|
||||
}
|
||||
_type.setType(fun);
|
||||
}
|
||||
|
||||
void GenTemplateInstance::visit(VoidType *)
|
||||
{ /* nothing to do*/ }
|
||||
|
||||
void GenTemplateInstance::visit(IntegerType *)
|
||||
{ /* nothing to do*/ }
|
||||
|
||||
void GenTemplateInstance::visit(FloatType *)
|
||||
{ /* nothing to do*/ }
|
||||
|
||||
void GenTemplateInstance::visit(Namespace *)
|
||||
{ Q_ASSERT(false); }
|
||||
|
||||
void GenTemplateInstance::visit(Class *)
|
||||
{ Q_ASSERT(false); }
|
||||
|
||||
void GenTemplateInstance::visit(Enum *)
|
||||
{ Q_ASSERT(false); }
|
||||
|
||||
// names
|
||||
void GenTemplateInstance::visit(NameId *)
|
||||
{ Q_ASSERT(false); }
|
||||
|
||||
void GenTemplateInstance::visit(TemplateNameId *)
|
||||
{ Q_ASSERT(false); }
|
||||
|
||||
void GenTemplateInstance::visit(DestructorNameId *)
|
||||
{ Q_ASSERT(false); }
|
||||
|
||||
void GenTemplateInstance::visit(OperatorNameId *)
|
||||
{ Q_ASSERT(false); }
|
||||
|
||||
void GenTemplateInstance::visit(ConversionNameId *)
|
||||
{ Q_ASSERT(false); }
|
||||
|
||||
void GenTemplateInstance::visit(QualifiedNameId *)
|
||||
{ Q_ASSERT(false); }
|
||||
|
||||
Control *GenTemplateInstance::control() const
|
||||
{ return _context.control(); }
|
||||
|
||||
@@ -1,3 +1,32 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef GENTEMPLATEINSTANCE_H
|
||||
#define GENTEMPLATEINSTANCE_H
|
||||
|
||||
@@ -5,51 +34,28 @@
|
||||
#include <NameVisitor.h>
|
||||
#include <FullySpecifiedType.h>
|
||||
|
||||
#include "LookupContext.h"
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QPair>
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
class CPLUSPLUS_EXPORT GenTemplateInstance: protected TypeVisitor, protected NameVisitor
|
||||
class CPLUSPLUS_EXPORT GenTemplateInstance
|
||||
{
|
||||
public:
|
||||
typedef QList< QPair<Name *, FullySpecifiedType> > Substitution;
|
||||
typedef QList< QPair<Identifier *, FullySpecifiedType> > Substitution;
|
||||
|
||||
public:
|
||||
GenTemplateInstance(Control *control, const Substitution &substitution);
|
||||
GenTemplateInstance(const LookupContext &context, const Substitution &substitution);
|
||||
|
||||
FullySpecifiedType operator()(const FullySpecifiedType &ty);
|
||||
FullySpecifiedType operator()(Symbol *symbol);
|
||||
|
||||
protected:
|
||||
FullySpecifiedType subst(Name *name);
|
||||
FullySpecifiedType subst(const FullySpecifiedType &ty);
|
||||
|
||||
FullySpecifiedType switchType(const FullySpecifiedType &type);
|
||||
|
||||
virtual void visit(PointerToMemberType * /*ty*/);
|
||||
virtual void visit(PointerType *ty);
|
||||
virtual void visit(ReferenceType *ty);
|
||||
virtual void visit(ArrayType *ty);
|
||||
virtual void visit(NamedType *ty);
|
||||
virtual void visit(Function *ty);
|
||||
virtual void visit(VoidType *);
|
||||
virtual void visit(IntegerType *);
|
||||
virtual void visit(FloatType *);
|
||||
virtual void visit(Namespace *);
|
||||
virtual void visit(Class *);
|
||||
virtual void visit(Enum *);
|
||||
|
||||
// names
|
||||
virtual void visit(NameId *);
|
||||
virtual void visit(TemplateNameId *);
|
||||
virtual void visit(DestructorNameId *);
|
||||
virtual void visit(OperatorNameId *);
|
||||
virtual void visit(ConversionNameId *);
|
||||
virtual void visit(QualifiedNameId *);
|
||||
Control *control() const;
|
||||
|
||||
private:
|
||||
Control *_control;
|
||||
FullySpecifiedType _type;
|
||||
Symbol *_symbol;
|
||||
LookupContext _context;
|
||||
const Substitution _substitution;
|
||||
};
|
||||
|
||||
|
||||
@@ -347,8 +347,10 @@ QList<Scope *> LookupContext::buildVisibleScopes()
|
||||
}
|
||||
|
||||
QList<Scope *> LookupContext::visibleScopes(const QPair<FullySpecifiedType, Symbol *> &result) const
|
||||
{ return visibleScopes(result.second); }
|
||||
|
||||
QList<Scope *> LookupContext::visibleScopes(Symbol *symbol) const
|
||||
{
|
||||
Symbol *symbol = result.second;
|
||||
QList<Scope *> scopes;
|
||||
for (Scope *scope = symbol->scope(); scope; scope = scope->enclosingScope())
|
||||
scopes.append(scope);
|
||||
|
||||
@@ -98,6 +98,7 @@ public:
|
||||
QList<Scope *> visibleScopes() const
|
||||
{ return _visibleScopes; }
|
||||
|
||||
QList<Scope *> visibleScopes(Symbol *symbol) const;
|
||||
QList<Scope *> visibleScopes(const QPair<FullySpecifiedType, Symbol *> &result) const;
|
||||
|
||||
QList<Scope *> expand(const QList<Scope *> &scopes) const;
|
||||
|
||||
@@ -566,6 +566,11 @@ ResolveExpression::resolveBaseExpression(const QList<Result> &baseResults, int a
|
||||
FullySpecifiedType ty = result.first.simplified();
|
||||
Symbol *lastVisibleSymbol = result.second;
|
||||
|
||||
if (Function *funTy = ty->asFunctionType()) {
|
||||
if (funTy->isAmbiguous())
|
||||
ty = funTy->returnType().simplified();
|
||||
}
|
||||
|
||||
if (accessOp == T_ARROW) {
|
||||
if (lastVisibleSymbol && ty->isClassType() && ! lastVisibleSymbol->isClass()) {
|
||||
// ### remove ! lastVisibleSymbol->isClass() from the condition.
|
||||
@@ -695,7 +700,7 @@ ResolveExpression::resolveMember(Name *memberName, Class *klass,
|
||||
QList<Scope *> scopes;
|
||||
_context.expand(klass->members(), _context.visibleScopes(), &scopes);
|
||||
|
||||
QList<Symbol *> candidates = _context.resolve(memberName, scopes);
|
||||
const QList<Symbol *> candidates = _context.resolve(memberName, scopes);
|
||||
|
||||
foreach (Symbol *candidate, candidates) {
|
||||
FullySpecifiedType ty = candidate->type();
|
||||
@@ -710,13 +715,17 @@ ResolveExpression::resolveMember(Name *memberName, Class *klass,
|
||||
for (unsigned i = 0; i < templId->templateArgumentCount(); ++i) {
|
||||
FullySpecifiedType templArgTy = templId->templateArgumentAt(i);
|
||||
|
||||
if (i < klass->templateParameterCount())
|
||||
subst.append(qMakePair(klass->templateParameterAt(i)->name(),
|
||||
templArgTy));
|
||||
if (i < klass->templateParameterCount()) {
|
||||
Name *templArgName = klass->templateParameterAt(i)->name();
|
||||
if (templArgName && templArgName->identifier()) {
|
||||
Identifier *templArgId = templArgName->identifier();
|
||||
subst.append(qMakePair(templArgId, templArgTy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GenTemplateInstance inst(control(), subst);
|
||||
ty = inst(ty);
|
||||
GenTemplateInstance inst(_context, subst);
|
||||
ty = inst(candidate);
|
||||
}
|
||||
|
||||
results.append(Result(ty, candidate));
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
DEFINES += CPLUSPLUS_BUILD_LIB
|
||||
contains(CONFIG, dll) {
|
||||
DEFINES += CPLUSPLUS_BUILD_LIB
|
||||
} else {
|
||||
DEFINES += CPLUSPLUS_BUILD_STATIC_LIB
|
||||
}
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
include(../../shared/cplusplus/cplusplus.pri)
|
||||
@@ -33,6 +38,7 @@ HEADERS += \
|
||||
$$PWD/CppBindings.h \
|
||||
$$PWD/ASTParent.h \
|
||||
$$PWD/GenTemplateInstance.h \
|
||||
$$PWD/FindUsages.h \
|
||||
$$PWD/CheckUndefinedSymbols.h \
|
||||
$$PWD/PreprocessorClient.h \
|
||||
$$PWD/PreprocessorEnvironment.h \
|
||||
@@ -56,6 +62,7 @@ SOURCES += \
|
||||
$$PWD/CppBindings.cpp \
|
||||
$$PWD/ASTParent.cpp \
|
||||
$$PWD/GenTemplateInstance.cpp \
|
||||
$$PWD/FindUsages.cpp \
|
||||
$$PWD/CheckUndefinedSymbols.cpp \
|
||||
$$PWD/PreprocessorClient.cpp \
|
||||
$$PWD/PreprocessorEnvironment.cpp \
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG+=dll
|
||||
TARGET = CPlusPlus
|
||||
|
||||
DEFINES += NDEBUG
|
||||
|
||||
Reference in New Issue
Block a user