Skip to content

Commit afc82d5

Browse files
sdkrystianvinniefalco
authored andcommitted
Better bool
close #189
1 parent aed34a1 commit afc82d5

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

source/lib/api/AST/ASTVisitor.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ getSourceCode(
225225

226226
//------------------------------------------------
227227

228+
std::string
229+
ASTVisitor::
230+
getTypeAsString(
231+
QualType T)
232+
{
233+
return T.getAsString(astContext_->getPrintingPolicy());
234+
}
235+
228236
Access
229237
ASTVisitor::
230238
getAccessFromSpecifier(
@@ -246,7 +254,7 @@ getAccessFromSpecifier(
246254
TagDecl*
247255
ASTVisitor::
248256
getTagDeclForType(
249-
QualType const& T)
257+
QualType T)
250258
{
251259
if(TagDecl const* D = T->getAsTagDecl())
252260
return D->getDefinition();
@@ -256,7 +264,7 @@ getTagDeclForType(
256264
RecordDecl*
257265
ASTVisitor::
258266
getRecordDeclForType(
259-
QualType const& T)
267+
QualType T)
260268
{
261269
if(RecordDecl const* D = T->getAsRecordDecl())
262270
return D->getDefinition();
@@ -266,14 +274,12 @@ getRecordDeclForType(
266274
TypeInfo
267275
ASTVisitor::
268276
getTypeInfoForType(
269-
QualType const& T)
277+
QualType T)
270278
{
271279
TagDecl const* TD = getTagDeclForType(T);
272-
if (T->isBuiltinType()
273-
&& (T->getAs<clang::BuiltinType>()->getKind() == BuiltinType::Bool))
274-
return TypeInfo(Reference(EmptySID, "bool"));
275280
if(!TD)
276-
return TypeInfo(Reference(EmptySID, T.getAsString()));
281+
return TypeInfo(Reference(EmptySID,
282+
getTypeAsString(T)));
277283
InfoType IT;
278284
if(dyn_cast<EnumDecl>(TD))
279285
IT = InfoType::IT_enum;
@@ -296,8 +302,6 @@ parseParameters(
296302
// KRYSTIAN NOTE: call getOriginalType instead
297303
// of getType if we want to preserve top-level
298304
// cv-qualfiers/array types/function types
299-
auto ti = getTypeInfoForType(P->getType());
300-
301305
FieldTypeInfo& FieldInfo = I.Params.emplace_back(
302306
getTypeInfoForType(P->getType()),
303307
P->getNameAsString());
@@ -683,10 +687,9 @@ extractBases(
683687
continue;
684688
if(auto const* Ty = B.getType()->getAs<TemplateSpecializationType>())
685689
{
686-
TemplateDecl const* D = Ty->getTemplateName().getAsTemplateDecl();
687690
I.Bases.emplace_back(
688691
getSymbolID(D),
689-
B.getType().getAsString(),
692+
getTypeAsString(B.getType()),
690693
getAccessFromSpecifier(B.getAccessSpecifier()),
691694
isVirtual);
692695
}
@@ -702,7 +705,7 @@ extractBases(
702705
{
703706
I.Bases.emplace_back(
704707
EmptySID,
705-
B.getType().getAsString(),
708+
getTypeAsString(B.getType()),
706709
getAccessFromSpecifier(B.getAccessSpecifier()),
707710
isVirtual);
708711
}
@@ -727,7 +730,7 @@ constructFunction(
727730
else
728731
I.Loc.emplace_back(LineNumber, File, IsFileInRootDir);
729732
QualType const qt = D->getReturnType();
730-
std::string s = qt.getAsString();
733+
std::string s = getTypeAsString(qt);
731734
I.ReturnType = getTypeInfoForType(qt);
732735
parseParameters(I, D);
733736

@@ -1046,7 +1049,7 @@ buildEnum(
10461049
I.Scoped = D->isScoped();
10471050
if(D->isFixed())
10481051
{
1049-
auto Name = D->getIntegerType().getAsString();
1052+
auto Name = getTypeAsString(D->getIntegerType());
10501053
I.BaseType = TypeInfo(Name);
10511054
}
10521055
parseEnumerators(I, D);
@@ -1069,8 +1072,8 @@ buildVar(
10691072
I.DefLoc.emplace(LineNumber, File, IsFileInRootDir);
10701073
else
10711074
I.Loc.emplace_back(LineNumber, File, IsFileInRootDir);
1072-
static_cast<TypeInfo&>(I) =
1073-
getTypeInfoForType(D->getTypeSourceInfo()->getType());
1075+
static_cast<TypeInfo&>(I) = getTypeInfoForType(
1076+
D->getTypeSourceInfo()->getType());
10741077
I.specs.storageClass = D->getStorageClass();
10751078
insertBitcode(ex_, writeBitcode(I));
10761079
insertBitcode(ex_, writeParent(I, D->getAccess()));
@@ -1120,7 +1123,8 @@ buildTypedef(
11201123
TypedefInfo I;
11211124
if(! extractInfo(I, D))
11221125
return;
1123-
I.Underlying = getTypeInfoForType(D->getUnderlyingType());
1126+
I.Underlying = getTypeInfoForType(
1127+
D->getUnderlyingType());
11241128
if(I.Underlying.Type.Name.empty())
11251129
{
11261130
// Typedef for an unnamed type. This is like

source/lib/api/AST/ASTVisitor.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,25 @@ class ASTVisitor
9595
Decl const* D,
9696
SourceRange const& R);
9797

98+
std::string
99+
getTypeAsString(
100+
QualType T);
101+
98102
Access
99103
getAccessFromSpecifier(
100104
AccessSpecifier as) noexcept;
101105

102106
TagDecl*
103107
getTagDeclForType(
104-
QualType const& T);
108+
QualType T);
105109

106110
RecordDecl*
107111
getRecordDeclForType(
108-
QualType const& T);
112+
QualType T);
109113

110114
TypeInfo
111115
getTypeInfoForType(
112-
QualType const& T);
116+
QualType T);
113117

114118
void
115119
parseParameters(

test-files/old-tests/function-parm-decay.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<file path="function-parm-decay.cpp" line="14"/>
1515
<file path="function-parm-decay.cpp" line="15"/>
1616
<file path="function-parm-decay.cpp" line="16"/>
17-
<param name="x" type="int (*)(_Bool)"/>
17+
<param name="x" type="int (*)(bool)"/>
1818
</function>
1919
<function name="i" id="UTOfie03KjmJww3mduHOqLZB5aI=">
2020
<file path="function-parm-decay.cpp" line="21"/>

0 commit comments

Comments
 (0)