зеркало из https://github.com/microsoft/clang-1.git
Fixed NamespaceDecl source range.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127242 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
17c964ad98
Коммит
acba90f308
|
@ -346,7 +346,11 @@ public:
|
|||
class NamespaceDecl : public NamedDecl, public DeclContext {
|
||||
bool IsInline : 1;
|
||||
|
||||
SourceLocation LBracLoc, RBracLoc;
|
||||
/// LocStart - The starting location of the source range, pointing
|
||||
/// to either the namespace or the inline keyword.
|
||||
SourceLocation LocStart;
|
||||
/// RBraceLoc - The ending location of the source range.
|
||||
SourceLocation RBraceLoc;
|
||||
|
||||
// For extended namespace definitions:
|
||||
//
|
||||
|
@ -373,13 +377,16 @@ class NamespaceDecl : public NamedDecl, public DeclContext {
|
|||
/// namespace declaration (which the boolean indicates).
|
||||
llvm::PointerIntPair<NamespaceDecl *, 1, bool> OrigOrAnonNamespace;
|
||||
|
||||
NamespaceDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
|
||||
: NamedDecl(Namespace, DC, L, Id), DeclContext(Namespace),
|
||||
IsInline(false), NextNamespace(), OrigOrAnonNamespace(0, true) { }
|
||||
NamespaceDecl(DeclContext *DC, SourceLocation StartLoc,
|
||||
SourceLocation IdLoc, IdentifierInfo *Id)
|
||||
: NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace),
|
||||
IsInline(false), LocStart(StartLoc), RBraceLoc(),
|
||||
NextNamespace(), OrigOrAnonNamespace(0, true) { }
|
||||
|
||||
public:
|
||||
static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
|
||||
SourceLocation L, IdentifierInfo *Id);
|
||||
SourceLocation StartLoc,
|
||||
SourceLocation IdLoc, IdentifierInfo *Id);
|
||||
|
||||
/// \brief Returns true if this is an anonymous namespace declaration.
|
||||
///
|
||||
|
@ -453,14 +460,14 @@ public:
|
|||
}
|
||||
|
||||
virtual SourceRange getSourceRange() const {
|
||||
return SourceRange(getLocation(), RBracLoc);
|
||||
return SourceRange(LocStart, RBraceLoc);
|
||||
}
|
||||
|
||||
SourceLocation getLBracLoc() const { return LBracLoc; }
|
||||
SourceLocation getRBracLoc() const { return RBracLoc; }
|
||||
void setLBracLoc(SourceLocation L) { LBracLoc = L; }
|
||||
void setRBracLoc(SourceLocation R) { RBracLoc = R; }
|
||||
|
||||
SourceLocation getLocStart() const { return LocStart; }
|
||||
SourceLocation getRBraceLoc() const { return RBraceLoc; }
|
||||
void setLocStart(SourceLocation L) { LocStart = L; }
|
||||
void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
|
||||
|
||||
// Implement isa/cast/dyncast/etc.
|
||||
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
|
||||
static bool classof(const NamespaceDecl *D) { return true; }
|
||||
|
|
|
@ -2197,6 +2197,7 @@ public:
|
|||
|
||||
// Act on C++ namespaces
|
||||
Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
|
||||
SourceLocation NamespaceLoc,
|
||||
SourceLocation IdentLoc,
|
||||
IdentifierInfo *Ident,
|
||||
SourceLocation LBrace,
|
||||
|
|
|
@ -1967,8 +1967,9 @@ Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) {
|
|||
// Create the "to" namespace, if needed.
|
||||
NamespaceDecl *ToNamespace = MergeWithNamespace;
|
||||
if (!ToNamespace) {
|
||||
ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC, Loc,
|
||||
Name.getAsIdentifierInfo());
|
||||
ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC,
|
||||
Importer.Import(D->getLocStart()),
|
||||
Loc, Name.getAsIdentifierInfo());
|
||||
ToNamespace->setLexicalDeclContext(LexicalDC);
|
||||
LexicalDC->addDecl(ToNamespace);
|
||||
|
||||
|
|
|
@ -2222,8 +2222,9 @@ LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC,
|
|||
|
||||
|
||||
NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
|
||||
SourceLocation L, IdentifierInfo *Id) {
|
||||
return new (C) NamespaceDecl(DC, L, Id);
|
||||
SourceLocation StartLoc,
|
||||
SourceLocation IdLoc, IdentifierInfo *Id) {
|
||||
return new (C) NamespaceDecl(DC, StartLoc, IdLoc, Id);
|
||||
}
|
||||
|
||||
NamespaceDecl *NamespaceDecl::getNextNamespace() {
|
||||
|
|
|
@ -111,8 +111,8 @@ Decl *Parser::ParseNamespace(unsigned Context,
|
|||
ParseScope NamespaceScope(this, Scope::DeclScope);
|
||||
|
||||
Decl *NamespcDecl =
|
||||
Actions.ActOnStartNamespaceDef(getCurScope(), InlineLoc, IdentLoc, Ident,
|
||||
LBrace, attrs.getList());
|
||||
Actions.ActOnStartNamespaceDef(getCurScope(), InlineLoc, NamespaceLoc,
|
||||
IdentLoc, Ident, LBrace, attrs.getList());
|
||||
|
||||
PrettyDeclStackTraceEntry CrashInfo(Actions, NamespcDecl, NamespaceLoc,
|
||||
"parsing namespace");
|
||||
|
|
|
@ -3543,14 +3543,16 @@ Decl *Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
|
|||
/// definition.
|
||||
Decl *Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
|
||||
SourceLocation InlineLoc,
|
||||
SourceLocation NamespaceLoc,
|
||||
SourceLocation IdentLoc,
|
||||
IdentifierInfo *II,
|
||||
SourceLocation LBrace,
|
||||
AttributeList *AttrList) {
|
||||
// anonymous namespace starts at its left brace
|
||||
SourceLocation StartLoc = InlineLoc.isValid() ? InlineLoc : NamespaceLoc;
|
||||
// For anonymous namespace, take the location of the left brace.
|
||||
SourceLocation Loc = II ? IdentLoc : LBrace;
|
||||
NamespaceDecl *Namespc = NamespaceDecl::Create(Context, CurContext,
|
||||
(II ? IdentLoc : LBrace) , II);
|
||||
Namespc->setLBracLoc(LBrace);
|
||||
StartLoc, Loc, II);
|
||||
Namespc->setInline(InlineLoc.isValid());
|
||||
|
||||
Scope *DeclRegionScope = NamespcScope->getParent();
|
||||
|
@ -3709,7 +3711,7 @@ static inline NamespaceDecl *getNamespaceDecl(NamedDecl *D) {
|
|||
void Sema::ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace) {
|
||||
NamespaceDecl *Namespc = dyn_cast_or_null<NamespaceDecl>(Dcl);
|
||||
assert(Namespc && "Invalid parameter, expected NamespaceDecl");
|
||||
Namespc->setRBracLoc(RBrace);
|
||||
Namespc->setRBraceLoc(RBrace);
|
||||
PopDeclContext();
|
||||
if (Namespc->hasAttr<VisibilityAttr>())
|
||||
PopPragmaVisibility();
|
||||
|
@ -3732,7 +3734,7 @@ NamespaceDecl *Sema::getOrCreateStdNamespace() {
|
|||
// The "std" namespace has not yet been defined, so build one implicitly.
|
||||
StdNamespace = NamespaceDecl::Create(Context,
|
||||
Context.getTranslationUnitDecl(),
|
||||
SourceLocation(),
|
||||
SourceLocation(), SourceLocation(),
|
||||
&PP.getIdentifierTable().get("std"));
|
||||
getStdNamespace()->setImplicit(true);
|
||||
}
|
||||
|
|
|
@ -756,8 +756,8 @@ void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
|
|||
void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
|
||||
VisitNamedDecl(D);
|
||||
D->IsInline = Record[Idx++];
|
||||
D->LBracLoc = ReadSourceLocation(Record, Idx);
|
||||
D->RBracLoc = ReadSourceLocation(Record, Idx);
|
||||
D->LocStart = ReadSourceLocation(Record, Idx);
|
||||
D->RBraceLoc = ReadSourceLocation(Record, Idx);
|
||||
D->NextNamespace = Record[Idx++];
|
||||
|
||||
bool IsOriginal = Record[Idx++];
|
||||
|
@ -1448,7 +1448,8 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
|
|||
D = LabelDecl::Create(*Context, 0, SourceLocation(), 0);
|
||||
break;
|
||||
case DECL_NAMESPACE:
|
||||
D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
|
||||
D = NamespaceDecl::Create(*Context, 0, SourceLocation(),
|
||||
SourceLocation(), 0);
|
||||
break;
|
||||
case DECL_NAMESPACE_ALIAS:
|
||||
D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
|
||||
|
|
|
@ -662,8 +662,8 @@ void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
|
|||
void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
|
||||
VisitNamedDecl(D);
|
||||
Record.push_back(D->isInline());
|
||||
Writer.AddSourceLocation(D->getLBracLoc(), Record);
|
||||
Writer.AddSourceLocation(D->getRBracLoc(), Record);
|
||||
Writer.AddSourceLocation(D->getLocStart(), Record);
|
||||
Writer.AddSourceLocation(D->getRBraceLoc(), Record);
|
||||
Writer.AddDeclRef(D->getNextNamespace(), Record);
|
||||
|
||||
// Only write one reference--original or anonymous
|
||||
|
|
|
@ -27,10 +27,10 @@ void std::g() {
|
|||
namespace my_rel_ops = std::rel_ops;
|
||||
|
||||
// RUN: c-index-test -test-load-source all %s | FileCheck %s
|
||||
// CHECK: load-namespaces.cpp:3:11: Namespace=std:3:11 (Definition) Extent=[3:11 - 7:2]
|
||||
// CHECK: load-namespaces.cpp:4:13: Namespace=rel_ops:4:13 (Definition) Extent=[4:13 - 6:4]
|
||||
// CHECK: load-namespaces.cpp:3:11: Namespace=std:3:11 (Definition) Extent=[3:1 - 7:2]
|
||||
// CHECK: load-namespaces.cpp:4:13: Namespace=rel_ops:4:13 (Definition) Extent=[4:3 - 6:4]
|
||||
// CHECK: load-namespaces.cpp:5:10: FunctionDecl=f:5:10 Extent=[5:5 - 5:13]
|
||||
// CHECK: load-namespaces.cpp:9:11: Namespace=std:9:11 (Definition) Extent=[9:11 - 11:2]
|
||||
// CHECK: load-namespaces.cpp:9:11: Namespace=std:9:11 (Definition) Extent=[9:1 - 11:2]
|
||||
// CHECK: load-namespaces.cpp:10:8: FunctionDecl=g:10:8 Extent=[10:3 - 10:11]
|
||||
// CHECK: load-namespaces.cpp:13:11: NamespaceAlias=std98:13:11 Extent=[13:1 - 13:22]
|
||||
// CHECK: load-namespaces.cpp:13:19: NamespaceRef=std:3:11 Extent=[13:19 - 13:22]
|
||||
|
@ -38,7 +38,7 @@ namespace my_rel_ops = std::rel_ops;
|
|||
// CHECK: load-namespaces.cpp:14:19: NamespaceRef=std98:13:11 Extent=[14:19 - 14:24]
|
||||
// CHECK: load-namespaces.cpp:16:17: UsingDirective=:16:17 Extent=[16:1 - 16:22]
|
||||
// CHECK: load-namespaces.cpp:16:17: NamespaceRef=std0x:14:11 Extent=[16:17 - 16:22]
|
||||
// CHECK: load-namespaces.cpp:18:11: Namespace=std:18:11 (Definition) Extent=[18:11 - 20:2]
|
||||
// CHECK: load-namespaces.cpp:18:11: Namespace=std:18:11 (Definition) Extent=[18:1 - 20:2]
|
||||
// CHECK: load-namespaces.cpp:19:7: FunctionDecl=g:19:7 Extent=[19:3 - 19:13]
|
||||
// CHECK: load-namespaces.cpp:19:12: ParmDecl=:19:12 (Definition) Extent=[19:9 - 19:13]
|
||||
// CHECK: load-namespaces.cpp:22:12: UsingDeclaration=g[19:7, 10:8] Extent=[22:1 - 22:13]
|
||||
|
|
|
@ -1527,7 +1527,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
|
|||
// CHECK: 1:27: TypedefDecl=__darwin_size_t:1:27 (Definition) Extent=[1:1 - 1:42]
|
||||
// CHECK: 2:25: TypedefDecl=size_t:2:25 (Definition) Extent=[2:1 - 2:31]
|
||||
// CHECK: 2:9: TypeRef=__darwin_size_t:1:27 Extent=[2:9 - 2:24]
|
||||
// CHECK: 3:11: Namespace=std:3:11 (Definition) Extent=[3:11 - 5:2]
|
||||
// CHECK: 3:11: Namespace=std:3:11 (Definition) Extent=[3:1 - 5:2]
|
||||
// CHECK: 4:44: ClassTemplate=pair:4:44 (Definition) Extent=[4:3 - 4:64]
|
||||
// CHECK: 4:20: TemplateTypeParameter=_T1:4:20 (Definition) Extent=[4:14 - 4:23]
|
||||
// CHECK: 4:31: TemplateTypeParameter=_T2:4:31 (Definition) Extent=[4:25 - 4:34]
|
||||
|
@ -1541,7 +1541,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
|
|||
// CHECK: 8:10: FunctionDecl=strlen:8:10 Extent=[8:3 - 8:30]
|
||||
// CHECK: 8:3: TypeRef=size_t:2:25 Extent=[8:3 - 8:9]
|
||||
// CHECK: 8:29: ParmDecl=:8:29 (Definition) Extent=[8:17 - 8:30]
|
||||
// CHECK: 10:17: Namespace=clang:10:17 (Definition) Extent=[10:17 - 35:2]
|
||||
// CHECK: 10:17: Namespace=clang:10:17 (Definition) Extent=[10:1 - 35:2]
|
||||
// CHECK: 11:9: ClassDecl=IdentifierInfo:11:9 Extent=[11:3 - 11:23]
|
||||
// CHECK: 12:9: ClassDecl=AttributeList:12:9 (Definition) Extent=[12:3 - 34:4]
|
||||
// CHECK: 13:10: EnumDecl=Kind:13:10 (Definition) Extent=[13:5 - 32:6]
|
||||
|
@ -1623,7 +1623,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
|
|||
// CHECK: 36:8: FunctionDecl=magic_length:36:8 Extent=[36:1 - 36:35]
|
||||
// CHECK: 36:1: TypeRef=size_t:2:25 Extent=[36:1 - 36:7]
|
||||
// CHECK: 36:33: ParmDecl=s:36:33 (Definition) Extent=[36:21 - 36:34]
|
||||
// CHECK: 37:11: Namespace=llvm:37:11 (Definition) Extent=[37:11 - 64:2]
|
||||
// CHECK: 37:11: Namespace=llvm:37:11 (Definition) Extent=[37:1 - 64:2]
|
||||
// CHECK: 38:7: ClassDecl=StringRef:38:7 (Definition) Extent=[38:1 - 63:2]
|
||||
// CHECK: 39:1: UnexposedDecl=:39:1 (Definition) Extent=[39:1 - 39:8]
|
||||
// CHECK: 40:23: TypedefDecl=iterator:40:23 (Definition) Extent=[40:3 - 40:31]
|
||||
|
@ -1765,7 +1765,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
|
|||
// CHECK: 61:43: UnexposedExpr=Length:44:10 Extent=[61:43 - 61:49]
|
||||
// CHECK: 61:43: MemberRefExpr=Length:44:10 Extent=[61:43 - 61:49]
|
||||
// CHECK: 61:52: DeclRefExpr=Start:60:27 Extent=[61:52 - 61:57]
|
||||
// CHECK: 65:11: Namespace=clang:65:11 (Definition) Extent=[65:11 - 81:2]
|
||||
// CHECK: 65:11: Namespace=clang:65:11 (Definition) Extent=[65:1 - 81:2]
|
||||
// CHECK: 66:7: ClassDecl=IdentifierInfo:66:7 (Definition) Extent=[66:1 - 80:2]
|
||||
// CHECK: 67:1: UnexposedDecl=:67:1 (Definition) Extent=[67:1 - 67:8]
|
||||
// CHECK: 67:8: CXXConstructor=IdentifierInfo:67:8 Extent=[67:8 - 67:24]
|
||||
|
@ -1831,7 +1831,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
|
|||
// CHECK: 78:44: UnexposedExpr=getLength:72:12 Extent=[78:44 - 78:55]
|
||||
// CHECK: 78:44: CallExpr=getLength:72:12 Extent=[78:44 - 78:55]
|
||||
// CHECK: 78:44: MemberRefExpr=getLength:72:12 Extent=[78:44 - 78:53]
|
||||
// CHECK: 82:11: Namespace=llvm:82:11 (Definition) Extent=[82:11 - 96:2]
|
||||
// CHECK: 82:11: Namespace=llvm:82:11 (Definition) Extent=[82:1 - 96:2]
|
||||
// CHECK: 83:47: ClassTemplate=StringSwitch:83:47 (Definition) Extent=[83:1 - 95:2]
|
||||
// CHECK: 83:21: TemplateTypeParameter=T:83:21 (Definition) Extent=[83:12 - 83:22]
|
||||
// CHECK: 83:33: TemplateTypeParameter=R:83:33 (Definition) Extent=[83:24 - 83:38]
|
||||
|
|
|
@ -66,11 +66,11 @@ using foo::ClsB;
|
|||
namespace foo_alias3 = foo;
|
||||
|
||||
// RUN: c-index-test -test-load-source-usrs all %s | FileCheck %s
|
||||
// CHECK: usrs.cpp c:@N@foo Extent=[1:11 - 4:2]
|
||||
// CHECK: usrs.cpp c:@N@foo Extent=[1:1 - 4:2]
|
||||
// CHECK: usrs.cpp c:@N@foo@x Extent=[2:3 - 2:8]
|
||||
// CHECK: usrs.cpp c:@N@foo@F@bar#I# Extent=[3:3 - 3:18]
|
||||
// CHECK: usrs.cpp c:usrs.cpp@36@N@foo@F@bar#I#@z Extent=[3:12 - 3:17]
|
||||
// CHECK: usrs.cpp c:@N@bar Extent=[5:11 - 8:2]
|
||||
// CHECK: usrs.cpp c:@N@bar Extent=[5:1 - 8:2]
|
||||
// CHECK: usrs.cpp c:usrs.cpp@64@N@bar@T@QType Extent=[6:3 - 6:20]
|
||||
// CHECK: usrs.cpp c:@N@bar@F@bar#I# Extent=[7:3 - 7:20]
|
||||
// CHECK: usrs.cpp c:usrs.cpp@94@N@bar@F@bar#I#@z Extent=[7:12 - 7:19]
|
||||
|
@ -81,7 +81,7 @@ namespace foo_alias3 = foo;
|
|||
// CHECK: usrs.cpp c:@C@ClsA@F@ClsA#I#I# Extent=[13:3 - 13:37]
|
||||
// CHECK: usrs.cpp c:usrs.cpp@147@C@ClsA@F@ClsA#I#I#@A Extent=[13:8 - 13:13]
|
||||
// CHECK: usrs.cpp c:usrs.cpp@154@C@ClsA@F@ClsA#I#I#@B Extent=[13:15 - 13:20]
|
||||
// CHECK: usrs.cpp c:@N@foo Extent=[16:11 - 22:2]
|
||||
// CHECK: usrs.cpp c:@N@foo Extent=[16:1 - 22:2]
|
||||
// CHECK: usrs.cpp c:@N@foo@C@ClsB Extent=[17:3 - 21:4]
|
||||
// CHECK: usrs.cpp c: Extent=[18:3 - 18:10]
|
||||
// CHECK: usrs.cpp c:@N@foo@C@ClsB@F@ClsB# Extent=[19:5 - 19:27]
|
||||
|
@ -90,8 +90,8 @@ namespace foo_alias3 = foo;
|
|||
// CHECK: usrs.cpp c:@aN@C@ClsC Extent=[29:3 - 29:35]
|
||||
// CHECK: usrs.cpp c:@aN@w Extent=[30:3 - 30:8]
|
||||
// CHECK: usrs.cpp c:@z Extent=[33:1 - 33:6]
|
||||
// CHECK: usrs.cpp c:@N@foo Extent=[35:11 - 40:2]
|
||||
// CHECK: usrs.cpp c:@N@foo@N@taz Extent=[35:27 - 39:2]
|
||||
// CHECK: usrs.cpp c:@N@foo Extent=[35:1 - 40:2]
|
||||
// CHECK: usrs.cpp c:@N@foo@N@taz Extent=[35:17 - 39:2]
|
||||
// CHECK: usrs.cpp c:@N@foo@N@taz@x Extent=[36:3 - 36:8]
|
||||
// CHECK: usrs.cpp c:usrs.cpp@457@N@foo@N@taz@F@add#I#I# Extent=[37:3 - 37:56]
|
||||
// CHECK: usrs.cpp c:usrs.cpp@479@N@foo@N@taz@F@add#I#I#@a Extent=[37:25 - 37:30]
|
||||
|
@ -99,8 +99,8 @@ namespace foo_alias3 = foo;
|
|||
// CHECK: usrs.cpp c:@N@foo@N@taz@F@sub#I#I# Extent=[38:3 - 38:25]
|
||||
// CHECK: usrs.cpp c:usrs.cpp@522@N@foo@N@taz@F@sub#I#I#@a Extent=[38:12 - 38:17]
|
||||
// CHECK: usrs.cpp c:usrs.cpp@529@N@foo@N@taz@F@sub#I#I#@b Extent=[38:19 - 38:24]
|
||||
// CHECK: usrs.cpp c:@N@foo Extent=[42:11 - 52:3]
|
||||
// CHECK: usrs.cpp c:@N@foo@N@taz Extent=[42:27 - 52:2]
|
||||
// CHECK: usrs.cpp c:@N@foo Extent=[42:1 - 52:3]
|
||||
// CHECK: usrs.cpp c:@N@foo@N@taz Extent=[42:17 - 52:2]
|
||||
// CHECK: usrs.cpp c:@N@foo@N@taz@C@ClsD Extent=[43:3 - 51:4]
|
||||
// CHECK: usrs.cpp c: Extent=[44:3 - 44:10]
|
||||
// CHECK: usrs.cpp c:@N@foo@N@taz@C@ClsD@F@operator=#I# Extent=[45:5 - 45:52]
|
||||
|
|
Загрузка…
Ссылка в новой задаче