Comments (8)
Looks like in llvm/llvm-project#91393, getTypeAsWritten
was replaced with getTemplateArgsAsWritten
.
IWYU also tripped over this.
from cvise.
Yep, it was replaced, but I don't see how can we get to the location of the type name as getTemplateArgsAsWritten
returns something that describes the template arguments. Please let me know once you have a hint, thanks.
from cvise.
from cvise.
from cvise.
@marxin @nickdesaulniers the TemplateSpecializationTypeLoc
returned by getTypeAsWritten
stores the same SourceLocation
for its TemplateName
as that returned by ClassTemplateSpecializationDecl::getLocation
(so you should change the code to use the latter).
Also, I think the existing code contains a subtile bug: it assumes TypeLoc::getBeginLoc
returns the location of the name; for explicit instantiations it will actually return the location of the template
keyword!
from cvise.
Thanks for the suggestions. With the following changes applied:
diff --git a/clang_delta/CommonRenameClassRewriteVisitor.h b/clang_delta/CommonRenameClassRewriteVisitor.h
index f2daeb2..ecbe4f1 100644
--- a/clang_delta/CommonRenameClassRewriteVisitor.h
+++ b/clang_delta/CommonRenameClassRewriteVisitor.h
@@ -144,7 +144,7 @@ bool CommonRenameClassRewriteVisitor<T>::
std::string Name;
if (getNewName(CXXRD, Name)) {
- const TypeSourceInfo *TyInfo = D->getTypeAsWritten();
+ const TypeSourceInfo *TyInfo = D->getTemplateArgsAsWritten()->getTemplateArgs()->getTypeSourceInfo();
if (!TyInfo)
return true;
TypeLoc TyLoc = TyInfo->getTypeLoc();
diff --git a/clang_delta/RemoveNamespace.cpp b/clang_delta/RemoveNamespace.cpp
index b31c00e..8650c49 100644
--- a/clang_delta/RemoveNamespace.cpp
+++ b/clang_delta/RemoveNamespace.cpp
@@ -439,7 +439,7 @@ bool RemoveNamespaceRewriteVisitor::VisitClassTemplatePartialSpecializationDecl(
std::string Name;
if (ConsumerInstance->getNewName(CXXRD, Name)) {
- const TypeSourceInfo *TyInfo = D->getTypeAsWritten();
+ const TypeSourceInfo *TyInfo = D->getTemplateArgsAsWritten()->getTemplateArgs()->getTypeSourceInfo();
if (!TyInfo)
return true;
TypeLoc TyLoc = TyInfo->getTypeLoc();
I've got the following failing tests:
cls = <class 'test_clang_delta.TestClangDelta'>, testcase = 'rename-class/instantiation.cpp', arguments = '--transformation=rename-class --counter=1', output_file = 'rename-class/instantiation.output'
E AssertionError: assert 'template <typename T>\nstruct A {};\n\ntemplate struct AAA<int>;\n' == 'template <typename T>\nstruct A {};\n\ntemplate struct A<int>;\n'
E template <typename T>
E struct A {};
E
E - template struct A<int>;
E + template struct AAA<int>;
E ? ++
Here it seems the renaming happens only for the original struct, not the later one.
cls = <class 'test_clang_delta.TestClangDelta'>, testcase = 'rename-class/partial_specialization.cpp', arguments = '--transformation=rename-class --counter=1', output_file = 'rename-class/partial_specialization.output'
E AssertionError: assert 'template <typename T, int N>\nstruct A {\n T value() const { return N; }\n};\n\ntemplate <typename T>\nstruct S1 <A 3> {\n T value() const { return 0; }\n};\n\n' == 'template <typename T, int N>\nstruct A {\n T value() const { return N; }\n};\n\ntemplate <typename T>\nstruct A <T, 3> {\n T value() const { return 0; }\n};\n\n'
E template <typename T, int N>
E struct A {
E T value() const { return N; }
E };
E
E template <typename T>
E - struct A <T, 3> {
E ? ----
E + struct S1 <A 3> {
E ? ++++
E T value() const { return 0; }
E };
And here it seems the location really points to the first template argument (rather than to the S1
).
cls = <class 'test_clang_delta.TestClangDelta'>, testcase = 'rename-class/specialization.cpp', arguments = '--transformation=rename-class --counter=1', output_file = 'rename-class/specialization.output'
E AssertionError: assert 'template <typename T>\nstruct A {};\n\ntemplate<> struct AAA<int> {};\n' == 'template <typename T>\nstruct A {};\n\ntemplate<> struct A<int> {};\n'
E template <typename T>
E struct A {};
E
E - template<> struct A<int> {};
E + template<> struct AAA<int> {};
E ? ++
This one is similar to the first failing test-case.
from cvise.
D->getTemplateArgsAsWritten()->getTemplateArgs()->getTypeSourceInfo()
returns the TypeSourceInfo
for the first template argument if it is a type, or nullptr
otherwise (and this will crash if an empty template argument list was used). You want to use Decl::getLocation
. I opened a PR that makes the correct changes here.
from cvise.
@sdkrystian Thanks for the PR!
from cvise.
Related Issues (20)
- remove-unused-outer-class is very restrictive on what it removes HOT 1
- cvise stops intermittently HOT 7
- Parallelism doesn't do much HOT 9
- When are shortcuts taken into account? HOT 3
- clang_delta: […] clang::Expr::ClassifyImpl(…) const: Assertion `isLValue()' failed. HOT 15
- cvise: running only the "light" transformations HOT 2
- ability to use /bin/sh for --commands HOT 2
- Release new version HOT 1
- Understanding C-Vise Performance with multiple cores and Comparison with C-Reduce HOT 7
- Idiomatic way to avoid reductions on some parts of the code? HOT 2
- C-Vise doesn't build with recent LLVM hashes HOT 1
- cvise fails to build with LLVM 18.1.0 HOT 7
- Permission denied failure on Windows HOT 23
- Req: cvise use with runtime errors HOT 1
- CVise fills temp directory on Windows HOT 1
- cvise doesn't reliably kill things upon timeout. HOT 3
- Add the ability to control when `cvise_extra` directories are created. HOT 2
- Cvise stopped abnormally midway HOT 5
- Obscure crash error message HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cvise.