本文整理汇总了C++中NamedDecl::getLocation方法的典型用法代码示例。如果您正苦于以下问题:C++ NamedDecl::getLocation方法的具体用法?C++ NamedDecl::getLocation怎么用?C++ NamedDecl::getLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamedDecl
的用法示例。
在下文中一共展示了NamedDecl::getLocation方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: noteOverloads
/// \brief Give notes for a set of overloads.
///
/// A companion to isExprCallable. In cases when the name that the programmer
/// wrote was an overloaded function, we may be able to make some guesses about
/// plausible overloads based on their return types; such guesses can be handed
/// off to this method to be emitted as notes.
///
/// \param Overloads - The overloads to note.
/// \param FinalNoteLoc - If we've suppressed printing some overloads due to
/// -fshow-overloads=best, this is the location to attach to the note about too
/// many candidates. Typically this will be the location of the original
/// ill-formed expression.
static void noteOverloads(Sema &S, const UnresolvedSetImpl &Overloads,
const SourceLocation FinalNoteLoc) {
int ShownOverloads = 0;
int SuppressedOverloads = 0;
for (UnresolvedSetImpl::iterator It = Overloads.begin(),
DeclsEnd = Overloads.end(); It != DeclsEnd; ++It) {
// FIXME: Magic number for max shown overloads stolen from
// OverloadCandidateSet::NoteCandidates.
if (ShownOverloads >= 4 && S.Diags.getShowOverloads() == Ovl_Best) {
++SuppressedOverloads;
continue;
}
NamedDecl *Fn = (*It)->getUnderlyingDecl();
S.Diag(Fn->getLocation(), diag::note_possible_target_of_call);
++ShownOverloads;
}
if (SuppressedOverloads)
S.Diag(FinalNoteLoc, diag::note_ovl_too_many_candidates)
<< SuppressedOverloads;
}
示例2: BuildCXXNestedNameSpecifier
//.........这里部分代码省略.........
// We were not able to compute the declaration context for a dependent
// base object type or prior nested-name-specifier, so this
// nested-name-specifier refers to an unknown specialization. Just build
// a dependent nested-name-specifier.
SS.Extend(Context, &Identifier, IdentifierLoc, CCLoc);
return false;
}
// FIXME: Deal with ambiguities cleanly.
if (Found.empty() && !ErrorRecoveryLookup) {
// We haven't found anything, and we're not recovering from a
// different kind of error, so look for typos.
DeclarationName Name = Found.getLookupName();
TypoCorrection Corrected;
Found.clear();
if ((Corrected = CorrectTypo(Found.getLookupNameInfo(),
Found.getLookupKind(), S, &SS, LookupCtx,
EnteringContext, CTC_NoKeywords)) &&
isAcceptableNestedNameSpecifier(Corrected.getCorrectionDecl())) {
std::string CorrectedStr(Corrected.getAsString(getLangOptions()));
std::string CorrectedQuotedStr(Corrected.getQuoted(getLangOptions()));
if (LookupCtx)
Diag(Found.getNameLoc(), diag::err_no_member_suggest)
<< Name << LookupCtx << CorrectedQuotedStr << SS.getRange()
<< FixItHint::CreateReplacement(Found.getNameLoc(), CorrectedStr);
else
Diag(Found.getNameLoc(), diag::err_undeclared_var_use_suggest)
<< Name << CorrectedQuotedStr
<< FixItHint::CreateReplacement(Found.getNameLoc(), CorrectedStr);
if (NamedDecl *ND = Corrected.getCorrectionDecl()) {
Diag(ND->getLocation(), diag::note_previous_decl) << CorrectedQuotedStr;
Found.addDecl(ND);
}
Found.setLookupName(Corrected.getCorrection());
} else {
Found.setLookupName(&Identifier);
}
}
NamedDecl *SD = Found.getAsSingle<NamedDecl>();
if (isAcceptableNestedNameSpecifier(SD)) {
if (!ObjectType.isNull() && !ObjectTypeSearchedInScope) {
// C++ [basic.lookup.classref]p4:
// [...] If the name is found in both contexts, the
// class-name-or-namespace-name shall refer to the same entity.
//
// We already found the name in the scope of the object. Now, look
// into the current scope (the scope of the postfix-expression) to
// see if we can find the same name there. As above, if there is no
// scope, reconstruct the result from the template instantiation itself.
NamedDecl *OuterDecl;
if (S) {
LookupResult FoundOuter(*this, &Identifier, IdentifierLoc,
LookupNestedNameSpecifierName);
LookupName(FoundOuter, S);
OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
} else
OuterDecl = ScopeLookupResult;
if (isAcceptableNestedNameSpecifier(OuterDecl) &&
OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
(!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
!Context.hasSameType(
示例3: BuildCXXNestedNameSpecifier
//.........这里部分代码省略.........
(!cast<CXXRecordDecl>(LookupCtx)->hasDefinition() ||
!cast<CXXRecordDecl>(LookupCtx)->hasAnyDependentBases()))) {
// Don't speculate if we're just trying to improve error recovery.
if (ErrorRecoveryLookup)
return true;
// We were not able to compute the declaration context for a dependent
// base object type or prior nested-name-specifier, so this
// nested-name-specifier refers to an unknown specialization. Just build
// a dependent nested-name-specifier.
SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc, IdInfo.CCLoc);
return false;
}
if (Found.empty() && !ErrorRecoveryLookup) {
// If identifier is not found as class-name-or-namespace-name, but is found
// as other entity, don't look for typos.
LookupResult R(*this, Found.getLookupNameInfo(), LookupOrdinaryName);
if (LookupCtx)
LookupQualifiedName(R, LookupCtx);
else if (S && !isDependent)
LookupName(R, S);
if (!R.empty()) {
// Don't diagnose problems with this speculative lookup.
R.suppressDiagnostics();
// The identifier is found in ordinary lookup. If correction to colon is
// allowed, suggest replacement to ':'.
if (IsCorrectedToColon) {
*IsCorrectedToColon = true;
Diag(IdInfo.CCLoc, diag::err_nested_name_spec_is_not_class)
<< IdInfo.Identifier << getLangOpts().CPlusPlus
<< FixItHint::CreateReplacement(IdInfo.CCLoc, ":");
if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
Diag(ND->getLocation(), diag::note_declared_at);
return true;
}
// Replacement '::' -> ':' is not allowed, just issue respective error.
Diag(R.getNameLoc(), OnlyNamespace
? unsigned(diag::err_expected_namespace_name)
: unsigned(diag::err_expected_class_or_namespace))
<< IdInfo.Identifier << getLangOpts().CPlusPlus;
if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
Diag(ND->getLocation(), diag::note_entity_declared_at)
<< IdInfo.Identifier;
return true;
}
}
if (Found.empty() && !ErrorRecoveryLookup && !getLangOpts().MSVCCompat) {
// We haven't found anything, and we're not recovering from a
// different kind of error, so look for typos.
DeclarationName Name = Found.getLookupName();
Found.clear();
NestedNameSpecifierValidatorCCC CCC(*this);
if (TypoCorrection Corrected = CorrectTypo(
Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS, CCC,
CTK_ErrorRecovery, LookupCtx, EnteringContext)) {
if (LookupCtx) {
bool DroppedSpecifier =
Corrected.WillReplaceSpecifier() &&
Name.getAsString() == Corrected.getAsString(getLangOpts());
if (DroppedSpecifier)
SS.clear();
diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
<< Name << LookupCtx << DroppedSpecifier
<< SS.getRange());
示例4: CheckTagDeclaration
bool DeclExtractor::CheckTagDeclaration(TagDecl* NewTD,
LookupResult& Previous){
// If the decl is already known invalid, don't check it.
if (NewTD->isInvalidDecl())
return false;
IdentifierInfo* Name = NewTD->getIdentifier();
// If this is not a definition, it must have a name.
assert((Name != 0 || NewTD->isThisDeclarationADefinition()) &&
"Nameless record must be a definition!");
// Figure out the underlying type if this a enum declaration. We need to do
// this early, because it's needed to detect if this is an incompatible
// redeclaration.
TagDecl::TagKind Kind = NewTD->getTagKind();
bool Invalid = false;
assert(NewTD->getNumTemplateParameterLists() == 0
&& "Cannot handle that yet!");
bool isExplicitSpecialization = false;
if (Kind == TTK_Enum) {
EnumDecl* ED = cast<EnumDecl>(NewTD);
bool ScopedEnum = ED->isScoped();
const QualType QT = ED->getIntegerType();
if (QT.isNull() && ScopedEnum)
// No underlying type explicitly specified, or we failed to parse the
// type, default to int.
; //EnumUnderlying = m_Context->IntTy.getTypePtr();
else if (!QT.isNull()) {
// C++0x 7.2p2: The type-specifier-seq of an enum-base shall name an
// integral type; any cv-qualification is ignored.
SourceLocation UnderlyingLoc;
TypeSourceInfo* TI = 0;
if ((TI = ED->getIntegerTypeSourceInfo()))
UnderlyingLoc = TI->getTypeLoc().getBeginLoc();
if (!QT->isDependentType() && !QT->isIntegralType(*m_Context)) {
m_Sema->Diag(UnderlyingLoc, diag::err_enum_invalid_underlying)
<< QT;
}
if (TI)
m_Sema->DiagnoseUnexpandedParameterPack(UnderlyingLoc, TI,
Sema::UPPC_FixedUnderlyingType);
}
}
DeclContext *SearchDC = m_Sema->CurContext;
DeclContext *DC = m_Sema->CurContext;
//bool isStdBadAlloc = false;
SourceLocation NameLoc = NewTD->getLocation();
// if (Name && SS.isNotEmpty()) {
// // We have a nested-name tag ('struct foo::bar').
// // Check for invalid 'foo::'.
// if (SS.isInvalid()) {
// Name = 0;
// goto CreateNewDecl;
// }
// // If this is a friend or a reference to a class in a dependent
// // context, don't try to make a decl for it.
// if (TUK == TUK_Friend || TUK == TUK_Reference) {
// DC = computeDeclContext(SS, false);
// if (!DC) {
// IsDependent = true;
// return 0;
// }
// } else {
// DC = computeDeclContext(SS, true);
// if (!DC) {
// Diag(SS.getRange().getBegin(),
// diag::err_dependent_nested_name_spec)
// << SS.getRange();
// return 0;
// }
// }
// if (RequireCompleteDeclContext(SS, DC))
// return 0;
// SearchDC = DC;
// // Look-up name inside 'foo::'.
// LookupQualifiedName(Previous, DC);
// if (Previous.isAmbiguous())
// return 0;
// if (Previous.empty()) {
// // Name lookup did not find anything. However, if the
// // nested-name-specifier refers to the current instantiation,
// // and that current instantiation has any dependent base
// // classes, we might find something at instantiation time: treat
// // this as a dependent elaborated-type-specifier.
// // But this only makes any sense for reference-like lookups.
// if (Previous.wasNotFoundInCurrentInstantiation() &&
// (TUK == TUK_Reference || TUK == TUK_Friend)) {
// IsDependent = true;
//.........这里部分代码省略.........
示例5: lookupPromiseType
/// Look up the std::coroutine_traits<...>::promise_type for the given
/// function type.
static QualType lookupPromiseType(Sema &S, const FunctionProtoType *FnType,
SourceLocation KwLoc,
SourceLocation FuncLoc) {
// FIXME: Cache std::coroutine_traits once we've found it.
NamespaceDecl *StdExp = S.lookupStdExperimentalNamespace();
if (!StdExp) {
S.Diag(KwLoc, diag::err_implied_coroutine_type_not_found)
<< "std::experimental::coroutine_traits";
return QualType();
}
LookupResult Result(S, &S.PP.getIdentifierTable().get("coroutine_traits"),
FuncLoc, Sema::LookupOrdinaryName);
if (!S.LookupQualifiedName(Result, StdExp)) {
S.Diag(KwLoc, diag::err_implied_coroutine_type_not_found)
<< "std::experimental::coroutine_traits";
return QualType();
}
ClassTemplateDecl *CoroTraits = Result.getAsSingle<ClassTemplateDecl>();
if (!CoroTraits) {
Result.suppressDiagnostics();
// We found something weird. Complain about the first thing we found.
NamedDecl *Found = *Result.begin();
S.Diag(Found->getLocation(), diag::err_malformed_std_coroutine_traits);
return QualType();
}
// Form template argument list for coroutine_traits<R, P1, P2, ...>.
TemplateArgumentListInfo Args(KwLoc, KwLoc);
Args.addArgument(TemplateArgumentLoc(
TemplateArgument(FnType->getReturnType()),
S.Context.getTrivialTypeSourceInfo(FnType->getReturnType(), KwLoc)));
// FIXME: If the function is a non-static member function, add the type
// of the implicit object parameter before the formal parameters.
for (QualType T : FnType->getParamTypes())
Args.addArgument(TemplateArgumentLoc(
TemplateArgument(T), S.Context.getTrivialTypeSourceInfo(T, KwLoc)));
// Build the template-id.
QualType CoroTrait =
S.CheckTemplateIdType(TemplateName(CoroTraits), KwLoc, Args);
if (CoroTrait.isNull())
return QualType();
if (S.RequireCompleteType(KwLoc, CoroTrait,
diag::err_coroutine_type_missing_specialization))
return QualType();
auto *RD = CoroTrait->getAsCXXRecordDecl();
assert(RD && "specialization of class template is not a class?");
// Look up the ::promise_type member.
LookupResult R(S, &S.PP.getIdentifierTable().get("promise_type"), KwLoc,
Sema::LookupOrdinaryName);
S.LookupQualifiedName(R, RD);
auto *Promise = R.getAsSingle<TypeDecl>();
if (!Promise) {
S.Diag(FuncLoc,
diag::err_implied_std_coroutine_traits_promise_type_not_found)
<< RD;
return QualType();
}
// The promise type is required to be a class type.
QualType PromiseType = S.Context.getTypeDeclType(Promise);
auto buildElaboratedType = [&]() {
auto *NNS = NestedNameSpecifier::Create(S.Context, nullptr, StdExp);
NNS = NestedNameSpecifier::Create(S.Context, NNS, false,
CoroTrait.getTypePtr());
return S.Context.getElaboratedType(ETK_None, NNS, PromiseType);
};
if (!PromiseType->getAsCXXRecordDecl()) {
S.Diag(FuncLoc,
diag::err_implied_std_coroutine_traits_promise_type_not_class)
<< buildElaboratedType();
return QualType();
}
if (S.RequireCompleteType(FuncLoc, buildElaboratedType(),
diag::err_coroutine_promise_type_incomplete))
return QualType();
return PromiseType;
}
示例6: getObjCMessageKind
Sema::ObjCMessageKind Sema::getObjCMessageKind(Scope *S,
IdentifierInfo *Name,
SourceLocation NameLoc,
bool IsSuper,
bool HasTrailingDot,
ParsedType &ReceiverType) {
ReceiverType = ParsedType();
// If the identifier is "super" and there is no trailing dot, we're
// messaging super. If the identifier is "super" and there is a
// trailing dot, it's an instance message.
if (IsSuper && S->isInObjcMethodScope())
return HasTrailingDot? ObjCInstanceMessage : ObjCSuperMessage;
LookupResult Result(*this, Name, NameLoc, LookupOrdinaryName);
LookupName(Result, S);
switch (Result.getResultKind()) {
case LookupResult::NotFound:
// Normal name lookup didn't find anything. If we're in an
// Objective-C method, look for ivars. If we find one, we're done!
// FIXME: This is a hack. Ivar lookup should be part of normal
// lookup.
if (ObjCMethodDecl *Method = getCurMethodDecl()) {
ObjCInterfaceDecl *ClassDeclared;
if (Method->getClassInterface()->lookupInstanceVariable(Name,
ClassDeclared))
return ObjCInstanceMessage;
}
// Break out; we'll perform typo correction below.
break;
case LookupResult::NotFoundInCurrentInstantiation:
case LookupResult::FoundOverloaded:
case LookupResult::FoundUnresolvedValue:
case LookupResult::Ambiguous:
Result.suppressDiagnostics();
return ObjCInstanceMessage;
case LookupResult::Found: {
// If the identifier is a class or not, and there is a trailing dot,
// it's an instance message.
if (HasTrailingDot)
return ObjCInstanceMessage;
// We found something. If it's a type, then we have a class
// message. Otherwise, it's an instance message.
NamedDecl *ND = Result.getFoundDecl();
QualType T;
if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(ND))
T = Context.getObjCInterfaceType(Class);
else if (TypeDecl *Type = dyn_cast<TypeDecl>(ND))
T = Context.getTypeDeclType(Type);
else
return ObjCInstanceMessage;
// We have a class message, and T is the type we're
// messaging. Build source-location information for it.
TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
ReceiverType = CreateParsedType(T, TSInfo);
return ObjCClassMessage;
}
}
// Determine our typo-correction context.
CorrectTypoContext CTC = CTC_Expression;
if (ObjCMethodDecl *Method = getCurMethodDecl())
if (Method->getClassInterface() &&
Method->getClassInterface()->getSuperClass())
CTC = CTC_ObjCMessageReceiver;
if (DeclarationName Corrected = CorrectTypo(Result, S, 0, 0, false, CTC)) {
if (Result.isSingleResult()) {
// If we found a declaration, correct when it refers to an Objective-C
// class.
NamedDecl *ND = Result.getFoundDecl();
if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(ND)) {
Diag(NameLoc, diag::err_unknown_receiver_suggest)
<< Name << Result.getLookupName()
<< FixItHint::CreateReplacement(SourceRange(NameLoc),
ND->getNameAsString());
Diag(ND->getLocation(), diag::note_previous_decl)
<< Corrected;
QualType T = Context.getObjCInterfaceType(Class);
TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
ReceiverType = CreateParsedType(T, TSInfo);
return ObjCClassMessage;
}
} else if (Result.empty() && Corrected.getAsIdentifierInfo() &&
Corrected.getAsIdentifierInfo()->isStr("super")) {
// If we've found the keyword "super", this is a send to super.
Diag(NameLoc, diag::err_unknown_receiver_suggest)
<< Name << Corrected
<< FixItHint::CreateReplacement(SourceRange(NameLoc), "super");
return ObjCSuperMessage;
}
}
// Fall back: let the parser try to parse it as an instance message.
//.........这里部分代码省略.........
示例7: DiagnoseAccessPath
/// Diagnose the path which caused the given declaration or base class
/// to become inaccessible.
static void DiagnoseAccessPath(Sema &S,
const EffectiveContext &EC,
AccessTarget &Entity) {
AccessSpecifier Access = Entity.getAccess();
const CXXRecordDecl *NamingClass = Entity.getNamingClass();
NamingClass = NamingClass->getCanonicalDecl();
NamedDecl *D = (Entity.isMemberAccess() ? Entity.getTargetDecl() : 0);
const CXXRecordDecl *DeclaringClass = Entity.getDeclaringClass();
// Easy case: the decl's natural access determined its path access.
// We have to check against AS_private here in case Access is AS_none,
// indicating a non-public member of a private base class.
if (D && (Access == D->getAccess() || D->getAccess() == AS_private)) {
switch (HasAccess(S, EC, DeclaringClass, D->getAccess(), Entity)) {
case AR_inaccessible: {
S.Diag(D->getLocation(), diag::note_access_natural)
<< (unsigned) (Access == AS_protected)
<< /*FIXME: not implicitly*/ 0;
return;
}
case AR_accessible: break;
case AR_dependent:
llvm_unreachable("can't diagnose dependent access failures");
return;
}
}
CXXBasePaths Paths;
CXXBasePath &Path = *FindBestPath(S, EC, Entity, AS_public, Paths);
CXXBasePath::iterator I = Path.end(), E = Path.begin();
while (I != E) {
--I;
const CXXBaseSpecifier *BS = I->Base;
AccessSpecifier BaseAccess = BS->getAccessSpecifier();
// If this is public inheritance, or the derived class is a friend,
// skip this step.
if (BaseAccess == AS_public)
continue;
switch (GetFriendKind(S, EC, I->Class)) {
case AR_accessible: continue;
case AR_inaccessible: break;
case AR_dependent:
llvm_unreachable("can't diagnose dependent access failures");
}
// Check whether this base specifier is the tighest point
// constraining access. We have to check against AS_private for
// the same reasons as above.
if (BaseAccess == AS_private || BaseAccess >= Access) {
// We're constrained by inheritance, but we want to say
// "declared private here" if we're diagnosing a hierarchy
// conversion and this is the final step.
unsigned diagnostic;
if (D) diagnostic = diag::note_access_constrained_by_path;
else if (I + 1 == Path.end()) diagnostic = diag::note_access_natural;
else diagnostic = diag::note_access_constrained_by_path;
S.Diag(BS->getSourceRange().getBegin(), diagnostic)
<< BS->getSourceRange()
<< (BaseAccess == AS_protected)
<< (BS->getAccessSpecifierAsWritten() == AS_none);
return;
}
}
llvm_unreachable("access not apparently constrained by path");
}
示例8: assert
NamespaceDecl *Sema::ActOnRogerNamespaceHeaderPart(DeclContext *DeclContext, IdentifierInfo *II,
SourceLocation IdentLoc,
AttributeList *AttrList) {
// set CurContext
SourceLocation NamespaceLoc;
SourceLocation InlineLoc;
SourceLocation StartLoc = InlineLoc.isValid() ? InlineLoc : NamespaceLoc;
assert(II);
SourceLocation Loc = IdentLoc;
bool IsInline = false;
bool IsInvalid = false;
bool IsStd = false;
bool AddToKnown = false;
//Scope *DeclRegionScope = NamespcScope->getParent();
NamespaceDecl *PrevNS = 0;
// C++ [namespace.def]p2:
// The identifier in an original-namespace-definition shall not
// have been previously defined in the declarative region in
// which the original-namespace-definition appears. The
// identifier in an original-namespace-definition is the name of
// the namespace. Subsequently in that declarative region, it is
// treated as an original-namespace-name.
//
// Since namespace names are unique in their scope, and we don't
// look through using directives, just look for any ordinary names.
const unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Member |
Decl::IDNS_Type | Decl::IDNS_Using | Decl::IDNS_Tag |
Decl::IDNS_Namespace;
NamedDecl *PrevDecl = 0;
DeclContext::lookup_result R = DeclContext->getRedeclContext()->lookup(II);
for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E;
++I) {
if ((*I)->getIdentifierNamespace() & IDNS) {
PrevDecl = *I;
break;
}
}
PrevNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl);
if (PrevNS) {
// This is an extended namespace definition.
if (IsInline != PrevNS->isInline()) {
// DiagnoseNamespaceInlineMismatch(*this, NamespaceLoc, Loc, II,
// &IsInline, PrevNS);
assert(false && "need to implement this");
}
return PrevNS;
} else if (PrevDecl) {
// This is an invalid name redefinition.
Diag(Loc, diag::err_redefinition_different_kind)
<< II;
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
IsInvalid = true;
// Continue on to push Namespc as current DeclContext and return it.
} else if (II->isStr("std") &&
DeclContext->getRedeclContext()->isTranslationUnit()) {
// This is the first "real" definition of the namespace "std", so update
// our cache of the "std" namespace to point at this definition.
PrevNS = getStdNamespace();
IsStd = true;
AddToKnown = !IsInline;
} else {
// We've seen this namespace for the first time.
AddToKnown = !IsInline;
}
NamespaceDecl *Namespc = NamespaceDecl::Create(Context, DeclContext, IsInline,
StartLoc, Loc, II, PrevNS);
Namespc->IsRogerNamespace = true;
if (IsInvalid)
Namespc->setInvalidDecl();
//ProcessDeclAttributeList(DeclRegionScope, Namespc, AttrList);
// FIXME: Should we be merging attributes?
if (const VisibilityAttr *Attr = Namespc->getAttr<VisibilityAttr>())
PushNamespaceVisibilityAttr(Attr, Loc);
if (IsStd)
StdNamespace = Namespc;
if (AddToKnown)
KnownNamespaces[Namespc] = false;
DeclContext->addDecl(Namespc);
if (PrevNS) {
return PrevNS;
} else {
return Namespc;
}
}
示例9: Found
//.........这里部分代码省略.........
// base object type or prior nested-name-specifier, so this
// nested-name-specifier refers to an unknown specialization. Just build
// a dependent nested-name-specifier.
if (!Prefix)
return NestedNameSpecifier::Create(Context, &II);
return NestedNameSpecifier::Create(Context, Prefix, &II);
} else {
// Perform unqualified name lookup in the current scope.
LookupName(Found, S);
}
// FIXME: Deal with ambiguities cleanly.
if (Found.empty() && !ErrorRecoveryLookup) {
// We haven't found anything, and we're not recovering from a
// different kind of error, so look for typos.
DeclarationName Name = Found.getLookupName();
if (CorrectTypo(Found, S, &SS, LookupCtx, EnteringContext) &&
Found.isSingleResult() &&
isAcceptableNestedNameSpecifier(Found.getAsSingle<NamedDecl>())) {
if (LookupCtx)
Diag(Found.getNameLoc(), diag::err_no_member_suggest)
<< Name << LookupCtx << Found.getLookupName() << SS.getRange()
<< CodeModificationHint::CreateReplacement(Found.getNameLoc(),
Found.getLookupName().getAsString());
else
Diag(Found.getNameLoc(), diag::err_undeclared_var_use_suggest)
<< Name << Found.getLookupName()
<< CodeModificationHint::CreateReplacement(Found.getNameLoc(),
Found.getLookupName().getAsString());
if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
Diag(ND->getLocation(), diag::note_previous_decl)
<< ND->getDeclName();
} else
Found.clear();
}
NamedDecl *SD = Found.getAsSingle<NamedDecl>();
if (isAcceptableNestedNameSpecifier(SD)) {
if (!ObjectType.isNull() && !ObjectTypeSearchedInScope) {
// C++ [basic.lookup.classref]p4:
// [...] If the name is found in both contexts, the
// class-name-or-namespace-name shall refer to the same entity.
//
// We already found the name in the scope of the object. Now, look
// into the current scope (the scope of the postfix-expression) to
// see if we can find the same name there. As above, if there is no
// scope, reconstruct the result from the template instantiation itself.
NamedDecl *OuterDecl;
if (S) {
LookupResult FoundOuter(*this, &II, IdLoc, LookupNestedNameSpecifierName);
LookupName(FoundOuter, S);
OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
} else
OuterDecl = ScopeLookupResult;
if (isAcceptableNestedNameSpecifier(OuterDecl) &&
OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
(!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
!Context.hasSameType(
Context.getTypeDeclType(cast<TypeDecl>(OuterDecl)),
Context.getTypeDeclType(cast<TypeDecl>(SD))))) {
if (ErrorRecoveryLookup)
return 0;
示例10: ExprError
//.........这里部分代码省略.........
if (R.empty()) {
// FIXME: make sure this prints the '*' for pointer-to-struct types (?)
//DeclContext *DC = BaseType->getAs<StructType>()->getDecl();
// FIXME: clang prints DC instead of BaseExprType here. Don't do that,
// else we don't print struct names right. However, make sure ParenTypes
// get desugared once they exist.
Diag(R.getNameLoc(), diag::no_field) << II << BaseExprType;
//Diag(R.getNameLoc(), diag::err_no_member)
//<< MemberName << DC
//<< (BaseExpr ? BaseExpr->getSourceRange() : SourceRange());
return ExprError();
}
assert(R.isSingleResult());
NamedDecl *MemberDecl = R.getFoundDecl();
#if 0
DeclAccessPair FoundDecl = R.begin().getPair();
// 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();
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())
ShouldCheckUse = false;
}
// Check the use of this member.
if (ShouldCheckUse && DiagnoseUseOfDecl(MemberDecl, MemberLoc)) {
Owned(BaseExpr);
return ExprError();
}
#endif
if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
//return BuildFieldReferenceExpr(*this, BaseExpr, IsArrow,
//FD, FoundDecl, MemberNameInfo);
return Owned(BuildMemberExpr(*this, Context, BaseExpr, FD,
R.getNameLoc(), FD->getType()));
}
#if 0
if (IndirectFieldDecl *FD = dyn_cast<IndirectFieldDecl>(MemberDecl))
// We may have found a field within an anonymous union or struct
// (C++ [class.union]).
return BuildAnonymousStructUnionMemberReference(MemberLoc, FD,
BaseExpr, OpLoc);
if (VarDecl *Var = dyn_cast<VarDecl>(MemberDecl)) {
return Owned(BuildMemberExpr(*this, Context, BaseExpr, IsArrow,
Var, FoundDecl, MemberNameInfo,
Var->getType().getNonReferenceType(),
VK_LValue, OK_Ordinary));
}
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();
}
return Owned(BuildMemberExpr(*this, Context, BaseExpr, IsArrow,
MemberFn, FoundDecl,
MemberNameInfo, type, valueKind,
OK_Ordinary));
}
assert(!isa<FunctionDecl>(MemberDecl) && "member function not C++ method?");
if (EnumConstantDecl *Enum = dyn_cast<EnumConstantDecl>(MemberDecl)) {
return Owned(BuildMemberExpr(*this, Context, BaseExpr, IsArrow,
Enum, FoundDecl, MemberNameInfo,
Enum->getType(), VK_RValue, OK_Ordinary));
}
Owned(BaseExpr);
// 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();
#endif
return ExprError();
}