Address Chris's comments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43445 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp
index 87de905..bab2e0f 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -837,10 +837,11 @@
return getTagDeclType(CFConstantStringTypeDecl);
}
+// This returns true if a type has been typedefed to BOOL:
+// typedef <type> BOOL;
static bool isTypeTypedefedAsBOOL(QualType T)
{
- if (const PointerType *NCPT = T->getAsPointerType())
- if (const TypedefType *TT = dyn_cast<TypedefType>(NCPT->getPointeeType()))
+ if (const TypedefType *TT = dyn_cast<TypedefType>(T))
if (!strcmp(TT->getDecl()->getName(), "BOOL"))
return true;
@@ -849,9 +850,15 @@
void ASTContext::getObjcEncodingForType(QualType T, std::string& S) const
{
- QualType Ty = T.getCanonicalType();
-
- if (const BuiltinType *BT = Ty->getAsBuiltinType()) {
+ // FIXME: This currently doesn't encode:
+ // @ An object (whether statically typed or typed id)
+ // # A class object (Class)
+ // : A method selector (SEL)
+ // {name=type...} A structure
+ // (name=type...) A union
+ // bnum A bit field of num bits
+
+ if (const BuiltinType *BT = T->getAsBuiltinType()) {
char encoding;
switch (BT->getKind()) {
case BuiltinType::Void:
@@ -906,13 +913,13 @@
}
S += encoding;
- } else if (const PointerType *PT = Ty->getAsPointerType()) {
+ } else if (const PointerType *PT = T->getAsPointerType()) {
QualType PointeeTy = PT->getPointeeType();
if (PointeeTy->isCharType()) {
// char pointer types should be encoded as '*' unless it is a
// type that has been typedef'd to 'BOOL'.
- if (!isTypeTypedefedAsBOOL(T)) {
+ if (!isTypeTypedefedAsBOOL(PointeeTy)) {
S += '*';
return;
}
@@ -920,7 +927,7 @@
S += '^';
getObjcEncodingForType(PT->getPointeeType(), S);
- } else if (const ArrayType *AT = Ty->getAsArrayType()) {
+ } else if (const ArrayType *AT = T->getAsArrayType()) {
S += '[';
if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT))
@@ -931,8 +938,7 @@
getObjcEncodingForType(AT->getElementType(), S);
S += ']';
} else
- fprintf(stderr, "@encode for type %s not implemented!\n",
- Ty.getAsString().c_str());
+ assert(0 && "@encode for type not implemented!");
}
void ASTContext::setBuiltinVaListType(QualType T)