Merge remote-tracking branch 'origin/3.4'

Change-Id: I66ac8be7a8e99fc730131f75710bafc73809f593
This commit is contained in:
Eike Ziller
2015-03-02 12:11:32 +01:00
357 changed files with 2741 additions and 1622 deletions

View File

@@ -38,6 +38,7 @@
using namespace CPlusPlus;
BackwardsScanner::BackwardsScanner(const QTextCursor &cursor,
const LanguageFeatures &languageFeatures,
int maxBlockCount,
const QString &suffix,
bool skipComments)
@@ -46,13 +47,7 @@ BackwardsScanner::BackwardsScanner(const QTextCursor &cursor,
, _block(cursor.block())
, _maxBlockCount(maxBlockCount)
{
// FIXME: Why these defaults?
LanguageFeatures features;
features.qtMocRunEnabled = true;
features.qtEnabled = true;
features.qtKeywordsEnabled = true;
features.objCEnabled = true;
_tokenize.setLanguageFeatures(features);
_tokenize.setLanguageFeatures(languageFeatures);
_tokenize.setSkipComments(skipComments);
_text = _block.text().left(cursor.position() - cursor.block().position());

View File

@@ -43,10 +43,11 @@ class CPLUSPLUS_EXPORT BackwardsScanner
enum { MAX_BLOCK_COUNT = 10 };
public:
explicit BackwardsScanner(const QTextCursor &cursor,
int maxBlockCount = MAX_BLOCK_COUNT,
const QString &suffix = QString(),
bool skipComments = true);
BackwardsScanner(const QTextCursor &cursor,
const LanguageFeatures &languageFeatures,
int maxBlockCount = MAX_BLOCK_COUNT,
const QString &suffix = QString(),
bool skipComments = true);
int startToken() const;

View File

@@ -40,8 +40,9 @@
using namespace CPlusPlus;
ExpressionUnderCursor::ExpressionUnderCursor()
ExpressionUnderCursor::ExpressionUnderCursor(const LanguageFeatures &languageFeatures)
: _jumpedComma(false)
, _languageFeatures(languageFeatures)
{ }
int ExpressionUnderCursor::startOfExpression(BackwardsScanner &tk, int index)
@@ -243,7 +244,7 @@ bool ExpressionUnderCursor::isAccessToken(const Token &tk)
QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
{
BackwardsScanner scanner(cursor);
BackwardsScanner scanner(cursor, _languageFeatures);
_jumpedComma = false;
@@ -257,7 +258,7 @@ QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor) const
{
BackwardsScanner scanner(cursor);
BackwardsScanner scanner(cursor, _languageFeatures);
int index = scanner.startToken();

View File

@@ -32,6 +32,7 @@
#define CPLUSPLUS_EXPRESSIONUNDERCURSOR_H
#include <cplusplus/CPlusPlusForwardDeclarations.h>
#include <cplusplus/Token.h>
#include <QList>
@@ -47,7 +48,7 @@ class BackwardsScanner;
class CPLUSPLUS_EXPORT ExpressionUnderCursor
{
public:
ExpressionUnderCursor();
ExpressionUnderCursor(const LanguageFeatures &languageFeatures);
QString operator()(const QTextCursor &cursor);
int startOfFunctionCall(const QTextCursor &cursor) const;
@@ -59,6 +60,7 @@ private:
private:
bool _jumpedComma;
LanguageFeatures _languageFeatures;
};
} // namespace CPlusPlus

View File

@@ -324,7 +324,7 @@ ClassOrNamespace *LookupContext::globalNamespace() const
}
ClassOrNamespace *LookupContext::lookupType(const Name *name, Scope *scope,
ClassOrNamespace* enclosingTemplateInstantiation,
ClassOrNamespace *enclosingBinding,
QSet<const Declaration *> typedefsBeingResolved) const
{
if (! scope || ! name) {
@@ -367,7 +367,7 @@ ClassOrNamespace *LookupContext::lookupType(const Name *name, Scope *scope,
}
// try to find it in block (rare case but has priority before enclosing scope)
// e.g.: void foo() { struct S {}; S s; }
if (ClassOrNamespace *b = bindings()->lookupType(scope, enclosingTemplateInstantiation)) {
if (ClassOrNamespace *b = bindings()->lookupType(scope, enclosingBinding)) {
if (ClassOrNamespace *classOrNamespaceNestedInNestedBlock = b->lookupType(name, block))
return classOrNamespaceNestedInNestedBlock;
}
@@ -376,13 +376,13 @@ ClassOrNamespace *LookupContext::lookupType(const Name *name, Scope *scope,
if (ClassOrNamespace *found = lookupType(name, scope->enclosingScope()))
return found;
} else if (ClassOrNamespace *b = bindings()->lookupType(scope, enclosingTemplateInstantiation)) {
} else if (ClassOrNamespace *b = bindings()->lookupType(scope, enclosingBinding)) {
return b->lookupType(name);
} else if (Class *scopeAsClass = scope->asClass()) {
if (scopeAsClass->enclosingScope()->isBlock()) {
if (ClassOrNamespace *b = lookupType(scopeAsClass->name(),
scopeAsClass->enclosingScope(),
enclosingTemplateInstantiation,
enclosingBinding,
typedefsBeingResolved)) {
return b->lookupType(name);
}
@@ -393,9 +393,9 @@ ClassOrNamespace *LookupContext::lookupType(const Name *name, Scope *scope,
}
ClassOrNamespace *LookupContext::lookupType(Symbol *symbol,
ClassOrNamespace* enclosingTemplateInstantiation) const
ClassOrNamespace *enclosingBinding) const
{
return bindings()->lookupType(symbol, enclosingTemplateInstantiation);
return bindings()->lookupType(symbol, enclosingBinding);
}
QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const
@@ -1521,19 +1521,20 @@ ClassOrNamespace *CreateBindings::globalNamespace() const
return _globalNamespace;
}
ClassOrNamespace *CreateBindings::lookupType(Symbol *symbol, ClassOrNamespace* enclosingTemplateInstantiation)
ClassOrNamespace *CreateBindings::lookupType(Symbol *symbol, ClassOrNamespace *enclosingBinding)
{
const QList<const Name *> path = LookupContext::path(symbol);
return lookupType(path, enclosingTemplateInstantiation);
return lookupType(path, enclosingBinding);
}
ClassOrNamespace *CreateBindings::lookupType(const QList<const Name *> &path, ClassOrNamespace* enclosingTemplateInstantiation)
ClassOrNamespace *CreateBindings::lookupType(const QList<const Name *> &path,
ClassOrNamespace *enclosingBinding)
{
if (path.isEmpty())
return _globalNamespace;
if (enclosingTemplateInstantiation) {
if (ClassOrNamespace *b = enclosingTemplateInstantiation->lookupType(path.last()))
if (enclosingBinding) {
if (ClassOrNamespace *b = enclosingBinding->lookupType(path.last()))
return b;
}

View File

@@ -202,10 +202,9 @@ public:
ClassOrNamespace *globalNamespace() const;
/// Finds the binding associated to the given symbol.
ClassOrNamespace *lookupType(Symbol *symbol,
ClassOrNamespace* enclosingTemplateInstantiation = 0);
ClassOrNamespace *lookupType(Symbol *symbol, ClassOrNamespace *enclosingBinding = 0);
ClassOrNamespace *lookupType(const QList<const Name *> &path,
ClassOrNamespace* enclosingTemplateInstantiation = 0);
ClassOrNamespace *enclosingBinding = 0);
/// Returns the Control that must be used to create temporary symbols.
/// \internal
@@ -310,11 +309,11 @@ public:
QList<LookupItem> lookup(const Name *name, Scope *scope) const;
ClassOrNamespace *lookupType(const Name *name, Scope *scope,
ClassOrNamespace* enclosingTemplateInstantiation = 0,
ClassOrNamespace *enclosingBinding = 0,
QSet<const Declaration *> typedefsBeingResolved
= QSet<const Declaration *>()) const;
ClassOrNamespace *lookupType(Symbol *symbol,
ClassOrNamespace* enclosingTemplateInstantiation = 0) const;
ClassOrNamespace *enclosingBinding = 0) const;
ClassOrNamespace *lookupParent(Symbol *symbol) const;
/// \internal

View File

@@ -154,7 +154,8 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
if (text.isEmpty() || !shouldInsertMatchingText(la))
return QString();
BackwardsScanner tk(tc, MAX_NUM_LINES, textToProcess.left(*skippedChars));
BackwardsScanner tk(tc, LanguageFeatures::defaultFeatures(), MAX_NUM_LINES,
textToProcess.left(*skippedChars));
const int startToken = tk.startToken();
int index = startToken;
@@ -215,7 +216,7 @@ static bool shouldInsertNewline(const QTextCursor &tc)
QString MatchingText::insertParagraphSeparator(const QTextCursor &tc)
{
BackwardsScanner tk(tc, MAX_NUM_LINES);
BackwardsScanner tk(tc, LanguageFeatures::defaultFeatures(), MAX_NUM_LINES);
int index = tk.startToken();
if (tk[index - 1].isNot(T_LBRACE))

View File

@@ -612,7 +612,7 @@ bool ResolveExpression::visit(UnaryExpressionAST *ast)
added = true;
} else if (namedTy != 0) {
const Name *starOp = control()->operatorNameId(OperatorNameId::StarOp);
if (ClassOrNamespace *b = _context.lookupType(namedTy->name(), p.scope())) {
if (ClassOrNamespace *b = _context.lookupType(namedTy->name(), p.scope(), p.binding())) {
foreach (const LookupItem &r, b->find(starOp)) {
Symbol *overload = r.declaration();
if (Function *funTy = overload->type()->asFunctionType()) {
@@ -730,6 +730,7 @@ bool ResolveExpression::visit(SimpleNameAST *ast)
continue;
TypeOfExpression exprTyper;
exprTyper.setExpandTemplates(true);
Document::Ptr doc = _context.snapshot().document(QString::fromLocal8Bit(decl->fileName()));
exprTyper.init(doc, _context.snapshot(), _context.bindings(),
QSet<const Declaration* >(_autoDeclarationsBeingResolved) << decl);
@@ -754,10 +755,12 @@ bool ResolveExpression::visit(SimpleNameAST *ast)
if (n == 0) {
item.setType(newType);
item.setScope(typeItems[n].scope());
item.setBinding(typeItems[n].binding());
} else {
LookupItem newItem(item);
newItem.setType(newType);
newItem.setScope(typeItems[n].scope());
newItem.setBinding(typeItems[n].binding());
newCandidates.push_back(newItem);
}
}
@@ -1015,20 +1018,20 @@ bool ResolveExpression::visit(MemberAccessAST *ast)
}
ClassOrNamespace *ResolveExpression::findClass(const FullySpecifiedType &originalTy, Scope *scope,
ClassOrNamespace* enclosingTemplateInstantiation) const
ClassOrNamespace *enclosingBinding) const
{
FullySpecifiedType ty = originalTy.simplified();
ClassOrNamespace *binding = 0;
if (Class *klass = ty->asClassType()) {
if (scope->isBlock())
binding = _context.lookupType(klass->name(), scope, enclosingTemplateInstantiation);
binding = _context.lookupType(klass->name(), scope, enclosingBinding);
if (!binding)
binding = _context.lookupType(klass, enclosingTemplateInstantiation);
binding = _context.lookupType(klass, enclosingBinding);
}
else if (NamedType *namedTy = ty->asNamedType())
binding = _context.lookupType(namedTy->name(), scope, enclosingTemplateInstantiation);
binding = _context.lookupType(namedTy->name(), scope, enclosingBinding);
else if (Function *funTy = ty->asFunctionType())
return findClass(funTy->returnType(), scope);
@@ -1078,8 +1081,9 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas
ClassOrNamespace *binding
= findClassForTemplateParameterInExpressionScope(r.binding(),
ty);
if (! binding)
binding = findClass(ty, scope);
binding = findClass(ty, scope, r.binding());
if (binding){
// lookup for overloads of operator->
@@ -1145,13 +1149,13 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas
return binding;
}
ClassOrNamespace *enclosingTemplateInstantiation = 0;
ClassOrNamespace *enclosingBinding = 0;
if (ClassOrNamespace *binding = r.binding()) {
if (binding->instantiationOrigin())
enclosingTemplateInstantiation = binding;
enclosingBinding = binding;
}
if (ClassOrNamespace *binding = findClass(ty, scope, enclosingTemplateInstantiation))
if (ClassOrNamespace *binding = findClass(ty, scope, enclosingBinding))
return binding;
}
}

View File

@@ -61,7 +61,7 @@ public:
protected:
ClassOrNamespace *findClass(const FullySpecifiedType &ty, Scope *scope,
ClassOrNamespace* enclosingTemplateInstantiation = 0) const;
ClassOrNamespace *enclosingBinding = 0) const;
QList<LookupItem> expression(ExpressionAST *ast);

View File

@@ -129,17 +129,10 @@ int SimpleLexer::tokenAt(const Tokens &tokens, unsigned utf16charsOffset)
Token SimpleLexer::tokenAt(const QString &text,
unsigned utf16charsOffset,
int state,
bool qtMocRunEnabled)
const LanguageFeatures &languageFeatures)
{
// FIXME: Check default values.
LanguageFeatures features;
features.qtMocRunEnabled = qtMocRunEnabled;
features.qtEnabled = qtMocRunEnabled;
features.qtKeywordsEnabled = qtMocRunEnabled;
features.objCEnabled = qtMocRunEnabled;
features.cxx11Enabled = qtMocRunEnabled;
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
tokenize.setLanguageFeatures(languageFeatures);
const QVector<Token> tokens = tokenize(text, state);
const int tokenIdx = tokenAt(tokens, utf16charsOffset);
return (tokenIdx == -1) ? Token() : tokens.at(tokenIdx);

View File

@@ -68,7 +68,7 @@ public:
static Token tokenAt(const QString &text,
unsigned utf16charsOffset,
int state,
bool qtMocRunEnabled = false);
const LanguageFeatures &languageFeatures);
static int tokenBefore(const Tokens &tokens, unsigned utf16charsOffset);