Skip to content

Commit 0b04669

Browse files
committed
Revert "Fix bugs related to printing types (compiler-research#661)"
This reverts commit f65f80a.
1 parent f65f80a commit 0b04669

File tree

3 files changed

+6
-54
lines changed

3 files changed

+6
-54
lines changed

lib/CppInterOp/CppInterOp.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -517,28 +517,18 @@ std::string GetCompleteName(TCppType_t klass) {
517517
auto& C = getSema().getASTContext();
518518
auto* D = (Decl*)klass;
519519

520-
PrintingPolicy Policy = C.getPrintingPolicy();
521-
Policy.SuppressUnwrittenScope = true;
522-
Policy.SuppressScope = true;
523-
Policy.AnonymousTagLocations = false;
524-
Policy.SuppressTemplateArgsInCXXConstructors = false;
525-
Policy.SuppressDefaultTemplateArgs = false;
526-
Policy.AlwaysIncludeTypeForTemplateArgument = true;
527-
528520
if (auto* ND = llvm::dyn_cast_or_null<NamedDecl>(D)) {
529521
if (auto* TD = llvm::dyn_cast<TagDecl>(ND)) {
530522
std::string type_name;
531523
QualType QT = C.getTagDeclType(TD);
524+
PrintingPolicy Policy = C.getPrintingPolicy();
525+
Policy.SuppressUnwrittenScope = true;
526+
Policy.SuppressScope = true;
527+
Policy.AnonymousTagLocations = false;
532528
QT.getAsStringInternal(type_name, Policy);
529+
533530
return type_name;
534531
}
535-
if (auto* FD = llvm::dyn_cast<FunctionDecl>(ND)) {
536-
std::string func_name;
537-
llvm::raw_string_ostream name_stream(func_name);
538-
FD->getNameForDiagnostic(name_stream, Policy, false);
539-
name_stream.flush();
540-
return func_name;
541-
}
542532

543533
return ND->getNameAsString();
544534
}
@@ -3645,11 +3635,7 @@ std::string GetFunctionArgDefault(TCppFunction_t func,
36453635
if (PI->hasDefaultArg()) {
36463636
std::string Result;
36473637
llvm::raw_string_ostream OS(Result);
3648-
Expr* DefaultArgExpr = nullptr;
3649-
if (PI->hasUninstantiatedDefaultArg())
3650-
DefaultArgExpr = PI->getUninstantiatedDefaultArg();
3651-
else
3652-
DefaultArgExpr = PI->getDefaultArg();
3638+
Expr* DefaultArgExpr = const_cast<Expr*>(PI->getDefaultArg());
36533639
DefaultArgExpr->printPretty(OS, nullptr, PrintingPolicy(LangOptions()));
36543640

36553641
// FIXME: Floats are printed in clang with the precision of their underlying

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,15 +2078,6 @@ TEST(FunctionReflectionTest, GetFunctionArgDefault) {
20782078
template<class A>
20792079
void get_size(long k, A, char ch = 'a', double l = 0.0) {}
20802080
2081-
template<typename T>
2082-
struct Other {};
2083-
2084-
template <typename T, typename S = Other<T>>
2085-
struct MyStruct {
2086-
T t;
2087-
S s;
2088-
void fn(T t, S s = S()) {}
2089-
};
20902081
)";
20912082

20922083
GetAllTopLevelDecls(code, Decls);
@@ -2111,20 +2102,6 @@ TEST(FunctionReflectionTest, GetFunctionArgDefault) {
21112102
EXPECT_EQ(Cpp::GetFunctionArgDefault(Decls[4], 1), "");
21122103
EXPECT_EQ(Cpp::GetFunctionArgDefault(Decls[4], 2), "\'a\'");
21132104
EXPECT_EQ(Cpp::GetFunctionArgDefault(Decls[4], 3), "0.");
2114-
2115-
ASTContext& C = Interp->getCI()->getASTContext();
2116-
Cpp::TemplateArgInfo template_args[1] = {C.IntTy.getAsOpaquePtr()};
2117-
Cpp::TCppScope_t my_struct =
2118-
Cpp::InstantiateTemplate(Decls[6], template_args, 1);
2119-
EXPECT_TRUE(my_struct);
2120-
2121-
std::vector<Cpp::TCppFunction_t> fns =
2122-
Cpp::GetFunctionsUsingName(my_struct, "fn");
2123-
EXPECT_EQ(fns.size(), 1);
2124-
2125-
Cpp::TCppScope_t fn = fns[0];
2126-
EXPECT_EQ(Cpp::GetFunctionArgDefault(fn, 0), "");
2127-
EXPECT_EQ(Cpp::GetFunctionArgDefault(fn, 1), "S()");
21282105
}
21292106

21302107
TEST(FunctionReflectionTest, Construct) {

unittests/CppInterOp/ScopeReflectionTest.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,6 @@ TEST(ScopeReflectionTest, GetCompleteName) {
334334
A<int> a;
335335
336336
enum { enum1 };
337-
338-
template<typename T1, typename T2>
339-
void fn(T1 t1, T2 t2) {}
340337
)";
341338
GetAllTopLevelDecls(code, Decls);
342339

@@ -353,15 +350,7 @@ TEST(ScopeReflectionTest, GetCompleteName) {
353350
Cpp::GetVariableType(
354351
Decls[9]))), "A<int>");
355352
EXPECT_EQ(Cpp::GetCompleteName(Decls[10]), "(unnamed)");
356-
EXPECT_EQ(Cpp::GetCompleteName(Decls[11]), "fn");
357353
EXPECT_EQ(Cpp::GetCompleteName(nullptr), "<unnamed>");
358-
359-
ASTContext& C = Interp->getCI()->getASTContext();
360-
Cpp::TemplateArgInfo template_args[2] = {C.IntTy.getAsOpaquePtr(),
361-
C.DoubleTy.getAsOpaquePtr()};
362-
Cpp::TCppScope_t fn = Cpp::InstantiateTemplate(Decls[11], template_args, 2);
363-
EXPECT_TRUE(fn);
364-
EXPECT_EQ(Cpp::GetCompleteName(fn), "fn<int, double>");
365354
}
366355

367356
TEST(ScopeReflectionTest, GetQualifiedName) {

0 commit comments

Comments
 (0)