2011-06-23 08:49:38 +08:00
|
|
|
//===--- SemaExprMember.cpp - Semantic Analysis for Expressions -----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements semantic analysis member access expressions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2014-10-28 02:07:46 +08:00
|
|
|
#include "clang/Sema/Overload.h"
|
This patch implements capturing of variables within generic lambdas.
Both Richard and I felt that the current wording in the working paper needed some tweaking - Please see http://llvm-reviews.chandlerc.com/D2035 for additional context and references to core-reflector messages that discuss wording tweaks.
What is implemented is what we had intended to specify in Bristol; but, recently felt that the specification might benefit from some tweaking and fleshing.
As a rough attempt to explain the semantics: If a nested lambda with a default-capture names a variable within its body, and if the enclosing full expression that contains the name of that variable is instantiation-dependent - then an enclosing lambda that is capture-ready (i.e. within a non-dependent context) must capture that variable, if all intervening nested lambdas can potentially capture that variable if they need to, and all intervening parent lambdas of the capture-ready lambda can and do capture the variable.
Of note, 'this' capturing is also currently underspecified in the working paper for generic lambdas. What is implemented here is if the set of candidate functions in a nested generic lambda includes both static and non-static member functions (regardless of viability checking - i.e. num and type of parameters/arguments) - and if all intervening nested-inner lambdas between the capture-ready lambda and the function-call containing nested lambda can capture 'this' and if all enclosing lambdas of the capture-ready lambda can capture 'this', then 'this' is speculatively captured by that capture-ready lambda.
Hopefully a paper for the C++ committee (that Richard and I had started some preliminary work on) is forthcoming.
This essentially makes generic lambdas feature complete, except for known bugs. The more prominent ones (and the ones I am currently aware of) being:
- generic lambdas and init-captures are broken - but a patch that fixes this is already in the works ...
- nested variadic expansions such as:
auto K = [](auto ... OuterArgs) {
vp([=](auto ... Is) {
decltype(OuterArgs) OA = OuterArgs;
return 0;
}(5)...);
return 0;
};
auto M = K('a', ' ', 1, " -- ", 3.14);
currently cause crashes. I think I know how to fix this (since I had done so in my initial implementation) - but it will probably take some work and back & forth with Doug and Richard.
A warm thanks to all who provided feedback - and especially to Doug Gregor and Richard Smith for their pivotal guidance: their insight and prestidigitation in such matters is boundless!
Now let's hope this commit doesn't upset the buildbot gods ;)
Thanks!
llvm-svn: 194188
2013-11-07 13:17:06 +08:00
|
|
|
#include "clang/AST/ASTLambda.h"
|
2011-06-23 08:49:38 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
|
|
|
#include "clang/AST/ExprCXX.h"
|
|
|
|
#include "clang/AST/ExprObjC.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Sema/Lookup.h"
|
|
|
|
#include "clang/Sema/Scope.h"
|
|
|
|
#include "clang/Sema/ScopeInfo.h"
|
2015-01-14 19:29:14 +08:00
|
|
|
#include "clang/Sema/SemaInternal.h"
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace sema;
|
|
|
|
|
2012-11-22 08:24:47 +08:00
|
|
|
typedef llvm::SmallPtrSet<const CXXRecordDecl*, 4> BaseSet;
|
|
|
|
static bool BaseIsNotInSet(const CXXRecordDecl *Base, void *BasesPtr) {
|
|
|
|
const BaseSet &Bases = *reinterpret_cast<const BaseSet*>(BasesPtr);
|
|
|
|
return !Bases.count(Base->getCanonicalDecl());
|
|
|
|
}
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
/// Determines if the given class is provably not derived from all of
|
|
|
|
/// the prospective base classes.
|
2012-11-22 08:24:47 +08:00
|
|
|
static bool isProvablyNotDerivedFrom(Sema &SemaRef, CXXRecordDecl *Record,
|
|
|
|
const BaseSet &Bases) {
|
|
|
|
void *BasesPtr = const_cast<void*>(reinterpret_cast<const void*>(&Bases));
|
|
|
|
return BaseIsNotInSet(Record, BasesPtr) &&
|
|
|
|
Record->forallBases(BaseIsNotInSet, BasesPtr);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum IMAKind {
|
|
|
|
/// The reference is definitely not an instance member access.
|
|
|
|
IMA_Static,
|
|
|
|
|
|
|
|
/// The reference may be an implicit instance member access.
|
|
|
|
IMA_Mixed,
|
|
|
|
|
2012-01-18 11:53:45 +08:00
|
|
|
/// The reference may be to an instance member, but it might be invalid if
|
2011-06-23 08:49:38 +08:00
|
|
|
/// so, because the context is not an instance method.
|
|
|
|
IMA_Mixed_StaticContext,
|
|
|
|
|
|
|
|
/// The reference may be to an instance member, but it is invalid if
|
|
|
|
/// so, because the context is from an unrelated class.
|
|
|
|
IMA_Mixed_Unrelated,
|
|
|
|
|
|
|
|
/// The reference is definitely an implicit instance member access.
|
|
|
|
IMA_Instance,
|
|
|
|
|
|
|
|
/// The reference may be to an unresolved using declaration.
|
|
|
|
IMA_Unresolved,
|
|
|
|
|
2013-05-03 08:10:13 +08:00
|
|
|
/// The reference is a contextually-permitted abstract member reference.
|
|
|
|
IMA_Abstract,
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
/// The reference may be to an unresolved using declaration and the
|
|
|
|
/// context is not an instance method.
|
|
|
|
IMA_Unresolved_StaticContext,
|
|
|
|
|
2012-01-20 09:26:23 +08:00
|
|
|
// The reference refers to a field which is not a member of the containing
|
|
|
|
// class, which is allowed because we're in C++11 mode and the context is
|
|
|
|
// unevaluated.
|
|
|
|
IMA_Field_Uneval_Context,
|
2012-01-18 11:53:45 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
/// All possible referrents are instance members and the current
|
|
|
|
/// context is not an instance method.
|
|
|
|
IMA_Error_StaticContext,
|
|
|
|
|
|
|
|
/// All possible referrents are instance members of an unrelated
|
|
|
|
/// class.
|
|
|
|
IMA_Error_Unrelated
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The given lookup names class member(s) and is not being used for
|
|
|
|
/// an address-of-member expression. Classify the type of access
|
|
|
|
/// according to whether it's possible that this reference names an
|
2012-01-18 11:53:45 +08:00
|
|
|
/// instance member. This is best-effort in dependent contexts; it is okay to
|
2011-06-23 08:49:38 +08:00
|
|
|
/// conservatively answer "yes", in which case some errors will simply
|
|
|
|
/// not be caught until template-instantiation.
|
|
|
|
static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef,
|
|
|
|
const LookupResult &R) {
|
|
|
|
assert(!R.empty() && (*R.begin())->isCXXClassMember());
|
|
|
|
|
|
|
|
DeclContext *DC = SemaRef.getFunctionLevelDeclContext();
|
|
|
|
|
2012-04-16 15:05:22 +08:00
|
|
|
bool isStaticContext = SemaRef.CXXThisTypeOverride.isNull() &&
|
|
|
|
(!isa<CXXMethodDecl>(DC) || cast<CXXMethodDecl>(DC)->isStatic());
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
if (R.isUnresolvableResult())
|
|
|
|
return isStaticContext ? IMA_Unresolved_StaticContext : IMA_Unresolved;
|
|
|
|
|
|
|
|
// Collect all the declaring classes of instance members we find.
|
|
|
|
bool hasNonInstance = false;
|
2012-01-18 11:53:45 +08:00
|
|
|
bool isField = false;
|
2012-11-22 08:24:47 +08:00
|
|
|
BaseSet Classes;
|
2011-06-23 08:49:38 +08:00
|
|
|
for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) {
|
|
|
|
NamedDecl *D = *I;
|
|
|
|
|
|
|
|
if (D->isCXXInstanceMember()) {
|
2015-04-10 19:37:55 +08:00
|
|
|
isField |= isa<FieldDecl>(D) || isa<MSPropertyDecl>(D) ||
|
|
|
|
isa<IndirectFieldDecl>(D);
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
CXXRecordDecl *R = cast<CXXRecordDecl>(D->getDeclContext());
|
|
|
|
Classes.insert(R->getCanonicalDecl());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hasNonInstance = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we didn't find any instance members, it can't be an implicit
|
|
|
|
// member reference.
|
|
|
|
if (Classes.empty())
|
|
|
|
return IMA_Static;
|
2013-05-03 08:10:13 +08:00
|
|
|
|
|
|
|
// C++11 [expr.prim.general]p12:
|
|
|
|
// An id-expression that denotes a non-static data member or non-static
|
|
|
|
// member function of a class can only be used:
|
|
|
|
// (...)
|
|
|
|
// - if that id-expression denotes a non-static data member and it
|
|
|
|
// appears in an unevaluated operand.
|
|
|
|
//
|
|
|
|
// This rule is specific to C++11. However, we also permit this form
|
|
|
|
// in unevaluated inline assembly operands, like the operand to a SIZE.
|
|
|
|
IMAKind AbstractInstanceResult = IMA_Static; // happens to be 'false'
|
|
|
|
assert(!AbstractInstanceResult);
|
|
|
|
switch (SemaRef.ExprEvalContexts.back().Context) {
|
|
|
|
case Sema::Unevaluated:
|
|
|
|
if (isField && SemaRef.getLangOpts().CPlusPlus11)
|
|
|
|
AbstractInstanceResult = IMA_Field_Uneval_Context;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Sema::UnevaluatedAbstract:
|
|
|
|
AbstractInstanceResult = IMA_Abstract;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Sema::ConstantEvaluated:
|
|
|
|
case Sema::PotentiallyEvaluated:
|
|
|
|
case Sema::PotentiallyEvaluatedIfUsed:
|
|
|
|
break;
|
2012-02-25 18:04:07 +08:00
|
|
|
}
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
// If the current context is not an instance method, it can't be
|
|
|
|
// an implicit member reference.
|
|
|
|
if (isStaticContext) {
|
|
|
|
if (hasNonInstance)
|
2012-02-25 18:04:07 +08:00
|
|
|
return IMA_Mixed_StaticContext;
|
|
|
|
|
2013-05-03 08:10:13 +08:00
|
|
|
return AbstractInstanceResult ? AbstractInstanceResult
|
|
|
|
: IMA_Error_StaticContext;
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXXRecordDecl *contextClass;
|
|
|
|
if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
|
|
|
|
contextClass = MD->getParent()->getCanonicalDecl();
|
|
|
|
else
|
|
|
|
contextClass = cast<CXXRecordDecl>(DC);
|
|
|
|
|
|
|
|
// [class.mfct.non-static]p3:
|
|
|
|
// ...is used in the body of a non-static member function of class X,
|
|
|
|
// if name lookup (3.4.1) resolves the name in the id-expression to a
|
|
|
|
// non-static non-type member of some class C [...]
|
|
|
|
// ...if C is not X or a base class of X, the class member access expression
|
|
|
|
// is ill-formed.
|
|
|
|
if (R.getNamingClass() &&
|
2012-02-25 08:11:55 +08:00
|
|
|
contextClass->getCanonicalDecl() !=
|
2012-11-22 08:24:47 +08:00
|
|
|
R.getNamingClass()->getCanonicalDecl()) {
|
|
|
|
// If the naming class is not the current context, this was a qualified
|
|
|
|
// member name lookup, and it's sufficient to check that we have the naming
|
|
|
|
// class as a base class.
|
|
|
|
Classes.clear();
|
2012-11-22 08:40:54 +08:00
|
|
|
Classes.insert(R.getNamingClass()->getCanonicalDecl());
|
2012-11-22 08:24:47 +08:00
|
|
|
}
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
// If we can prove that the current context is unrelated to all the
|
|
|
|
// declaring classes, it can't be an implicit member reference (in
|
|
|
|
// which case it's an error if any of those members are selected).
|
2012-11-22 08:24:47 +08:00
|
|
|
if (isProvablyNotDerivedFrom(SemaRef, contextClass, Classes))
|
2012-02-25 18:20:59 +08:00
|
|
|
return hasNonInstance ? IMA_Mixed_Unrelated :
|
2013-05-03 08:10:13 +08:00
|
|
|
AbstractInstanceResult ? AbstractInstanceResult :
|
|
|
|
IMA_Error_Unrelated;
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
return (hasNonInstance ? IMA_Mixed : IMA_Instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Diagnose a reference to a field with no object available.
|
2012-04-05 09:13:04 +08:00
|
|
|
static void diagnoseInstanceReference(Sema &SemaRef,
|
2011-06-23 08:49:38 +08:00
|
|
|
const CXXScopeSpec &SS,
|
2012-04-05 09:13:04 +08:00
|
|
|
NamedDecl *Rep,
|
2012-01-20 09:26:23 +08:00
|
|
|
const DeclarationNameInfo &nameInfo) {
|
2011-06-23 08:49:38 +08:00
|
|
|
SourceLocation Loc = nameInfo.getLoc();
|
|
|
|
SourceRange Range(Loc);
|
|
|
|
if (SS.isSet()) Range.setBegin(SS.getRange().getBegin());
|
2012-01-18 11:53:45 +08:00
|
|
|
|
2014-12-18 08:42:51 +08:00
|
|
|
// Look through using shadow decls and aliases.
|
|
|
|
Rep = Rep->getUnderlyingDecl();
|
|
|
|
|
2012-04-05 09:13:04 +08:00
|
|
|
DeclContext *FunctionLevelDC = SemaRef.getFunctionLevelDeclContext();
|
|
|
|
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FunctionLevelDC);
|
2014-05-26 14:22:03 +08:00
|
|
|
CXXRecordDecl *ContextClass = Method ? Method->getParent() : nullptr;
|
2012-04-05 09:13:04 +08:00
|
|
|
CXXRecordDecl *RepClass = dyn_cast<CXXRecordDecl>(Rep->getDeclContext());
|
|
|
|
|
|
|
|
bool InStaticMethod = Method && Method->isStatic();
|
|
|
|
bool IsField = isa<FieldDecl>(Rep) || isa<IndirectFieldDecl>(Rep);
|
|
|
|
|
|
|
|
if (IsField && InStaticMethod)
|
|
|
|
// "invalid use of member 'x' in static member function"
|
|
|
|
SemaRef.Diag(Loc, diag::err_invalid_member_use_in_static_method)
|
|
|
|
<< Range << nameInfo.getName();
|
|
|
|
else if (ContextClass && RepClass && SS.isEmpty() && !InStaticMethod &&
|
|
|
|
!RepClass->Equals(ContextClass) && RepClass->Encloses(ContextClass))
|
|
|
|
// Unqualified lookup in a non-static member function found a member of an
|
|
|
|
// enclosing class.
|
|
|
|
SemaRef.Diag(Loc, diag::err_nested_non_static_member_use)
|
|
|
|
<< IsField << RepClass << nameInfo.getName() << ContextClass << Range;
|
|
|
|
else if (IsField)
|
2012-01-20 09:26:23 +08:00
|
|
|
SemaRef.Diag(Loc, diag::err_invalid_non_static_member_use)
|
2012-04-05 09:13:04 +08:00
|
|
|
<< nameInfo.getName() << Range;
|
|
|
|
else
|
|
|
|
SemaRef.Diag(Loc, diag::err_member_call_without_object)
|
|
|
|
<< Range;
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Builds an expression which might be an implicit member expression.
|
|
|
|
ExprResult
|
|
|
|
Sema::BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
|
2012-01-27 17:46:47 +08:00
|
|
|
SourceLocation TemplateKWLoc,
|
2011-06-23 08:49:38 +08:00
|
|
|
LookupResult &R,
|
|
|
|
const TemplateArgumentListInfo *TemplateArgs) {
|
2014-12-18 08:42:51 +08:00
|
|
|
switch (ClassifyImplicitMemberAccess(*this, R)) {
|
2011-06-23 08:49:38 +08:00
|
|
|
case IMA_Instance:
|
2012-01-27 17:46:47 +08:00
|
|
|
return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, true);
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
case IMA_Mixed:
|
|
|
|
case IMA_Mixed_Unrelated:
|
|
|
|
case IMA_Unresolved:
|
2012-01-27 17:46:47 +08:00
|
|
|
return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, false);
|
2011-06-23 08:49:38 +08:00
|
|
|
|
2012-02-25 18:20:59 +08:00
|
|
|
case IMA_Field_Uneval_Context:
|
|
|
|
Diag(R.getNameLoc(), diag::warn_cxx98_compat_non_static_member_use)
|
|
|
|
<< R.getLookupNameInfo().getName();
|
|
|
|
// Fall through.
|
2011-06-23 08:49:38 +08:00
|
|
|
case IMA_Static:
|
2013-05-03 08:10:13 +08:00
|
|
|
case IMA_Abstract:
|
2011-06-23 08:49:38 +08:00
|
|
|
case IMA_Mixed_StaticContext:
|
|
|
|
case IMA_Unresolved_StaticContext:
|
2012-02-06 22:31:00 +08:00
|
|
|
if (TemplateArgs || TemplateKWLoc.isValid())
|
|
|
|
return BuildTemplateIdExpr(SS, TemplateKWLoc, R, false, TemplateArgs);
|
2011-06-23 08:49:38 +08:00
|
|
|
return BuildDeclarationNameExpr(SS, R, false);
|
|
|
|
|
|
|
|
case IMA_Error_StaticContext:
|
|
|
|
case IMA_Error_Unrelated:
|
2012-04-05 09:13:04 +08:00
|
|
|
diagnoseInstanceReference(*this, SS, R.getRepresentativeDecl(),
|
2011-06-23 08:49:38 +08:00
|
|
|
R.getLookupNameInfo());
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("unexpected instance member access kind");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Check an ext-vector component access expression.
|
|
|
|
///
|
|
|
|
/// VK should be set in advance to the value kind of the base
|
|
|
|
/// expression.
|
|
|
|
static QualType
|
|
|
|
CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK,
|
|
|
|
SourceLocation OpLoc, const IdentifierInfo *CompName,
|
|
|
|
SourceLocation CompLoc) {
|
|
|
|
// FIXME: Share logic with ExtVectorElementExpr::containsDuplicateElements,
|
|
|
|
// see FIXME there.
|
|
|
|
//
|
|
|
|
// FIXME: This logic can be greatly simplified by splitting it along
|
|
|
|
// halving/not halving and reworking the component checking.
|
|
|
|
const ExtVectorType *vecType = baseType->getAs<ExtVectorType>();
|
|
|
|
|
|
|
|
// The vector accessor can't exceed the number of elements.
|
|
|
|
const char *compStr = CompName->getNameStart();
|
|
|
|
|
|
|
|
// This flag determines whether or not the component is one of the four
|
|
|
|
// special names that indicate a subset of exactly half the elements are
|
|
|
|
// to be selected.
|
|
|
|
bool HalvingSwizzle = false;
|
|
|
|
|
|
|
|
// This flag determines whether or not CompName has an 's' char prefix,
|
|
|
|
// indicating that it is a string of hex values to be used as vector indices.
|
2014-04-04 03:43:01 +08:00
|
|
|
bool HexSwizzle = (*compStr == 's' || *compStr == 'S') && compStr[1];
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
bool HasRepeated = false;
|
|
|
|
bool HasIndex[16] = {};
|
|
|
|
|
|
|
|
int Idx;
|
|
|
|
|
|
|
|
// Check that we've found one of the special components, or that the component
|
|
|
|
// names must come from the same set.
|
|
|
|
if (!strcmp(compStr, "hi") || !strcmp(compStr, "lo") ||
|
|
|
|
!strcmp(compStr, "even") || !strcmp(compStr, "odd")) {
|
|
|
|
HalvingSwizzle = true;
|
|
|
|
} else if (!HexSwizzle &&
|
|
|
|
(Idx = vecType->getPointAccessorIdx(*compStr)) != -1) {
|
|
|
|
do {
|
|
|
|
if (HasIndex[Idx]) HasRepeated = true;
|
|
|
|
HasIndex[Idx] = true;
|
|
|
|
compStr++;
|
|
|
|
} while (*compStr && (Idx = vecType->getPointAccessorIdx(*compStr)) != -1);
|
|
|
|
} else {
|
|
|
|
if (HexSwizzle) compStr++;
|
|
|
|
while ((Idx = vecType->getNumericAccessorIdx(*compStr)) != -1) {
|
|
|
|
if (HasIndex[Idx]) HasRepeated = true;
|
|
|
|
HasIndex[Idx] = true;
|
|
|
|
compStr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HalvingSwizzle && *compStr) {
|
|
|
|
// We didn't get to the end of the string. This means the component names
|
|
|
|
// didn't come from the same set *or* we encountered an illegal name.
|
|
|
|
S.Diag(OpLoc, diag::err_ext_vector_component_name_illegal)
|
2011-07-23 18:55:15 +08:00
|
|
|
<< StringRef(compStr, 1) << SourceRange(CompLoc);
|
2011-06-23 08:49:38 +08:00
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure no component accessor exceeds the width of the vector type it
|
|
|
|
// operates on.
|
|
|
|
if (!HalvingSwizzle) {
|
|
|
|
compStr = CompName->getNameStart();
|
|
|
|
|
|
|
|
if (HexSwizzle)
|
|
|
|
compStr++;
|
|
|
|
|
|
|
|
while (*compStr) {
|
|
|
|
if (!vecType->isAccessorWithinNumElements(*compStr++)) {
|
|
|
|
S.Diag(OpLoc, diag::err_ext_vector_component_exceeds_length)
|
|
|
|
<< baseType << SourceRange(CompLoc);
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The component accessor looks fine - now we need to compute the actual type.
|
|
|
|
// The vector type is implied by the component accessor. For example,
|
|
|
|
// vec4.b is a float, vec4.xy is a vec2, vec4.rgb is a vec3, etc.
|
|
|
|
// vec4.s0 is a float, vec4.s23 is a vec3, etc.
|
|
|
|
// vec4.hi, vec4.lo, vec4.e, and vec4.o all return vec2.
|
|
|
|
unsigned CompSize = HalvingSwizzle ? (vecType->getNumElements() + 1) / 2
|
|
|
|
: CompName->getLength();
|
|
|
|
if (HexSwizzle)
|
|
|
|
CompSize--;
|
|
|
|
|
|
|
|
if (CompSize == 1)
|
|
|
|
return vecType->getElementType();
|
|
|
|
|
|
|
|
if (HasRepeated) VK = VK_RValue;
|
|
|
|
|
|
|
|
QualType VT = S.Context.getExtVectorType(vecType->getElementType(), CompSize);
|
|
|
|
// Now look up the TypeDefDecl from the vector type. Without this,
|
|
|
|
// diagostics look bad. We want extended vector types to appear built-in.
|
2011-07-28 08:39:29 +08:00
|
|
|
for (Sema::ExtVectorDeclsType::iterator
|
2012-10-19 03:05:02 +08:00
|
|
|
I = S.ExtVectorDecls.begin(S.getExternalSource()),
|
2011-07-28 08:39:29 +08:00
|
|
|
E = S.ExtVectorDecls.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if ((*I)->getUnderlyingType() == VT)
|
|
|
|
return S.Context.getTypedefType(*I);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
2011-07-28 08:39:29 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
return VT; // should never get here (a typedef type should always be found).
|
|
|
|
}
|
|
|
|
|
|
|
|
static Decl *FindGetterSetterNameDeclFromProtocolList(const ObjCProtocolDecl*PDecl,
|
|
|
|
IdentifierInfo *Member,
|
|
|
|
const Selector &Sel,
|
|
|
|
ASTContext &Context) {
|
|
|
|
if (Member)
|
|
|
|
if (ObjCPropertyDecl *PD = PDecl->FindPropertyDeclaration(Member))
|
|
|
|
return PD;
|
|
|
|
if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Sel))
|
|
|
|
return OMD;
|
|
|
|
|
2014-03-14 06:58:06 +08:00
|
|
|
for (const auto *I : PDecl->protocols()) {
|
|
|
|
if (Decl *D = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel,
|
2011-06-23 08:49:38 +08:00
|
|
|
Context))
|
|
|
|
return D;
|
|
|
|
}
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static Decl *FindGetterSetterNameDecl(const ObjCObjectPointerType *QIdTy,
|
|
|
|
IdentifierInfo *Member,
|
|
|
|
const Selector &Sel,
|
|
|
|
ASTContext &Context) {
|
|
|
|
// Check protocols on qualified interfaces.
|
2014-05-26 14:22:03 +08:00
|
|
|
Decl *GDecl = nullptr;
|
2014-03-18 00:14:00 +08:00
|
|
|
for (const auto *I : QIdTy->quals()) {
|
2011-06-23 08:49:38 +08:00
|
|
|
if (Member)
|
2014-03-18 00:14:00 +08:00
|
|
|
if (ObjCPropertyDecl *PD = I->FindPropertyDeclaration(Member)) {
|
2011-06-23 08:49:38 +08:00
|
|
|
GDecl = PD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Also must look for a getter or setter name which uses property syntax.
|
2014-03-18 00:14:00 +08:00
|
|
|
if (ObjCMethodDecl *OMD = I->getInstanceMethod(Sel)) {
|
2011-06-23 08:49:38 +08:00
|
|
|
GDecl = OMD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!GDecl) {
|
2014-03-18 00:14:00 +08:00
|
|
|
for (const auto *I : QIdTy->quals()) {
|
2011-06-23 08:49:38 +08:00
|
|
|
// Search in the protocol-qualifier list of current protocol.
|
2014-03-18 00:14:00 +08:00
|
|
|
GDecl = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel, Context);
|
2011-06-23 08:49:38 +08:00
|
|
|
if (GDecl)
|
|
|
|
return GDecl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExprResult
|
|
|
|
Sema::ActOnDependentMemberExpr(Expr *BaseExpr, QualType BaseType,
|
|
|
|
bool IsArrow, SourceLocation OpLoc,
|
|
|
|
const CXXScopeSpec &SS,
|
2012-01-27 17:46:47 +08:00
|
|
|
SourceLocation TemplateKWLoc,
|
2011-06-23 08:49:38 +08:00
|
|
|
NamedDecl *FirstQualifierInScope,
|
|
|
|
const DeclarationNameInfo &NameInfo,
|
|
|
|
const TemplateArgumentListInfo *TemplateArgs) {
|
|
|
|
// Even in dependent contexts, try to diagnose base expressions with
|
|
|
|
// obviously wrong types, e.g.:
|
|
|
|
//
|
|
|
|
// T* t;
|
|
|
|
// t.f;
|
|
|
|
//
|
|
|
|
// In Obj-C++, however, the above expression is valid, since it could be
|
|
|
|
// accessing the 'f' property if T is an Obj-C interface. The extra check
|
|
|
|
// allows this, while still reporting an error if T is a struct pointer.
|
|
|
|
if (!IsArrow) {
|
|
|
|
const PointerType *PT = BaseType->getAs<PointerType>();
|
2012-03-11 15:00:24 +08:00
|
|
|
if (PT && (!getLangOpts().ObjC1 ||
|
2011-06-23 08:49:38 +08:00
|
|
|
PT->getPointeeType()->isRecordType())) {
|
|
|
|
assert(BaseExpr && "cannot happen with implicit member accesses");
|
2012-04-21 09:12:48 +08:00
|
|
|
Diag(OpLoc, diag::err_typecheck_member_reference_struct_union)
|
2012-04-21 10:13:04 +08:00
|
|
|
<< BaseType << BaseExpr->getSourceRange() << NameInfo.getSourceRange();
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(BaseType->isDependentType() ||
|
|
|
|
NameInfo.getName().isDependentName() ||
|
|
|
|
isDependentScopeSpecifier(SS));
|
|
|
|
|
|
|
|
// Get the type being accessed in BaseType. If this is an arrow, the BaseExpr
|
|
|
|
// must have pointer type, and the accessed type is the pointee.
|
2014-05-29 22:05:12 +08:00
|
|
|
return CXXDependentScopeMemberExpr::Create(
|
|
|
|
Context, BaseExpr, BaseType, IsArrow, OpLoc,
|
|
|
|
SS.getWithLocInContext(Context), TemplateKWLoc, FirstQualifierInScope,
|
|
|
|
NameInfo, TemplateArgs);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// We know that the given qualified member reference points only to
|
|
|
|
/// declarations which do not belong to the static type of the base
|
|
|
|
/// expression. Diagnose the problem.
|
|
|
|
static void DiagnoseQualifiedMemberReference(Sema &SemaRef,
|
|
|
|
Expr *BaseExpr,
|
|
|
|
QualType BaseType,
|
|
|
|
const CXXScopeSpec &SS,
|
|
|
|
NamedDecl *rep,
|
|
|
|
const DeclarationNameInfo &nameInfo) {
|
|
|
|
// If this is an implicit member access, use a different set of
|
|
|
|
// diagnostics.
|
|
|
|
if (!BaseExpr)
|
2012-04-05 09:13:04 +08:00
|
|
|
return diagnoseInstanceReference(SemaRef, SS, rep, nameInfo);
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
SemaRef.Diag(nameInfo.getLoc(), diag::err_qualified_member_of_unrelated)
|
|
|
|
<< SS.getRange() << rep << BaseType;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the declarations we found through a nested-name
|
|
|
|
// specifier in a member expression are actually members of the base
|
|
|
|
// type. The restriction here is:
|
|
|
|
//
|
|
|
|
// C++ [expr.ref]p2:
|
|
|
|
// ... In these cases, the id-expression shall name a
|
|
|
|
// member of the class or of one of its base classes.
|
|
|
|
//
|
|
|
|
// So it's perfectly legitimate for the nested-name specifier to name
|
|
|
|
// an unrelated class, and for us to find an overload set including
|
|
|
|
// decls from classes which are not superclasses, as long as the decl
|
|
|
|
// we actually pick through overload resolution is from a superclass.
|
|
|
|
bool Sema::CheckQualifiedMemberReference(Expr *BaseExpr,
|
|
|
|
QualType BaseType,
|
|
|
|
const CXXScopeSpec &SS,
|
|
|
|
const LookupResult &R) {
|
2012-11-22 08:24:47 +08:00
|
|
|
CXXRecordDecl *BaseRecord =
|
|
|
|
cast_or_null<CXXRecordDecl>(computeDeclContext(BaseType));
|
|
|
|
if (!BaseRecord) {
|
2011-06-23 08:49:38 +08:00
|
|
|
// We can't check this yet because the base type is still
|
|
|
|
// dependent.
|
|
|
|
assert(BaseType->isDependentType());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) {
|
|
|
|
// If this is an implicit member reference and we find a
|
|
|
|
// non-instance member, it's not an error.
|
|
|
|
if (!BaseExpr && !(*I)->isCXXInstanceMember())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Note that we use the DC of the decl, not the underlying decl.
|
|
|
|
DeclContext *DC = (*I)->getDeclContext();
|
|
|
|
while (DC->isTransparentContext())
|
|
|
|
DC = DC->getParent();
|
|
|
|
|
|
|
|
if (!DC->isRecord())
|
|
|
|
continue;
|
|
|
|
|
2012-11-22 08:24:47 +08:00
|
|
|
CXXRecordDecl *MemberRecord = cast<CXXRecordDecl>(DC)->getCanonicalDecl();
|
|
|
|
if (BaseRecord->getCanonicalDecl() == MemberRecord ||
|
|
|
|
!BaseRecord->isProvablyNotDerivedFrom(MemberRecord))
|
2011-06-23 08:49:38 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DiagnoseQualifiedMemberReference(*this, BaseExpr, BaseType, SS,
|
|
|
|
R.getRepresentativeDecl(),
|
|
|
|
R.getLookupNameInfo());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-14 05:28:55 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Callback to only accept typo corrections that are either a ValueDecl or a
|
2013-10-19 08:05:00 +08:00
|
|
|
// FunctionTemplateDecl and are declared in the current record or, for a C++
|
|
|
|
// classes, one of its base classes.
|
2012-01-14 05:28:55 +08:00
|
|
|
class RecordMemberExprValidatorCCC : public CorrectionCandidateCallback {
|
2014-11-12 07:00:38 +08:00
|
|
|
public:
|
2013-10-19 08:05:00 +08:00
|
|
|
explicit RecordMemberExprValidatorCCC(const RecordType *RTy)
|
2014-11-12 07:00:40 +08:00
|
|
|
: Record(RTy->getDecl()) {
|
|
|
|
// Don't add bare keywords to the consumer since they will always fail
|
|
|
|
// validation by virtue of not being associated with any decls.
|
|
|
|
WantTypeSpecifiers = false;
|
|
|
|
WantExpressionKeywords = false;
|
|
|
|
WantCXXNamedCasts = false;
|
|
|
|
WantFunctionLikeCasts = false;
|
|
|
|
WantRemainingKeywords = false;
|
|
|
|
}
|
2013-10-19 08:05:00 +08:00
|
|
|
|
2014-03-12 12:55:44 +08:00
|
|
|
bool ValidateCandidate(const TypoCorrection &candidate) override {
|
2012-01-14 05:28:55 +08:00
|
|
|
NamedDecl *ND = candidate.getCorrectionDecl();
|
2013-10-19 08:05:00 +08:00
|
|
|
// Don't accept candidates that cannot be member functions, constants,
|
|
|
|
// variables, or templates.
|
|
|
|
if (!ND || !(isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Accept candidates that occur in the current record.
|
|
|
|
if (Record->containsDecl(ND))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Record)) {
|
|
|
|
// Accept candidates that occur in any of the current class' base classes.
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &BS : RD->bases()) {
|
2014-11-12 07:00:38 +08:00
|
|
|
if (const RecordType *BSTy =
|
|
|
|
dyn_cast_or_null<RecordType>(BS.getType().getTypePtrOrNull())) {
|
2013-10-19 08:05:00 +08:00
|
|
|
if (BSTy->getDecl()->containsDecl(ND))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-01-14 05:28:55 +08:00
|
|
|
}
|
2013-10-19 08:05:00 +08:00
|
|
|
|
2014-11-12 07:00:38 +08:00
|
|
|
private:
|
2013-10-19 08:05:00 +08:00
|
|
|
const RecordDecl *const Record;
|
2012-01-14 05:28:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-12 07:00:38 +08:00
|
|
|
static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
|
2014-11-12 07:26:54 +08:00
|
|
|
Expr *BaseExpr,
|
2014-11-12 07:00:38 +08:00
|
|
|
const RecordType *RTy,
|
2014-11-12 07:26:54 +08:00
|
|
|
SourceLocation OpLoc, bool IsArrow,
|
|
|
|
CXXScopeSpec &SS, bool HasTemplateArgs,
|
2014-11-12 07:26:58 +08:00
|
|
|
TypoExpr *&TE) {
|
2014-11-12 07:26:54 +08:00
|
|
|
SourceRange BaseRange = BaseExpr ? BaseExpr->getSourceRange() : SourceRange();
|
2011-06-23 08:49:38 +08:00
|
|
|
RecordDecl *RDecl = RTy->getDecl();
|
2012-04-16 15:05:22 +08:00
|
|
|
if (!SemaRef.isThisOutsideMemberFunctionBody(QualType(RTy, 0)) &&
|
|
|
|
SemaRef.RequireCompleteType(OpLoc, QualType(RTy, 0),
|
2012-05-05 00:32:21 +08:00
|
|
|
diag::err_typecheck_incomplete_tag,
|
|
|
|
BaseRange))
|
2011-06-23 08:49:38 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (HasTemplateArgs) {
|
|
|
|
// LookupTemplateName doesn't expect these both to exist simultaneously.
|
|
|
|
QualType ObjectType = SS.isSet() ? QualType() : QualType(RTy, 0);
|
|
|
|
|
|
|
|
bool MOUS;
|
2014-05-26 14:22:03 +08:00
|
|
|
SemaRef.LookupTemplateName(R, nullptr, SS, ObjectType, false, MOUS);
|
2011-06-23 08:49:38 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeclContext *DC = RDecl;
|
|
|
|
if (SS.isSet()) {
|
|
|
|
// If the member name was a qualified-id, look into the
|
|
|
|
// nested-name-specifier.
|
|
|
|
DC = SemaRef.computeDeclContext(SS, false);
|
|
|
|
|
|
|
|
if (SemaRef.RequireCompleteDeclContext(SS, DC)) {
|
|
|
|
SemaRef.Diag(SS.getRange().getEnd(), diag::err_typecheck_incomplete_tag)
|
2014-11-12 07:00:38 +08:00
|
|
|
<< SS.getRange() << DC;
|
2011-06-23 08:49:38 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(DC && "Cannot handle non-computable dependent contexts in lookup");
|
|
|
|
|
|
|
|
if (!isa<TypeDecl>(DC)) {
|
|
|
|
SemaRef.Diag(R.getNameLoc(), diag::err_qualified_member_nonclass)
|
2014-11-12 07:00:38 +08:00
|
|
|
<< DC << SS.getRange();
|
2011-06-23 08:49:38 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The record definition is complete, now look up the member.
|
2014-12-02 07:15:01 +08:00
|
|
|
SemaRef.LookupQualifiedName(R, DC, SS);
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
if (!R.empty())
|
|
|
|
return false;
|
|
|
|
|
2014-11-12 07:26:58 +08:00
|
|
|
DeclarationName Typo = R.getLookupName();
|
|
|
|
SourceLocation TypoLoc = R.getNameLoc();
|
|
|
|
TE = SemaRef.CorrectTypoDelayed(
|
2014-11-12 07:00:38 +08:00
|
|
|
R.getLookupNameInfo(), R.getLookupKind(), nullptr, &SS,
|
|
|
|
llvm::make_unique<RecordMemberExprValidatorCCC>(RTy),
|
2014-11-12 07:26:58 +08:00
|
|
|
[=, &SemaRef](const TypoCorrection &TC) {
|
|
|
|
if (TC) {
|
|
|
|
assert(!TC.isKeyword() &&
|
|
|
|
"Got a keyword as a correction for a member!");
|
|
|
|
bool DroppedSpecifier =
|
|
|
|
TC.WillReplaceSpecifier() &&
|
|
|
|
Typo.getAsString() == TC.getAsString(SemaRef.getLangOpts());
|
|
|
|
SemaRef.diagnoseTypo(TC, SemaRef.PDiag(diag::err_no_member_suggest)
|
|
|
|
<< Typo << DC << DroppedSpecifier
|
|
|
|
<< SS.getRange());
|
|
|
|
} else {
|
|
|
|
SemaRef.Diag(TypoLoc, diag::err_no_member) << Typo << DC << BaseRange;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[=](Sema &SemaRef, TypoExpr *TE, TypoCorrection TC) mutable {
|
|
|
|
R.clear(); // Ensure there's no decls lingering in the shared state.
|
|
|
|
R.suppressDiagnostics();
|
|
|
|
R.setLookupName(TC.getCorrection());
|
|
|
|
for (NamedDecl *ND : TC)
|
|
|
|
R.addDecl(ND);
|
|
|
|
R.resolveKind();
|
|
|
|
return SemaRef.BuildMemberReferenceExpr(
|
|
|
|
BaseExpr, BaseExpr->getType(), OpLoc, IsArrow, SS, SourceLocation(),
|
|
|
|
nullptr, R, nullptr);
|
|
|
|
},
|
2014-11-12 07:00:38 +08:00
|
|
|
Sema::CTK_ErrorRecovery, DC);
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
|
|
|
|
ExprResult &BaseExpr, bool &IsArrow,
|
|
|
|
SourceLocation OpLoc, CXXScopeSpec &SS,
|
|
|
|
Decl *ObjCImpDecl, bool HasTemplateArgs);
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
ExprResult
|
|
|
|
Sema::BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
|
|
|
|
SourceLocation OpLoc, bool IsArrow,
|
|
|
|
CXXScopeSpec &SS,
|
2012-01-27 17:46:47 +08:00
|
|
|
SourceLocation TemplateKWLoc,
|
2011-06-23 08:49:38 +08:00
|
|
|
NamedDecl *FirstQualifierInScope,
|
|
|
|
const DeclarationNameInfo &NameInfo,
|
2014-05-31 08:18:32 +08:00
|
|
|
const TemplateArgumentListInfo *TemplateArgs,
|
|
|
|
ActOnMemberAccessExtraArgs *ExtraArgs) {
|
2011-06-23 08:49:38 +08:00
|
|
|
if (BaseType->isDependentType() ||
|
|
|
|
(SS.isSet() && isDependentScopeSpecifier(SS)))
|
|
|
|
return ActOnDependentMemberExpr(Base, BaseType,
|
|
|
|
IsArrow, OpLoc,
|
2012-01-27 17:46:47 +08:00
|
|
|
SS, TemplateKWLoc, FirstQualifierInScope,
|
2011-06-23 08:49:38 +08:00
|
|
|
NameInfo, TemplateArgs);
|
|
|
|
|
|
|
|
LookupResult R(*this, NameInfo, LookupMemberName);
|
|
|
|
|
|
|
|
// Implicit member accesses.
|
|
|
|
if (!Base) {
|
2014-11-12 07:26:58 +08:00
|
|
|
TypoExpr *TE = nullptr;
|
2011-06-23 08:49:38 +08:00
|
|
|
QualType RecordTy = BaseType;
|
|
|
|
if (IsArrow) RecordTy = RecordTy->getAs<PointerType>()->getPointeeType();
|
2014-11-12 07:26:54 +08:00
|
|
|
if (LookupMemberExprInRecord(*this, R, nullptr,
|
|
|
|
RecordTy->getAs<RecordType>(), OpLoc, IsArrow,
|
2014-11-12 07:26:58 +08:00
|
|
|
SS, TemplateArgs != nullptr, TE))
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
2014-11-12 07:26:58 +08:00
|
|
|
if (TE)
|
|
|
|
return TE;
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
// Explicit member accesses.
|
|
|
|
} else {
|
2014-05-29 22:05:12 +08:00
|
|
|
ExprResult BaseResult = Base;
|
2014-05-31 08:18:32 +08:00
|
|
|
ExprResult Result = LookupMemberExpr(
|
|
|
|
*this, R, BaseResult, IsArrow, OpLoc, SS,
|
|
|
|
ExtraArgs ? ExtraArgs->ObjCImpDecl : nullptr,
|
|
|
|
TemplateArgs != nullptr);
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
if (BaseResult.isInvalid())
|
|
|
|
return ExprError();
|
2014-05-29 18:55:11 +08:00
|
|
|
Base = BaseResult.get();
|
2011-06-23 08:49:38 +08:00
|
|
|
|
2014-05-29 22:05:12 +08:00
|
|
|
if (Result.isInvalid())
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (Result.get())
|
2012-08-24 05:35:17 +08:00
|
|
|
return Result;
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
// LookupMemberExpr can modify Base, and thus change BaseType
|
|
|
|
BaseType = Base->getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
return BuildMemberReferenceExpr(Base, BaseType,
|
2012-01-27 17:46:47 +08:00
|
|
|
OpLoc, IsArrow, SS, TemplateKWLoc,
|
2014-05-31 08:18:32 +08:00
|
|
|
FirstQualifierInScope, R, TemplateArgs,
|
|
|
|
false, ExtraArgs);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ExprResult
|
|
|
|
BuildFieldReferenceExpr(Sema &S, Expr *BaseExpr, bool IsArrow,
|
2015-03-24 23:07:53 +08:00
|
|
|
SourceLocation OpLoc, const CXXScopeSpec &SS,
|
|
|
|
FieldDecl *Field, DeclAccessPair FoundDecl,
|
2011-06-23 08:49:38 +08:00
|
|
|
const DeclarationNameInfo &MemberNameInfo);
|
|
|
|
|
|
|
|
ExprResult
|
|
|
|
Sema::BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS,
|
|
|
|
SourceLocation loc,
|
|
|
|
IndirectFieldDecl *indirectField,
|
2013-07-16 08:01:31 +08:00
|
|
|
DeclAccessPair foundDecl,
|
2011-06-23 08:49:38 +08:00
|
|
|
Expr *baseObjectExpr,
|
|
|
|
SourceLocation opLoc) {
|
|
|
|
// First, build the expression that refers to the base object.
|
|
|
|
|
|
|
|
bool baseObjectIsPointer = false;
|
|
|
|
Qualifiers baseQuals;
|
|
|
|
|
|
|
|
// Case 1: the base of the indirect field is not a field.
|
|
|
|
VarDecl *baseVariable = indirectField->getVarDecl();
|
|
|
|
CXXScopeSpec EmptySS;
|
|
|
|
if (baseVariable) {
|
|
|
|
assert(baseVariable->getType()->isRecordType());
|
|
|
|
|
|
|
|
// In principle we could have a member access expression that
|
|
|
|
// accesses an anonymous struct/union that's a static member of
|
|
|
|
// the base object's class. However, under the current standard,
|
|
|
|
// static data members cannot be anonymous structs or unions.
|
|
|
|
// Supporting this is as easy as building a MemberExpr here.
|
|
|
|
assert(!baseObjectExpr && "anonymous struct/union is static data member?");
|
|
|
|
|
|
|
|
DeclarationNameInfo baseNameInfo(DeclarationName(), loc);
|
|
|
|
|
|
|
|
ExprResult result
|
|
|
|
= BuildDeclarationNameExpr(EmptySS, baseNameInfo, baseVariable);
|
|
|
|
if (result.isInvalid()) return ExprError();
|
|
|
|
|
2014-05-29 18:55:11 +08:00
|
|
|
baseObjectExpr = result.get();
|
2011-06-23 08:49:38 +08:00
|
|
|
baseObjectIsPointer = false;
|
|
|
|
baseQuals = baseObjectExpr->getType().getQualifiers();
|
|
|
|
|
|
|
|
// Case 2: the base of the indirect field is a field and the user
|
|
|
|
// wrote a member expression.
|
|
|
|
} else if (baseObjectExpr) {
|
|
|
|
// The caller provided the base object expression. Determine
|
|
|
|
// whether its a pointer and whether it adds any qualifiers to the
|
|
|
|
// anonymous struct/union fields we're looking into.
|
|
|
|
QualType objectType = baseObjectExpr->getType();
|
|
|
|
|
|
|
|
if (const PointerType *ptr = objectType->getAs<PointerType>()) {
|
|
|
|
baseObjectIsPointer = true;
|
|
|
|
objectType = ptr->getPointeeType();
|
|
|
|
} else {
|
|
|
|
baseObjectIsPointer = false;
|
|
|
|
}
|
|
|
|
baseQuals = objectType.getQualifiers();
|
|
|
|
|
|
|
|
// Case 3: the base of the indirect field is a field and we should
|
|
|
|
// build an implicit member access.
|
|
|
|
} else {
|
|
|
|
// We've found a member of an anonymous struct/union that is
|
|
|
|
// inside a non-anonymous struct/union, so in a well-formed
|
|
|
|
// program our base object expression is "this".
|
2011-10-19 00:47:30 +08:00
|
|
|
QualType ThisTy = getCurrentThisType();
|
2011-06-23 08:49:38 +08:00
|
|
|
if (ThisTy.isNull()) {
|
|
|
|
Diag(loc, diag::err_invalid_member_use_in_static_method)
|
|
|
|
<< indirectField->getDeclName();
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Our base object expression is "this".
|
2012-01-07 12:59:52 +08:00
|
|
|
CheckCXXThisCapture(loc);
|
2011-06-23 08:49:38 +08:00
|
|
|
baseObjectExpr
|
|
|
|
= new (Context) CXXThisExpr(loc, ThisTy, /*isImplicit=*/ true);
|
|
|
|
baseObjectIsPointer = true;
|
|
|
|
baseQuals = ThisTy->castAs<PointerType>()->getPointeeType().getQualifiers();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the implicit member references to the field of the
|
|
|
|
// anonymous struct/union.
|
|
|
|
Expr *result = baseObjectExpr;
|
|
|
|
IndirectFieldDecl::chain_iterator
|
|
|
|
FI = indirectField->chain_begin(), FEnd = indirectField->chain_end();
|
|
|
|
|
|
|
|
// Build the first member access in the chain with full information.
|
|
|
|
if (!baseVariable) {
|
|
|
|
FieldDecl *field = cast<FieldDecl>(*FI);
|
|
|
|
|
|
|
|
// Make a nameInfo that properly uses the anonymous name.
|
|
|
|
DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
|
2015-03-24 23:07:53 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
result = BuildFieldReferenceExpr(*this, result, baseObjectIsPointer,
|
2015-03-24 23:07:53 +08:00
|
|
|
SourceLocation(), EmptySS, field,
|
|
|
|
foundDecl, memberNameInfo).get();
|
2013-07-16 08:01:31 +08:00
|
|
|
if (!result)
|
|
|
|
return ExprError();
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
// FIXME: check qualified member access
|
|
|
|
}
|
|
|
|
|
|
|
|
// In all cases, we should now skip the first declaration in the chain.
|
|
|
|
++FI;
|
|
|
|
|
|
|
|
while (FI != FEnd) {
|
|
|
|
FieldDecl *field = cast<FieldDecl>(*FI++);
|
2013-07-16 08:01:31 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
// FIXME: these are somewhat meaningless
|
|
|
|
DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
|
2013-07-16 08:01:31 +08:00
|
|
|
DeclAccessPair fakeFoundDecl =
|
|
|
|
DeclAccessPair::make(field, field->getAccess());
|
|
|
|
|
2015-03-24 23:07:53 +08:00
|
|
|
result =
|
|
|
|
BuildFieldReferenceExpr(*this, result, /*isarrow*/ false,
|
|
|
|
SourceLocation(), (FI == FEnd ? SS : EmptySS),
|
|
|
|
field, fakeFoundDecl, memberNameInfo).get();
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
2014-05-29 22:05:12 +08:00
|
|
|
return result;
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:28:30 +08:00
|
|
|
static ExprResult
|
|
|
|
BuildMSPropertyRefExpr(Sema &S, Expr *BaseExpr, bool IsArrow,
|
|
|
|
const CXXScopeSpec &SS,
|
|
|
|
MSPropertyDecl *PD,
|
|
|
|
const DeclarationNameInfo &NameInfo) {
|
|
|
|
// Property names are always simple identifiers and therefore never
|
|
|
|
// require any interesting additional storage.
|
|
|
|
return new (S.Context) MSPropertyRefExpr(BaseExpr, PD, IsArrow,
|
|
|
|
S.Context.PseudoObjectTy, VK_LValue,
|
|
|
|
SS.getWithLocInContext(S.Context),
|
|
|
|
NameInfo.getLoc());
|
|
|
|
}
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
/// \brief Build a MemberExpr AST node.
|
2015-03-24 23:07:53 +08:00
|
|
|
static MemberExpr *BuildMemberExpr(
|
|
|
|
Sema &SemaRef, ASTContext &C, Expr *Base, bool isArrow,
|
|
|
|
SourceLocation OpLoc, const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
|
|
|
|
ValueDecl *Member, DeclAccessPair FoundDecl,
|
|
|
|
const DeclarationNameInfo &MemberNameInfo, QualType Ty, ExprValueKind VK,
|
|
|
|
ExprObjectKind OK, const TemplateArgumentListInfo *TemplateArgs = nullptr) {
|
2011-10-28 06:11:44 +08:00
|
|
|
assert((!isArrow || Base->isRValue()) && "-> base must be a pointer rvalue");
|
2015-03-24 23:07:53 +08:00
|
|
|
MemberExpr *E = MemberExpr::Create(
|
|
|
|
C, Base, isArrow, OpLoc, SS.getWithLocInContext(C), TemplateKWLoc, Member,
|
|
|
|
FoundDecl, MemberNameInfo, TemplateArgs, Ty, VK, OK);
|
2012-02-02 11:46:19 +08:00
|
|
|
SemaRef.MarkMemberReferenced(E);
|
|
|
|
return E;
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ExprResult
|
|
|
|
Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
|
|
|
|
SourceLocation OpLoc, bool IsArrow,
|
|
|
|
const CXXScopeSpec &SS,
|
2012-01-27 17:46:47 +08:00
|
|
|
SourceLocation TemplateKWLoc,
|
2011-06-23 08:49:38 +08:00
|
|
|
NamedDecl *FirstQualifierInScope,
|
|
|
|
LookupResult &R,
|
2012-04-26 03:49:54 +08:00
|
|
|
const TemplateArgumentListInfo *TemplateArgs,
|
|
|
|
bool SuppressQualifierCheck,
|
|
|
|
ActOnMemberAccessExtraArgs *ExtraArgs) {
|
2011-06-23 08:49:38 +08:00
|
|
|
QualType BaseType = BaseExprType;
|
|
|
|
if (IsArrow) {
|
|
|
|
assert(BaseType->isPointerType());
|
2011-10-26 01:37:35 +08:00
|
|
|
BaseType = BaseType->castAs<PointerType>()->getPointeeType();
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
R.setBaseObjectType(BaseType);
|
This patch implements capturing of variables within generic lambdas.
Both Richard and I felt that the current wording in the working paper needed some tweaking - Please see http://llvm-reviews.chandlerc.com/D2035 for additional context and references to core-reflector messages that discuss wording tweaks.
What is implemented is what we had intended to specify in Bristol; but, recently felt that the specification might benefit from some tweaking and fleshing.
As a rough attempt to explain the semantics: If a nested lambda with a default-capture names a variable within its body, and if the enclosing full expression that contains the name of that variable is instantiation-dependent - then an enclosing lambda that is capture-ready (i.e. within a non-dependent context) must capture that variable, if all intervening nested lambdas can potentially capture that variable if they need to, and all intervening parent lambdas of the capture-ready lambda can and do capture the variable.
Of note, 'this' capturing is also currently underspecified in the working paper for generic lambdas. What is implemented here is if the set of candidate functions in a nested generic lambda includes both static and non-static member functions (regardless of viability checking - i.e. num and type of parameters/arguments) - and if all intervening nested-inner lambdas between the capture-ready lambda and the function-call containing nested lambda can capture 'this' and if all enclosing lambdas of the capture-ready lambda can capture 'this', then 'this' is speculatively captured by that capture-ready lambda.
Hopefully a paper for the C++ committee (that Richard and I had started some preliminary work on) is forthcoming.
This essentially makes generic lambdas feature complete, except for known bugs. The more prominent ones (and the ones I am currently aware of) being:
- generic lambdas and init-captures are broken - but a patch that fixes this is already in the works ...
- nested variadic expansions such as:
auto K = [](auto ... OuterArgs) {
vp([=](auto ... Is) {
decltype(OuterArgs) OA = OuterArgs;
return 0;
}(5)...);
return 0;
};
auto M = K('a', ' ', 1, " -- ", 3.14);
currently cause crashes. I think I know how to fix this (since I had done so in my initial implementation) - but it will probably take some work and back & forth with Doug and Richard.
A warm thanks to all who provided feedback - and especially to Doug Gregor and Richard Smith for their pivotal guidance: their insight and prestidigitation in such matters is boundless!
Now let's hope this commit doesn't upset the buildbot gods ;)
Thanks!
llvm-svn: 194188
2013-11-07 13:17:06 +08:00
|
|
|
|
|
|
|
LambdaScopeInfo *const CurLSI = getCurLambda();
|
|
|
|
// If this is an implicit member reference and the overloaded
|
|
|
|
// name refers to both static and non-static member functions
|
|
|
|
// (i.e. BaseExpr is null) and if we are currently processing a lambda,
|
|
|
|
// check if we should/can capture 'this'...
|
|
|
|
// Keep this example in mind:
|
|
|
|
// struct X {
|
|
|
|
// void f(int) { }
|
|
|
|
// static void f(double) { }
|
|
|
|
//
|
|
|
|
// int g() {
|
|
|
|
// auto L = [=](auto a) {
|
|
|
|
// return [](int i) {
|
|
|
|
// return [=](auto b) {
|
|
|
|
// f(b);
|
|
|
|
// //f(decltype(a){});
|
|
|
|
// };
|
|
|
|
// };
|
|
|
|
// };
|
|
|
|
// auto M = L(0.0);
|
|
|
|
// auto N = M(3);
|
|
|
|
// N(5.32); // OK, must not error.
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
if (!BaseExpr && CurLSI) {
|
|
|
|
SourceLocation Loc = R.getNameLoc();
|
|
|
|
if (SS.getRange().isValid())
|
|
|
|
Loc = SS.getRange().getBegin();
|
|
|
|
DeclContext *EnclosingFunctionCtx = CurContext->getParent()->getParent();
|
|
|
|
// If the enclosing function is not dependent, then this lambda is
|
|
|
|
// capture ready, so if we can capture this, do so.
|
|
|
|
if (!EnclosingFunctionCtx->isDependentContext()) {
|
|
|
|
// If the current lambda and all enclosing lambdas can capture 'this' -
|
|
|
|
// then go ahead and capture 'this' (since our unresolved overload set
|
|
|
|
// contains both static and non-static member functions).
|
|
|
|
if (!CheckCXXThisCapture(Loc, /*Explcit*/false, /*Diagnose*/false))
|
|
|
|
CheckCXXThisCapture(Loc);
|
|
|
|
} else if (CurContext->isDependentContext()) {
|
|
|
|
// ... since this is an implicit member reference, that might potentially
|
|
|
|
// involve a 'this' capture, mark 'this' for potential capture in
|
|
|
|
// enclosing lambdas.
|
|
|
|
if (CurLSI->ImpCaptureStyle != CurLSI->ImpCap_None)
|
|
|
|
CurLSI->addPotentialThisCapture(Loc);
|
|
|
|
}
|
|
|
|
}
|
2011-06-23 08:49:38 +08:00
|
|
|
const DeclarationNameInfo &MemberNameInfo = R.getLookupNameInfo();
|
|
|
|
DeclarationName MemberName = MemberNameInfo.getName();
|
|
|
|
SourceLocation MemberLoc = MemberNameInfo.getLoc();
|
|
|
|
|
|
|
|
if (R.isAmbiguous())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (R.empty()) {
|
|
|
|
// Rederive where we looked up.
|
|
|
|
DeclContext *DC = (SS.isSet()
|
|
|
|
? computeDeclContext(SS, false)
|
|
|
|
: BaseType->getAs<RecordType>()->getDecl());
|
|
|
|
|
2012-04-26 03:49:54 +08:00
|
|
|
if (ExtraArgs) {
|
|
|
|
ExprResult RetryExpr;
|
|
|
|
if (!IsArrow && BaseExpr) {
|
2012-05-01 09:17:53 +08:00
|
|
|
SFINAETrap Trap(*this, true);
|
2012-04-26 03:49:54 +08:00
|
|
|
ParsedType ObjectType;
|
|
|
|
bool MayBePseudoDestructor = false;
|
|
|
|
RetryExpr = ActOnStartCXXMemberReference(getCurScope(), BaseExpr,
|
|
|
|
OpLoc, tok::arrow, ObjectType,
|
|
|
|
MayBePseudoDestructor);
|
|
|
|
if (RetryExpr.isUsable() && !Trap.hasErrorOccurred()) {
|
|
|
|
CXXScopeSpec TempSS(SS);
|
|
|
|
RetryExpr = ActOnMemberAccessExpr(
|
|
|
|
ExtraArgs->S, RetryExpr.get(), OpLoc, tok::arrow, TempSS,
|
2015-02-26 01:36:15 +08:00
|
|
|
TemplateKWLoc, ExtraArgs->Id, ExtraArgs->ObjCImpDecl);
|
2012-04-26 03:49:54 +08:00
|
|
|
}
|
|
|
|
if (Trap.hasErrorOccurred())
|
|
|
|
RetryExpr = ExprError();
|
|
|
|
}
|
|
|
|
if (RetryExpr.isUsable()) {
|
|
|
|
Diag(OpLoc, diag::err_no_member_overloaded_arrow)
|
|
|
|
<< MemberName << DC << FixItHint::CreateReplacement(OpLoc, "->");
|
|
|
|
return RetryExpr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
Diag(R.getNameLoc(), diag::err_no_member)
|
|
|
|
<< MemberName << DC
|
|
|
|
<< (BaseExpr ? BaseExpr->getSourceRange() : SourceRange());
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Diagnose lookups that find only declarations from a non-base
|
|
|
|
// type. This is possible for either qualified lookups (which may
|
|
|
|
// have been qualified with an unrelated type) or implicit member
|
|
|
|
// expressions (which were found with unqualified lookup and thus
|
|
|
|
// may have come from an enclosing scope). Note that it's okay for
|
|
|
|
// lookup to find declarations from a non-base type as long as those
|
|
|
|
// aren't the ones picked by overload resolution.
|
|
|
|
if ((SS.isSet() || !BaseExpr ||
|
|
|
|
(isa<CXXThisExpr>(BaseExpr) &&
|
|
|
|
cast<CXXThisExpr>(BaseExpr)->isImplicit())) &&
|
|
|
|
!SuppressQualifierCheck &&
|
|
|
|
CheckQualifiedMemberReference(BaseExpr, BaseType, SS, R))
|
|
|
|
return ExprError();
|
2011-10-18 05:00:22 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
// Construct an unresolved result if we in fact got an unresolved
|
|
|
|
// result.
|
|
|
|
if (R.isOverloadedResult() || R.isUnresolvableResult()) {
|
|
|
|
// Suppress any lookup-related diagnostics; we'll do these when we
|
|
|
|
// pick a member.
|
|
|
|
R.suppressDiagnostics();
|
|
|
|
|
|
|
|
UnresolvedMemberExpr *MemExpr
|
|
|
|
= UnresolvedMemberExpr::Create(Context, R.isUnresolvableResult(),
|
|
|
|
BaseExpr, BaseExprType,
|
|
|
|
IsArrow, OpLoc,
|
|
|
|
SS.getWithLocInContext(Context),
|
2012-01-27 17:46:47 +08:00
|
|
|
TemplateKWLoc, MemberNameInfo,
|
2011-06-23 08:49:38 +08:00
|
|
|
TemplateArgs, R.begin(), R.end());
|
|
|
|
|
2014-05-29 22:05:12 +08:00
|
|
|
return MemExpr;
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(R.isSingleResult());
|
|
|
|
DeclAccessPair FoundDecl = R.begin().getPair();
|
|
|
|
NamedDecl *MemberDecl = R.getFoundDecl();
|
|
|
|
|
|
|
|
// FIXME: diagnose the presence of template arguments now.
|
|
|
|
|
|
|
|
// If the decl being referenced had an error, return an error for this
|
|
|
|
// sub-expr without emitting another error, in order to avoid cascading
|
|
|
|
// error cases.
|
|
|
|
if (MemberDecl->isInvalidDecl())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// Handle the implicit-member-access case.
|
|
|
|
if (!BaseExpr) {
|
|
|
|
// If this is not an instance member, convert to a non-member access.
|
|
|
|
if (!MemberDecl->isCXXInstanceMember())
|
|
|
|
return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), MemberDecl);
|
|
|
|
|
|
|
|
SourceLocation Loc = R.getNameLoc();
|
|
|
|
if (SS.getRange().isValid())
|
|
|
|
Loc = SS.getRange().getBegin();
|
2012-01-07 12:59:52 +08:00
|
|
|
CheckCXXThisCapture(Loc);
|
2011-06-23 08:49:38 +08:00
|
|
|
BaseExpr = new (Context) CXXThisExpr(Loc, BaseExprType,/*isImplicit=*/true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShouldCheckUse = true;
|
|
|
|
if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(MemberDecl)) {
|
|
|
|
// Don't diagnose the use of a virtual member function unless it's
|
|
|
|
// explicitly qualified.
|
|
|
|
if (MD->isVirtual() && !SS.isSet())
|
|
|
|
ShouldCheckUse = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the use of this member.
|
2014-05-29 22:05:12 +08:00
|
|
|
if (ShouldCheckUse && DiagnoseUseOfDecl(MemberDecl, MemberLoc))
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl))
|
2015-03-24 23:07:53 +08:00
|
|
|
return BuildFieldReferenceExpr(*this, BaseExpr, IsArrow, OpLoc, SS, FD,
|
|
|
|
FoundDecl, MemberNameInfo);
|
2011-06-23 08:49:38 +08:00
|
|
|
|
2013-04-16 15:28:30 +08:00
|
|
|
if (MSPropertyDecl *PD = dyn_cast<MSPropertyDecl>(MemberDecl))
|
|
|
|
return BuildMSPropertyRefExpr(*this, BaseExpr, IsArrow, SS, PD,
|
|
|
|
MemberNameInfo);
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
if (IndirectFieldDecl *FD = dyn_cast<IndirectFieldDecl>(MemberDecl))
|
|
|
|
// We may have found a field within an anonymous union or struct
|
|
|
|
// (C++ [class.union]).
|
|
|
|
return BuildAnonymousStructUnionMemberReference(SS, MemberLoc, FD,
|
2013-07-16 08:01:31 +08:00
|
|
|
FoundDecl, BaseExpr,
|
|
|
|
OpLoc);
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
if (VarDecl *Var = dyn_cast<VarDecl>(MemberDecl)) {
|
2015-03-24 23:07:53 +08:00
|
|
|
return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
|
|
|
|
TemplateKWLoc, Var, FoundDecl, MemberNameInfo,
|
2014-05-29 22:05:12 +08:00
|
|
|
Var->getType().getNonReferenceType(), VK_LValue,
|
|
|
|
OK_Ordinary);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CXXMethodDecl *MemberFn = dyn_cast<CXXMethodDecl>(MemberDecl)) {
|
|
|
|
ExprValueKind valueKind;
|
|
|
|
QualType type;
|
|
|
|
if (MemberFn->isInstance()) {
|
|
|
|
valueKind = VK_RValue;
|
|
|
|
type = Context.BoundMemberTy;
|
|
|
|
} else {
|
|
|
|
valueKind = VK_LValue;
|
|
|
|
type = MemberFn->getType();
|
|
|
|
}
|
|
|
|
|
2015-03-24 23:07:53 +08:00
|
|
|
return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
|
|
|
|
TemplateKWLoc, MemberFn, FoundDecl, MemberNameInfo,
|
|
|
|
type, valueKind, OK_Ordinary);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
assert(!isa<FunctionDecl>(MemberDecl) && "member function not C++ method?");
|
|
|
|
|
|
|
|
if (EnumConstantDecl *Enum = dyn_cast<EnumConstantDecl>(MemberDecl)) {
|
2015-03-24 23:07:53 +08:00
|
|
|
return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS,
|
|
|
|
TemplateKWLoc, Enum, FoundDecl, MemberNameInfo,
|
|
|
|
Enum->getType(), VK_RValue, OK_Ordinary);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// We found something that we didn't expect. Complain.
|
|
|
|
if (isa<TypeDecl>(MemberDecl))
|
|
|
|
Diag(MemberLoc, diag::err_typecheck_member_reference_type)
|
|
|
|
<< MemberName << BaseType << int(IsArrow);
|
|
|
|
else
|
|
|
|
Diag(MemberLoc, diag::err_typecheck_member_reference_unknown)
|
|
|
|
<< MemberName << BaseType << int(IsArrow);
|
|
|
|
|
|
|
|
Diag(MemberDecl->getLocation(), diag::note_member_declared_here)
|
|
|
|
<< MemberName;
|
|
|
|
R.suppressDiagnostics();
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Given that normal member access failed on the given expression,
|
|
|
|
/// and given that the expression's type involves builtin-id or
|
|
|
|
/// builtin-Class, decide whether substituting in the redefinition
|
|
|
|
/// types would be profitable. The redefinition type is whatever
|
|
|
|
/// this translation unit tried to typedef to id/Class; we store
|
|
|
|
/// it to the side and then re-use it in places like this.
|
|
|
|
static bool ShouldTryAgainWithRedefinitionType(Sema &S, ExprResult &base) {
|
|
|
|
const ObjCObjectPointerType *opty
|
|
|
|
= base.get()->getType()->getAs<ObjCObjectPointerType>();
|
|
|
|
if (!opty) return false;
|
|
|
|
|
|
|
|
const ObjCObjectType *ty = opty->getObjectType();
|
|
|
|
|
|
|
|
QualType redef;
|
|
|
|
if (ty->isObjCId()) {
|
2011-08-12 04:58:55 +08:00
|
|
|
redef = S.Context.getObjCIdRedefinitionType();
|
2011-06-23 08:49:38 +08:00
|
|
|
} else if (ty->isObjCClass()) {
|
2011-08-12 04:58:55 +08:00
|
|
|
redef = S.Context.getObjCClassRedefinitionType();
|
2011-06-23 08:49:38 +08:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do the substitution as long as the redefinition type isn't just a
|
|
|
|
// possibly-qualified pointer to builtin-id or builtin-Class again.
|
|
|
|
opty = redef->getAs<ObjCObjectPointerType>();
|
2012-10-13 01:48:40 +08:00
|
|
|
if (opty && !opty->getObjectType()->getInterface())
|
2011-06-23 08:49:38 +08:00
|
|
|
return false;
|
|
|
|
|
2014-05-29 18:55:11 +08:00
|
|
|
base = S.ImpCastExprToType(base.get(), redef, CK_BitCast);
|
2011-06-23 08:49:38 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-12 07:14:30 +08:00
|
|
|
static bool isRecordType(QualType T) {
|
|
|
|
return T->isRecordType();
|
|
|
|
}
|
|
|
|
static bool isPointerToRecordType(QualType T) {
|
|
|
|
if (const PointerType *PT = T->getAs<PointerType>())
|
|
|
|
return PT->getPointeeType()->isRecordType();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-27 03:06:56 +08:00
|
|
|
/// Perform conversions on the LHS of a member access expression.
|
|
|
|
ExprResult
|
|
|
|
Sema::PerformMemberExprBaseConversion(Expr *Base, bool IsArrow) {
|
2012-01-13 10:20:01 +08:00
|
|
|
if (IsArrow && !Base->getType()->isFunctionType())
|
|
|
|
return DefaultFunctionArrayLvalueConversion(Base);
|
2011-10-27 03:06:56 +08:00
|
|
|
|
2012-01-13 10:20:01 +08:00
|
|
|
return CheckPlaceholderExpr(Base);
|
2011-10-27 03:06:56 +08:00
|
|
|
}
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
/// Look up the given member of the given non-type-dependent
|
|
|
|
/// expression. This can return in one of two ways:
|
|
|
|
/// * If it returns a sentinel null-but-valid result, the caller will
|
|
|
|
/// assume that lookup was performed and the results written into
|
|
|
|
/// the provided structure. It will take over from there.
|
|
|
|
/// * Otherwise, the returned expression will be produced in place of
|
|
|
|
/// an ordinary member expression.
|
|
|
|
///
|
|
|
|
/// The ObjCImpDecl bit is a gross hack that will need to be properly
|
|
|
|
/// fixed for ObjC++.
|
2014-05-31 08:18:32 +08:00
|
|
|
static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
|
|
|
|
ExprResult &BaseExpr, bool &IsArrow,
|
|
|
|
SourceLocation OpLoc, CXXScopeSpec &SS,
|
|
|
|
Decl *ObjCImpDecl, bool HasTemplateArgs) {
|
2011-06-23 08:49:38 +08:00
|
|
|
assert(BaseExpr.get() && "no base expression");
|
|
|
|
|
|
|
|
// Perform default conversions.
|
2014-05-31 08:18:32 +08:00
|
|
|
BaseExpr = S.PerformMemberExprBaseConversion(BaseExpr.get(), IsArrow);
|
2011-10-12 07:14:30 +08:00
|
|
|
if (BaseExpr.isInvalid())
|
|
|
|
return ExprError();
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
QualType BaseType = BaseExpr.get()->getType();
|
|
|
|
assert(!BaseType->isDependentType());
|
|
|
|
|
|
|
|
DeclarationName MemberName = R.getLookupName();
|
|
|
|
SourceLocation MemberLoc = R.getNameLoc();
|
|
|
|
|
|
|
|
// For later type-checking purposes, turn arrow accesses into dot
|
|
|
|
// accesses. The only access type we support that doesn't follow
|
|
|
|
// the C equivalence "a->b === (*a).b" is ObjC property accesses,
|
|
|
|
// and those never use arrows, so this is unaffected.
|
|
|
|
if (IsArrow) {
|
|
|
|
if (const PointerType *Ptr = BaseType->getAs<PointerType>())
|
|
|
|
BaseType = Ptr->getPointeeType();
|
|
|
|
else if (const ObjCObjectPointerType *Ptr
|
|
|
|
= BaseType->getAs<ObjCObjectPointerType>())
|
|
|
|
BaseType = Ptr->getPointeeType();
|
|
|
|
else if (BaseType->isRecordType()) {
|
|
|
|
// Recover from arrow accesses to records, e.g.:
|
|
|
|
// struct MyRecord foo;
|
|
|
|
// foo->bar
|
|
|
|
// This is actually well-formed in C++ if MyRecord has an
|
|
|
|
// overloaded operator->, but that should have been dealt with
|
2013-08-01 01:38:24 +08:00
|
|
|
// by now--or a diagnostic message already issued if a problem
|
|
|
|
// was encountered while looking for the overloaded operator->.
|
2014-05-31 08:18:32 +08:00
|
|
|
if (!S.getLangOpts().CPlusPlus) {
|
|
|
|
S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
|
2013-11-01 04:32:56 +08:00
|
|
|
<< BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange()
|
|
|
|
<< FixItHint::CreateReplacement(OpLoc, ".");
|
|
|
|
}
|
2011-06-23 08:49:38 +08:00
|
|
|
IsArrow = false;
|
2012-01-13 10:20:01 +08:00
|
|
|
} else if (BaseType->isFunctionType()) {
|
2011-06-23 08:49:38 +08:00
|
|
|
goto fail;
|
|
|
|
} else {
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(MemberLoc, diag::err_typecheck_member_reference_arrow)
|
2011-06-23 08:49:38 +08:00
|
|
|
<< BaseType << BaseExpr.get()->getSourceRange();
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle field access to simple records.
|
|
|
|
if (const RecordType *RTy = BaseType->getAs<RecordType>()) {
|
2014-10-28 02:07:46 +08:00
|
|
|
TypoExpr *TE = nullptr;
|
2014-11-12 07:26:54 +08:00
|
|
|
if (LookupMemberExprInRecord(S, R, BaseExpr.get(), RTy,
|
2014-11-12 07:26:58 +08:00
|
|
|
OpLoc, IsArrow, SS, HasTemplateArgs, TE))
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// Returning valid-but-null is how we indicate to the caller that
|
2014-10-28 02:07:46 +08:00
|
|
|
// the lookup result was filled in. If typo correction was attempted and
|
|
|
|
// failed, the lookup result will have been cleared--that combined with the
|
|
|
|
// valid-but-null ExprResult will trigger the appropriate diagnostics.
|
|
|
|
return ExprResult(TE);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle ivar access to Objective-C objects.
|
|
|
|
if (const ObjCObjectType *OTy = BaseType->getAs<ObjCObjectType>()) {
|
2011-10-11 00:09:49 +08:00
|
|
|
if (!SS.isEmpty() && !SS.isInvalid()) {
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access)
|
2011-10-10 07:22:49 +08:00
|
|
|
<< 1 << SS.getScopeRep()
|
|
|
|
<< FixItHint::CreateRemoval(SS.getRange());
|
|
|
|
SS.clear();
|
|
|
|
}
|
2014-05-31 08:18:32 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
|
|
|
|
|
|
|
|
// There are three cases for the base type:
|
|
|
|
// - builtin id (qualified or unqualified)
|
|
|
|
// - builtin Class (qualified or unqualified)
|
|
|
|
// - an interface
|
|
|
|
ObjCInterfaceDecl *IDecl = OTy->getInterface();
|
|
|
|
if (!IDecl) {
|
2014-05-31 08:18:32 +08:00
|
|
|
if (S.getLangOpts().ObjCAutoRefCount &&
|
2011-06-23 08:49:38 +08:00
|
|
|
(OTy->isObjCId() || OTy->isObjCClass()))
|
|
|
|
goto fail;
|
|
|
|
// There's an implicit 'isa' ivar on all objects.
|
|
|
|
// But we only actually find it this way on objects of type 'id',
|
2012-08-17 07:50:37 +08:00
|
|
|
// apparently.
|
2013-03-28 05:19:25 +08:00
|
|
|
if (OTy->isObjCId() && Member->isStr("isa"))
|
2014-05-31 08:18:32 +08:00
|
|
|
return new (S.Context) ObjCIsaExpr(BaseExpr.get(), IsArrow, MemberLoc,
|
|
|
|
OpLoc, S.Context.getObjCClassType());
|
|
|
|
if (ShouldTryAgainWithRedefinitionType(S, BaseExpr))
|
|
|
|
return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
|
2011-06-23 08:49:38 +08:00
|
|
|
ObjCImpDecl, HasTemplateArgs);
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-05-31 08:18:32 +08:00
|
|
|
|
|
|
|
if (S.RequireCompleteType(OpLoc, BaseType,
|
|
|
|
diag::err_typecheck_incomplete_tag,
|
|
|
|
BaseExpr.get()))
|
2012-01-03 01:18:37 +08:00
|
|
|
return ExprError();
|
2014-05-26 14:22:03 +08:00
|
|
|
|
|
|
|
ObjCInterfaceDecl *ClassDeclared = nullptr;
|
2011-06-23 08:49:38 +08:00
|
|
|
ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared);
|
|
|
|
|
|
|
|
if (!IV) {
|
|
|
|
// Attempt to correct for typos in ivar names.
|
2014-10-28 02:07:29 +08:00
|
|
|
auto Validator = llvm::make_unique<DeclFilterCCC<ObjCIvarDecl>>();
|
|
|
|
Validator->IsObjCIvarLookup = IsArrow;
|
2014-05-31 08:18:32 +08:00
|
|
|
if (TypoCorrection Corrected = S.CorrectTypo(
|
|
|
|
R.getLookupNameInfo(), Sema::LookupMemberName, nullptr, nullptr,
|
2014-10-28 02:07:29 +08:00
|
|
|
std::move(Validator), Sema::CTK_ErrorRecovery, IDecl)) {
|
2012-01-14 05:28:55 +08:00
|
|
|
IV = Corrected.getCorrectionDeclAs<ObjCIvarDecl>();
|
2014-05-31 08:18:32 +08:00
|
|
|
S.diagnoseTypo(
|
|
|
|
Corrected,
|
|
|
|
S.PDiag(diag::err_typecheck_member_reference_ivar_suggest)
|
|
|
|
<< IDecl->getDeclName() << MemberName);
|
2013-08-17 08:46:16 +08:00
|
|
|
|
2012-03-17 08:53:39 +08:00
|
|
|
// Figure out the class that declares the ivar.
|
|
|
|
assert(!ClassDeclared);
|
|
|
|
Decl *D = cast<Decl>(IV->getDeclContext());
|
|
|
|
if (ObjCCategoryDecl *CAT = dyn_cast<ObjCCategoryDecl>(D))
|
|
|
|
D = CAT->getClassInterface();
|
|
|
|
ClassDeclared = cast<ObjCInterfaceDecl>(D);
|
2011-06-23 08:49:38 +08:00
|
|
|
} else {
|
2011-06-28 08:00:52 +08:00
|
|
|
if (IsArrow && IDecl->FindPropertyDeclaration(Member)) {
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(MemberLoc, diag::err_property_found_suggest)
|
|
|
|
<< Member << BaseExpr.get()->getType()
|
|
|
|
<< FixItHint::CreateReplacement(OpLoc, ".");
|
2011-06-28 08:00:52 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
2011-06-23 08:49:38 +08:00
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(MemberLoc, diag::err_typecheck_member_reference_ivar)
|
|
|
|
<< IDecl->getDeclName() << MemberName
|
|
|
|
<< BaseExpr.get()->getSourceRange();
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
}
|
2014-05-31 08:18:32 +08:00
|
|
|
|
2012-03-17 08:53:39 +08:00
|
|
|
assert(ClassDeclared);
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
// If the decl being referenced had an error, return an error for this
|
|
|
|
// sub-expr without emitting another error, in order to avoid cascading
|
|
|
|
// error cases.
|
|
|
|
if (IV->isInvalidDecl())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// Check whether we can reference this field.
|
2014-05-31 08:18:32 +08:00
|
|
|
if (S.DiagnoseUseOfDecl(IV, MemberLoc))
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
|
|
|
if (IV->getAccessControl() != ObjCIvarDecl::Public &&
|
|
|
|
IV->getAccessControl() != ObjCIvarDecl::Package) {
|
2014-05-26 14:22:03 +08:00
|
|
|
ObjCInterfaceDecl *ClassOfMethodDecl = nullptr;
|
2014-05-31 08:18:32 +08:00
|
|
|
if (ObjCMethodDecl *MD = S.getCurMethodDecl())
|
2011-06-23 08:49:38 +08:00
|
|
|
ClassOfMethodDecl = MD->getClassInterface();
|
2014-05-31 08:18:32 +08:00
|
|
|
else if (ObjCImpDecl && S.getCurFunctionDecl()) {
|
2011-06-23 08:49:38 +08:00
|
|
|
// Case of a c-function declared inside an objc implementation.
|
|
|
|
// FIXME: For a c-style function nested inside an objc implementation
|
|
|
|
// class, there is no implementation context available, so we pass
|
|
|
|
// down the context as argument to this routine. Ideally, this context
|
|
|
|
// need be passed down in the AST node and somehow calculated from the
|
|
|
|
// AST for a function decl.
|
|
|
|
if (ObjCImplementationDecl *IMPD =
|
|
|
|
dyn_cast<ObjCImplementationDecl>(ObjCImpDecl))
|
|
|
|
ClassOfMethodDecl = IMPD->getClassInterface();
|
|
|
|
else if (ObjCCategoryImplDecl* CatImplClass =
|
|
|
|
dyn_cast<ObjCCategoryImplDecl>(ObjCImpDecl))
|
|
|
|
ClassOfMethodDecl = CatImplClass->getClassInterface();
|
|
|
|
}
|
2014-05-31 08:18:32 +08:00
|
|
|
if (!S.getLangOpts().DebuggerSupport) {
|
2012-03-07 08:58:41 +08:00
|
|
|
if (IV->getAccessControl() == ObjCIvarDecl::Private) {
|
|
|
|
if (!declaresSameEntity(ClassDeclared, IDecl) ||
|
|
|
|
!declaresSameEntity(ClassOfMethodDecl, ClassDeclared))
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(MemberLoc, diag::error_private_ivar_access)
|
2012-03-07 08:58:41 +08:00
|
|
|
<< IV->getDeclName();
|
|
|
|
} else if (!IDecl->isSuperClassOf(ClassOfMethodDecl))
|
|
|
|
// @protected
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(MemberLoc, diag::error_protected_ivar_access)
|
|
|
|
<< IV->getDeclName();
|
2012-03-07 08:58:41 +08:00
|
|
|
}
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
2012-08-08 07:48:10 +08:00
|
|
|
bool warn = true;
|
2014-05-31 08:18:32 +08:00
|
|
|
if (S.getLangOpts().ObjCAutoRefCount) {
|
2011-06-23 08:49:38 +08:00
|
|
|
Expr *BaseExp = BaseExpr.get()->IgnoreParenImpCasts();
|
|
|
|
if (UnaryOperator *UO = dyn_cast<UnaryOperator>(BaseExp))
|
|
|
|
if (UO->getOpcode() == UO_Deref)
|
|
|
|
BaseExp = UO->getSubExpr()->IgnoreParenCasts();
|
|
|
|
|
|
|
|
if (DeclRefExpr *DE = dyn_cast<DeclRefExpr>(BaseExp))
|
2012-08-08 07:48:10 +08:00
|
|
|
if (DE->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(DE->getLocation(), diag::error_arc_weak_ivar_access);
|
2012-08-08 07:48:10 +08:00
|
|
|
warn = false;
|
|
|
|
}
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
2012-08-09 00:41:04 +08:00
|
|
|
if (warn) {
|
2014-05-31 08:18:32 +08:00
|
|
|
if (ObjCMethodDecl *MD = S.getCurMethodDecl()) {
|
2012-08-08 00:38:44 +08:00
|
|
|
ObjCMethodFamily MF = MD->getMethodFamily();
|
|
|
|
warn = (MF != OMF_init && MF != OMF_dealloc &&
|
2013-02-15 03:07:19 +08:00
|
|
|
MF != OMF_finalize &&
|
2014-05-31 08:18:32 +08:00
|
|
|
!S.IvarBacksCurrentMethodAccessor(IDecl, MD, IV));
|
2012-08-08 00:38:44 +08:00
|
|
|
}
|
|
|
|
if (warn)
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(MemberLoc, diag::warn_direct_ivar_access) << IV->getDeclName();
|
2012-08-08 00:38:44 +08:00
|
|
|
}
|
2012-09-29 06:21:35 +08:00
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
ObjCIvarRefExpr *Result = new (S.Context) ObjCIvarRefExpr(
|
|
|
|
IV, IV->getType(), MemberLoc, OpLoc, BaseExpr.get(), IsArrow);
|
2012-09-29 06:21:35 +08:00
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
if (S.getLangOpts().ObjCAutoRefCount) {
|
2012-09-29 06:21:35 +08:00
|
|
|
if (IV->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
|
2014-06-16 07:30:39 +08:00
|
|
|
if (!S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, MemberLoc))
|
2014-05-31 08:18:32 +08:00
|
|
|
S.recordUseOfEvaluatedWeak(Result);
|
2012-09-29 06:21:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 22:05:12 +08:00
|
|
|
return Result;
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Objective-C property access.
|
|
|
|
const ObjCObjectPointerType *OPT;
|
|
|
|
if (!IsArrow && (OPT = BaseType->getAs<ObjCObjectPointerType>())) {
|
2011-10-11 00:09:49 +08:00
|
|
|
if (!SS.isEmpty() && !SS.isInvalid()) {
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access)
|
|
|
|
<< 0 << SS.getScopeRep() << FixItHint::CreateRemoval(SS.getRange());
|
2011-10-10 07:22:49 +08:00
|
|
|
SS.clear();
|
|
|
|
}
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
// This actually uses the base as an r-value.
|
2014-05-31 08:18:32 +08:00
|
|
|
BaseExpr = S.DefaultLvalueConversion(BaseExpr.get());
|
2011-06-23 08:49:38 +08:00
|
|
|
if (BaseExpr.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
assert(S.Context.hasSameUnqualifiedType(BaseType,
|
|
|
|
BaseExpr.get()->getType()));
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
|
|
|
|
|
|
|
|
const ObjCObjectType *OT = OPT->getObjectType();
|
|
|
|
|
|
|
|
// id, with and without qualifiers.
|
|
|
|
if (OT->isObjCId()) {
|
|
|
|
// Check protocols on qualified interfaces.
|
2014-05-31 08:18:32 +08:00
|
|
|
Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member);
|
|
|
|
if (Decl *PMDecl =
|
|
|
|
FindGetterSetterNameDecl(OPT, Member, Sel, S.Context)) {
|
2011-06-23 08:49:38 +08:00
|
|
|
if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(PMDecl)) {
|
|
|
|
// Check the use of this declaration
|
2014-05-31 08:18:32 +08:00
|
|
|
if (S.DiagnoseUseOfDecl(PD, MemberLoc))
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
return new (S.Context)
|
|
|
|
ObjCPropertyRefExpr(PD, S.Context.PseudoObjectTy, VK_LValue,
|
2014-05-29 22:05:12 +08:00
|
|
|
OK_ObjCProperty, MemberLoc, BaseExpr.get());
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(PMDecl)) {
|
|
|
|
// Check the use of this method.
|
2014-05-31 08:18:32 +08:00
|
|
|
if (S.DiagnoseUseOfDecl(OMD, MemberLoc))
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
|
|
|
Selector SetterSel =
|
2014-05-31 08:18:32 +08:00
|
|
|
SelectorTable::constructSetterSelector(S.PP.getIdentifierTable(),
|
|
|
|
S.PP.getSelectorTable(),
|
2013-06-08 06:29:12 +08:00
|
|
|
Member);
|
2014-05-26 14:22:03 +08:00
|
|
|
ObjCMethodDecl *SMD = nullptr;
|
|
|
|
if (Decl *SDecl = FindGetterSetterNameDecl(OPT,
|
2014-05-31 08:18:32 +08:00
|
|
|
/*Property id*/ nullptr,
|
|
|
|
SetterSel, S.Context))
|
2011-06-23 08:49:38 +08:00
|
|
|
SMD = dyn_cast<ObjCMethodDecl>(SDecl);
|
2014-05-31 08:18:32 +08:00
|
|
|
|
|
|
|
return new (S.Context)
|
|
|
|
ObjCPropertyRefExpr(OMD, SMD, S.Context.PseudoObjectTy, VK_LValue,
|
2014-05-29 22:05:12 +08:00
|
|
|
OK_ObjCProperty, MemberLoc, BaseExpr.get());
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Use of id.member can only be for a property reference. Do not
|
|
|
|
// use the 'id' redefinition in this case.
|
2014-05-31 08:18:32 +08:00
|
|
|
if (IsArrow && ShouldTryAgainWithRedefinitionType(S, BaseExpr))
|
|
|
|
return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
|
2011-06-23 08:49:38 +08:00
|
|
|
ObjCImpDecl, HasTemplateArgs);
|
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
return ExprError(S.Diag(MemberLoc, diag::err_property_not_found)
|
2011-06-23 08:49:38 +08:00
|
|
|
<< MemberName << BaseType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 'Class', unqualified only.
|
|
|
|
if (OT->isObjCClass()) {
|
|
|
|
// Only works in a method declaration (??!).
|
2014-05-31 08:18:32 +08:00
|
|
|
ObjCMethodDecl *MD = S.getCurMethodDecl();
|
2011-06-23 08:49:38 +08:00
|
|
|
if (!MD) {
|
2014-05-31 08:18:32 +08:00
|
|
|
if (ShouldTryAgainWithRedefinitionType(S, BaseExpr))
|
|
|
|
return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
|
2011-06-23 08:49:38 +08:00
|
|
|
ObjCImpDecl, HasTemplateArgs);
|
|
|
|
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also must look for a getter name which uses property syntax.
|
2014-05-31 08:18:32 +08:00
|
|
|
Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member);
|
2011-06-23 08:49:38 +08:00
|
|
|
ObjCInterfaceDecl *IFace = MD->getClassInterface();
|
|
|
|
ObjCMethodDecl *Getter;
|
|
|
|
if ((Getter = IFace->lookupClassMethod(Sel))) {
|
|
|
|
// Check the use of this method.
|
2014-05-31 08:18:32 +08:00
|
|
|
if (S.DiagnoseUseOfDecl(Getter, MemberLoc))
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
|
|
|
} else
|
|
|
|
Getter = IFace->lookupPrivateMethod(Sel, false);
|
|
|
|
// If we found a getter then this may be a valid dot-reference, we
|
|
|
|
// will look for the matching setter, in case it is needed.
|
|
|
|
Selector SetterSel =
|
2014-05-31 08:18:32 +08:00
|
|
|
SelectorTable::constructSetterSelector(S.PP.getIdentifierTable(),
|
|
|
|
S.PP.getSelectorTable(),
|
2013-06-08 06:29:12 +08:00
|
|
|
Member);
|
2011-06-23 08:49:38 +08:00
|
|
|
ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel);
|
|
|
|
if (!Setter) {
|
|
|
|
// If this reference is in an @implementation, also check for 'private'
|
|
|
|
// methods.
|
|
|
|
Setter = IFace->lookupPrivateMethod(SetterSel, false);
|
|
|
|
}
|
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
if (Setter && S.DiagnoseUseOfDecl(Setter, MemberLoc))
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
if (Getter || Setter) {
|
2014-05-31 08:18:32 +08:00
|
|
|
return new (S.Context) ObjCPropertyRefExpr(
|
|
|
|
Getter, Setter, S.Context.PseudoObjectTy, VK_LValue,
|
|
|
|
OK_ObjCProperty, MemberLoc, BaseExpr.get());
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
if (ShouldTryAgainWithRedefinitionType(S, BaseExpr))
|
|
|
|
return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
|
2011-06-23 08:49:38 +08:00
|
|
|
ObjCImpDecl, HasTemplateArgs);
|
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
return ExprError(S.Diag(MemberLoc, diag::err_property_not_found)
|
2011-06-23 08:49:38 +08:00
|
|
|
<< MemberName << BaseType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normal property access.
|
2014-05-31 08:18:32 +08:00
|
|
|
return S.HandleExprPropertyRefExpr(OPT, BaseExpr.get(), OpLoc, MemberName,
|
|
|
|
MemberLoc, SourceLocation(), QualType(),
|
|
|
|
false);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle 'field access' to vectors, such as 'V.xx'.
|
|
|
|
if (BaseType->isExtVectorType()) {
|
|
|
|
// FIXME: this expr should store IsArrow.
|
|
|
|
IdentifierInfo *Member = MemberName.getAsIdentifierInfo();
|
2015-04-07 00:56:39 +08:00
|
|
|
ExprValueKind VK;
|
|
|
|
if (IsArrow)
|
|
|
|
VK = VK_LValue;
|
|
|
|
else {
|
|
|
|
if (PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(BaseExpr.get()))
|
|
|
|
VK = POE->getSyntacticForm()->getValueKind();
|
|
|
|
else
|
|
|
|
VK = BaseExpr.get()->getValueKind();
|
|
|
|
}
|
2014-05-31 08:18:32 +08:00
|
|
|
QualType ret = CheckExtVectorComponent(S, BaseType, VK, OpLoc,
|
2011-06-23 08:49:38 +08:00
|
|
|
Member, MemberLoc);
|
|
|
|
if (ret.isNull())
|
|
|
|
return ExprError();
|
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
return new (S.Context)
|
2014-05-29 22:05:12 +08:00
|
|
|
ExtVectorElementExpr(ret, VK, BaseExpr.get(), *Member, MemberLoc);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust builtin-sel to the appropriate redefinition type if that's
|
|
|
|
// not just a pointer to builtin-sel again.
|
2014-05-31 08:18:32 +08:00
|
|
|
if (IsArrow && BaseType->isSpecificBuiltinType(BuiltinType::ObjCSel) &&
|
|
|
|
!S.Context.getObjCSelRedefinitionType()->isObjCSelType()) {
|
|
|
|
BaseExpr = S.ImpCastExprToType(
|
|
|
|
BaseExpr.get(), S.Context.getObjCSelRedefinitionType(), CK_BitCast);
|
|
|
|
return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
|
2011-06-23 08:49:38 +08:00
|
|
|
ObjCImpDecl, HasTemplateArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Failure cases.
|
|
|
|
fail:
|
|
|
|
|
|
|
|
// Recover from dot accesses to pointers, e.g.:
|
|
|
|
// type *foo;
|
|
|
|
// foo.bar
|
|
|
|
// This is actually well-formed in two cases:
|
|
|
|
// - 'type' is an Objective C type
|
|
|
|
// - 'bar' is a pseudo-destructor name which happens to refer to
|
|
|
|
// the appropriate pointer type
|
|
|
|
if (const PointerType *Ptr = BaseType->getAs<PointerType>()) {
|
|
|
|
if (!IsArrow && Ptr->getPointeeType()->isRecordType() &&
|
|
|
|
MemberName.getNameKind() != DeclarationName::CXXDestructorName) {
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
|
|
|
|
<< BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange()
|
2011-06-23 08:49:38 +08:00
|
|
|
<< FixItHint::CreateReplacement(OpLoc, "->");
|
|
|
|
|
|
|
|
// Recurse as an -> access.
|
|
|
|
IsArrow = true;
|
2014-05-31 08:18:32 +08:00
|
|
|
return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
|
2011-06-23 08:49:38 +08:00
|
|
|
ObjCImpDecl, HasTemplateArgs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the user is trying to apply -> or . to a function name, it's probably
|
|
|
|
// because they forgot parentheses to call that function.
|
2014-05-31 08:18:32 +08:00
|
|
|
if (S.tryToRecoverWithCall(
|
|
|
|
BaseExpr, S.PDiag(diag::err_member_reference_needs_call),
|
|
|
|
/*complain*/ false,
|
|
|
|
IsArrow ? &isPointerToRecordType : &isRecordType)) {
|
2011-10-12 07:14:30 +08:00
|
|
|
if (BaseExpr.isInvalid())
|
2011-06-23 08:49:38 +08:00
|
|
|
return ExprError();
|
2014-05-31 08:18:32 +08:00
|
|
|
BaseExpr = S.DefaultFunctionArrayConversion(BaseExpr.get());
|
|
|
|
return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
|
2011-10-12 07:14:30 +08:00
|
|
|
ObjCImpDecl, HasTemplateArgs);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 08:18:32 +08:00
|
|
|
S.Diag(OpLoc, diag::err_typecheck_member_reference_struct_union)
|
2012-04-21 10:13:04 +08:00
|
|
|
<< BaseType << BaseExpr.get()->getSourceRange() << MemberLoc;
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The main callback when the parser finds something like
|
|
|
|
/// expression . [nested-name-specifier] identifier
|
|
|
|
/// expression -> [nested-name-specifier] identifier
|
|
|
|
/// where 'identifier' encompasses a fairly broad spectrum of
|
|
|
|
/// possibilities, including destructor and operator references.
|
|
|
|
///
|
|
|
|
/// \param OpKind either tok::arrow or tok::period
|
2012-06-15 15:13:21 +08:00
|
|
|
/// \param ObjCImpDecl the current Objective-C \@implementation
|
|
|
|
/// decl; this is an ugly hack around the fact that Objective-C
|
|
|
|
/// \@implementations aren't properly put in the context chain
|
2011-06-23 08:49:38 +08:00
|
|
|
ExprResult Sema::ActOnMemberAccessExpr(Scope *S, Expr *Base,
|
|
|
|
SourceLocation OpLoc,
|
|
|
|
tok::TokenKind OpKind,
|
|
|
|
CXXScopeSpec &SS,
|
2012-01-27 17:46:47 +08:00
|
|
|
SourceLocation TemplateKWLoc,
|
2011-06-23 08:49:38 +08:00
|
|
|
UnqualifiedId &Id,
|
2015-02-26 01:36:15 +08:00
|
|
|
Decl *ObjCImpDecl) {
|
2011-06-23 08:49:38 +08:00
|
|
|
if (SS.isSet() && SS.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// Warn about the explicit constructor calls Microsoft extension.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().MicrosoftExt &&
|
2011-06-23 08:49:38 +08:00
|
|
|
Id.getKind() == UnqualifiedId::IK_ConstructorName)
|
|
|
|
Diag(Id.getSourceRange().getBegin(),
|
|
|
|
diag::ext_ms_explicit_constructor_call);
|
|
|
|
|
|
|
|
TemplateArgumentListInfo TemplateArgsBuffer;
|
|
|
|
|
|
|
|
// Decompose the name into its component parts.
|
|
|
|
DeclarationNameInfo NameInfo;
|
|
|
|
const TemplateArgumentListInfo *TemplateArgs;
|
|
|
|
DecomposeUnqualifiedId(Id, TemplateArgsBuffer,
|
|
|
|
NameInfo, TemplateArgs);
|
|
|
|
|
|
|
|
DeclarationName Name = NameInfo.getName();
|
|
|
|
bool IsArrow = (OpKind == tok::arrow);
|
|
|
|
|
|
|
|
NamedDecl *FirstQualifierInScope
|
2014-05-26 14:22:03 +08:00
|
|
|
= (!SS.isSet() ? nullptr : FindFirstQualifierInScope(S, SS.getScopeRep()));
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
// This is a postfix expression, so get rid of ParenListExprs.
|
|
|
|
ExprResult Result = MaybeConvertParenListExprToParenExpr(S, Base);
|
|
|
|
if (Result.isInvalid()) return ExprError();
|
2014-05-29 18:55:11 +08:00
|
|
|
Base = Result.get();
|
2011-06-23 08:49:38 +08:00
|
|
|
|
|
|
|
if (Base->getType()->isDependentType() || Name.isDependentName() ||
|
|
|
|
isDependentScopeSpecifier(SS)) {
|
2014-05-31 08:18:32 +08:00
|
|
|
return ActOnDependentMemberExpr(Base, Base->getType(), IsArrow, OpLoc, SS,
|
|
|
|
TemplateKWLoc, FirstQualifierInScope,
|
|
|
|
NameInfo, TemplateArgs);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
2015-02-26 01:36:15 +08:00
|
|
|
ActOnMemberAccessExtraArgs ExtraArgs = {S, Id, ObjCImpDecl};
|
2014-05-31 08:18:32 +08:00
|
|
|
return BuildMemberReferenceExpr(Base, Base->getType(), OpLoc, IsArrow, SS,
|
|
|
|
TemplateKWLoc, FirstQualifierInScope,
|
|
|
|
NameInfo, TemplateArgs, &ExtraArgs);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ExprResult
|
|
|
|
BuildFieldReferenceExpr(Sema &S, Expr *BaseExpr, bool IsArrow,
|
2015-03-24 23:07:53 +08:00
|
|
|
SourceLocation OpLoc, const CXXScopeSpec &SS,
|
|
|
|
FieldDecl *Field, DeclAccessPair FoundDecl,
|
2011-06-23 08:49:38 +08:00
|
|
|
const DeclarationNameInfo &MemberNameInfo) {
|
|
|
|
// x.a is an l-value if 'a' has a reference type. Otherwise:
|
|
|
|
// x.a is an l-value/x-value/pr-value if the base is (and note
|
|
|
|
// that *x is always an l-value), except that if the base isn't
|
|
|
|
// an ordinary object then we must have an rvalue.
|
|
|
|
ExprValueKind VK = VK_LValue;
|
|
|
|
ExprObjectKind OK = OK_Ordinary;
|
|
|
|
if (!IsArrow) {
|
|
|
|
if (BaseExpr->getObjectKind() == OK_Ordinary)
|
|
|
|
VK = BaseExpr->getValueKind();
|
|
|
|
else
|
|
|
|
VK = VK_RValue;
|
|
|
|
}
|
|
|
|
if (VK != VK_RValue && Field->isBitField())
|
|
|
|
OK = OK_BitField;
|
|
|
|
|
|
|
|
// Figure out the type of the member; see C99 6.5.2.3p3, C++ [expr.ref]
|
|
|
|
QualType MemberType = Field->getType();
|
|
|
|
if (const ReferenceType *Ref = MemberType->getAs<ReferenceType>()) {
|
|
|
|
MemberType = Ref->getPointeeType();
|
|
|
|
VK = VK_LValue;
|
|
|
|
} else {
|
|
|
|
QualType BaseType = BaseExpr->getType();
|
|
|
|
if (IsArrow) BaseType = BaseType->getAs<PointerType>()->getPointeeType();
|
2013-02-27 05:16:00 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
Qualifiers BaseQuals = BaseType.getQualifiers();
|
2013-02-27 05:16:00 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
// GC attributes are never picked up by members.
|
|
|
|
BaseQuals.removeObjCGCAttr();
|
2013-02-27 05:16:00 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
// CVR attributes from the base are picked up by members,
|
|
|
|
// except that 'mutable' members don't pick up 'const'.
|
|
|
|
if (Field->isMutable()) BaseQuals.removeConst();
|
2013-02-27 05:16:00 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
Qualifiers MemberQuals
|
|
|
|
= S.Context.getCanonicalType(MemberType).getQualifiers();
|
2013-02-27 05:16:00 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
assert(!MemberQuals.hasAddressSpace());
|
2013-02-27 05:16:00 +08:00
|
|
|
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
Qualifiers Combined = BaseQuals + MemberQuals;
|
|
|
|
if (Combined != MemberQuals)
|
|
|
|
MemberType = S.Context.getQualifiedType(MemberType, Combined);
|
|
|
|
}
|
2013-02-27 05:16:00 +08:00
|
|
|
|
2012-06-06 16:32:04 +08:00
|
|
|
S.UnusedPrivateFields.remove(Field);
|
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
ExprResult Base =
|
|
|
|
S.PerformObjectMemberConversion(BaseExpr, SS.getScopeRep(),
|
|
|
|
FoundDecl, Field);
|
|
|
|
if (Base.isInvalid())
|
|
|
|
return ExprError();
|
2015-03-24 23:07:53 +08:00
|
|
|
return BuildMemberExpr(S, S.Context, Base.get(), IsArrow, OpLoc, SS,
|
2014-05-29 22:05:12 +08:00
|
|
|
/*TemplateKWLoc=*/SourceLocation(), Field, FoundDecl,
|
|
|
|
MemberNameInfo, MemberType, VK, OK);
|
2011-06-23 08:49:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Builds an implicit member access expression. The current context
|
|
|
|
/// is known to be an instance method, and the given unqualified lookup
|
|
|
|
/// set is known to contain only instance members, at least one of which
|
|
|
|
/// is from an appropriate type.
|
|
|
|
ExprResult
|
|
|
|
Sema::BuildImplicitMemberExpr(const CXXScopeSpec &SS,
|
2012-01-27 17:46:47 +08:00
|
|
|
SourceLocation TemplateKWLoc,
|
2011-06-23 08:49:38 +08:00
|
|
|
LookupResult &R,
|
|
|
|
const TemplateArgumentListInfo *TemplateArgs,
|
|
|
|
bool IsKnownInstance) {
|
|
|
|
assert(!R.empty() && !R.isAmbiguous());
|
|
|
|
|
|
|
|
SourceLocation loc = R.getNameLoc();
|
2014-01-18 06:29:43 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
// If this is known to be an instance access, go ahead and build an
|
|
|
|
// implicit 'this' expression now.
|
|
|
|
// 'this' expression now.
|
2011-10-19 00:47:30 +08:00
|
|
|
QualType ThisTy = getCurrentThisType();
|
2011-06-23 08:49:38 +08:00
|
|
|
assert(!ThisTy.isNull() && "didn't correctly pre-flight capture of 'this'");
|
2014-05-26 14:22:03 +08:00
|
|
|
|
|
|
|
Expr *baseExpr = nullptr; // null signifies implicit access
|
2011-06-23 08:49:38 +08:00
|
|
|
if (IsKnownInstance) {
|
|
|
|
SourceLocation Loc = R.getNameLoc();
|
|
|
|
if (SS.getRange().isValid())
|
|
|
|
Loc = SS.getRange().getBegin();
|
2012-01-07 12:59:52 +08:00
|
|
|
CheckCXXThisCapture(Loc);
|
2011-06-23 08:49:38 +08:00
|
|
|
baseExpr = new (Context) CXXThisExpr(loc, ThisTy, /*isImplicit=*/true);
|
|
|
|
}
|
2014-05-26 14:22:03 +08:00
|
|
|
|
2011-06-23 08:49:38 +08:00
|
|
|
return BuildMemberReferenceExpr(baseExpr, ThisTy,
|
|
|
|
/*OpLoc*/ SourceLocation(),
|
|
|
|
/*IsArrow*/ true,
|
2012-01-27 17:46:47 +08:00
|
|
|
SS, TemplateKWLoc,
|
2014-05-26 14:22:03 +08:00
|
|
|
/*FirstQualifierInScope*/ nullptr,
|
2011-06-23 08:49:38 +08:00
|
|
|
R, TemplateArgs);
|
|
|
|
}
|