[PATCH] D15470: Preserve source location in namespaced base ctor initializers
shahms created this revision. shahms added a subscriber: cfe-commits. Resolved a FIXME to preserve source location in qualified base initializers. This patch preserves location information for constructs such as: namespace ns1 { struct Base {}; struct Derived : Base { Derived() : ns1::Base() {} }; } previously, the reference to ns1 would overlap the reference to Base. With this patch it properly spans only ns1. http://reviews.llvm.org/D15470 Files: lib/Sema/SemaDeclCXX.cpp test/Index/namespaced-base-ctor-init.cpp Index: test/Index/namespaced-base-ctor-init.cpp === --- /dev/null +++ test/Index/namespaced-base-ctor-init.cpp @@ -0,0 +1,9 @@ +namespace ns1 { +struct Base {}; +struct Derived : Base { + Derived() : ns1::Base() {} +}; +} + +// RUN: c-index-test -test-load-source all %s | FileCheck %s +// CHECK: namespaced-base-ctor-init.cpp:4:15: NamespaceRef=ns1:1:11 Extent=[4:15 - 4:18] Index: lib/Sema/SemaDeclCXX.cpp === --- lib/Sema/SemaDeclCXX.cpp +++ lib/Sema/SemaDeclCXX.cpp @@ -2980,10 +2980,14 @@ if (BaseType.isNull()) { BaseType = Context.getTypeDeclType(TyD); MarkAnyDeclReferenced(TyD->getLocation(), TyD, /*OdrUse=*/false); - if (SS.isSet()) -// FIXME: preserve source range information + if (SS.isSet()) { BaseType = Context.getElaboratedType(ETK_None, SS.getScopeRep(), BaseType); +TInfo = Context.CreateTypeSourceInfo(BaseType); +ElaboratedTypeLoc TL = TInfo->getTypeLoc().castAs(); +TL.setElaboratedKeywordLoc(IdLoc); +TL.setQualifierLoc(SS.getWithLocInContext(Context)); + } } } Index: test/Index/namespaced-base-ctor-init.cpp === --- /dev/null +++ test/Index/namespaced-base-ctor-init.cpp @@ -0,0 +1,9 @@ +namespace ns1 { +struct Base {}; +struct Derived : Base { + Derived() : ns1::Base() {} +}; +} + +// RUN: c-index-test -test-load-source all %s | FileCheck %s +// CHECK: namespaced-base-ctor-init.cpp:4:15: NamespaceRef=ns1:1:11 Extent=[4:15 - 4:18] Index: lib/Sema/SemaDeclCXX.cpp === --- lib/Sema/SemaDeclCXX.cpp +++ lib/Sema/SemaDeclCXX.cpp @@ -2980,10 +2980,14 @@ if (BaseType.isNull()) { BaseType = Context.getTypeDeclType(TyD); MarkAnyDeclReferenced(TyD->getLocation(), TyD, /*OdrUse=*/false); - if (SS.isSet()) -// FIXME: preserve source range information + if (SS.isSet()) { BaseType = Context.getElaboratedType(ETK_None, SS.getScopeRep(), BaseType); +TInfo = Context.CreateTypeSourceInfo(BaseType); +ElaboratedTypeLoc TL = TInfo->getTypeLoc().castAs(); +TL.setElaboratedKeywordLoc(IdLoc); +TL.setQualifierLoc(SS.getWithLocInContext(Context)); + } } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15470: Preserve source location in namespaced base ctor initializers
shahms updated this revision to Diff 42608. shahms added a comment. Address comments and add CHECK for TypeRef as well http://reviews.llvm.org/D15470 Files: lib/Sema/SemaDeclCXX.cpp test/Index/namespaced-base-ctor-init.cpp Index: test/Index/namespaced-base-ctor-init.cpp === --- /dev/null +++ test/Index/namespaced-base-ctor-init.cpp @@ -0,0 +1,10 @@ +namespace ns1 { +struct Base {}; +struct Derived : Base { + Derived() : ns1::Base() {} +}; +} + +// RUN: c-index-test -test-load-source all %s | FileCheck %s +// CHECK: namespaced-base-ctor-init.cpp:4:15: NamespaceRef=ns1:1:11 Extent=[4:15 - 4:18] +// CHECK: namespaced-base-ctor-init.cpp:4:20: TypeRef=struct ns1::Base:2:8 Extent=[4:20 - 4:24] Index: lib/Sema/SemaDeclCXX.cpp === --- lib/Sema/SemaDeclCXX.cpp +++ lib/Sema/SemaDeclCXX.cpp @@ -2980,10 +2980,15 @@ if (BaseType.isNull()) { BaseType = Context.getTypeDeclType(TyD); MarkAnyDeclReferenced(TyD->getLocation(), TyD, /*OdrUse=*/false); - if (SS.isSet()) -// FIXME: preserve source range information + if (SS.isSet()) { BaseType = Context.getElaboratedType(ETK_None, SS.getScopeRep(), BaseType); +TInfo = Context.CreateTypeSourceInfo(BaseType); +ElaboratedTypeLoc TL = TInfo->getTypeLoc().castAs(); +TL.getNamedTypeLoc().castAs().setNameLoc(IdLoc); +TL.setElaboratedKeywordLoc(SourceLocation()); +TL.setQualifierLoc(SS.getWithLocInContext(Context)); + } } } Index: test/Index/namespaced-base-ctor-init.cpp === --- /dev/null +++ test/Index/namespaced-base-ctor-init.cpp @@ -0,0 +1,10 @@ +namespace ns1 { +struct Base {}; +struct Derived : Base { + Derived() : ns1::Base() {} +}; +} + +// RUN: c-index-test -test-load-source all %s | FileCheck %s +// CHECK: namespaced-base-ctor-init.cpp:4:15: NamespaceRef=ns1:1:11 Extent=[4:15 - 4:18] +// CHECK: namespaced-base-ctor-init.cpp:4:20: TypeRef=struct ns1::Base:2:8 Extent=[4:20 - 4:24] Index: lib/Sema/SemaDeclCXX.cpp === --- lib/Sema/SemaDeclCXX.cpp +++ lib/Sema/SemaDeclCXX.cpp @@ -2980,10 +2980,15 @@ if (BaseType.isNull()) { BaseType = Context.getTypeDeclType(TyD); MarkAnyDeclReferenced(TyD->getLocation(), TyD, /*OdrUse=*/false); - if (SS.isSet()) -// FIXME: preserve source range information + if (SS.isSet()) { BaseType = Context.getElaboratedType(ETK_None, SS.getScopeRep(), BaseType); +TInfo = Context.CreateTypeSourceInfo(BaseType); +ElaboratedTypeLoc TL = TInfo->getTypeLoc().castAs(); +TL.getNamedTypeLoc().castAs().setNameLoc(IdLoc); +TL.setElaboratedKeywordLoc(SourceLocation()); +TL.setQualifierLoc(SS.getWithLocInContext(Context)); + } } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15470: Preserve source location in namespaced base ctor initializers
shahms marked 2 inline comments as done. shahms added a comment. Thanks for taking a look at this so quickly. I've updated the test to make sure the TypeRef is correct as well, in light of the changes here. http://reviews.llvm.org/D15470 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits