Added a new class for Interfaces qualified by protocol list.

Protocols are now sorted and made unique in the list.
Enhanced pretty printer for @interface (So, I can see the protocol list).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42776 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Fariborz Jahanian 2007-10-08 23:06:41 +00:00
Родитель 22cdd239dc
Коммит e37882ad33
5 изменённых файлов: 64 добавлений и 3 удалений

Просмотреть файл

@ -141,6 +141,10 @@ const llvm::Type *CodeGenTypes::ConvertType(QualType T) {
assert(0 && "FIXME: add missing functionality here");
break;
case Type::ObjcQualifiedInterface:
assert(0 && "FIXME: add missing functionality here");
break;
case Type::Tagged:
const TagType &TT = cast<TagType>(Ty);
const TagDecl *TD = TT.getDecl();

Просмотреть файл

@ -74,8 +74,26 @@ static void PrintTypeDefDecl(TypedefDecl *TD) {
}
static void PrintObjcInterfaceDecl(ObjcInterfaceDecl *OID) {
std::string S = OID->getName();
fprintf(stderr, "@interface %s;\n", S.c_str());
std::string I = OID->getName();
ObjcInterfaceDecl *SID = OID->getSuperClass();
if (SID) {
std::string S = SID->getName();
fprintf(stderr, "@interface %s : %s", I.c_str(), S.c_str());
}
else
fprintf(stderr, "@interface %s", I.c_str());
// Protocols?
int count = OID->getNumIntfRefProtocols();
if (count > 0) {
ObjcProtocolDecl **refProtocols = OID->getReferencedProtocols();
for (int i = 0; i < count; i++)
fprintf(stderr, "%c%s", (i == 0 ? '<' : ','),
refProtocols[i]->getName());
}
if (count > 0)
fprintf(stderr, ">;\n");
else
fprintf(stderr, ";\n");
// FIXME: implement the rest...
}

Просмотреть файл

@ -618,6 +618,12 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(tok::TokenKind mType,
MethodAttrs, MethodImplKind);
}
/// CmpProtocolVals - Comparison predicate for sorting protocols.
static bool CmpProtocolVals(const IdentifierInfo* const& lhs,
const IdentifierInfo* const& rhs) {
return strcmp(lhs->getName(), rhs->getName()) < 0;
}
/// objc-protocol-refs:
/// '<' identifier-list '>'
///
@ -640,6 +646,15 @@ bool Parser::ParseObjCProtocolReferences(
break;
ConsumeToken();
}
// Sort protocols, keyed by name.
// Later on, we remove duplicates.
std::stable_sort(ProtocolRefs.begin(), ProtocolRefs.end(), CmpProtocolVals);
// Make protocol names unique.
ProtocolRefs.erase(std::unique(ProtocolRefs.begin(), ProtocolRefs.end()),
ProtocolRefs.end());
// Consume the '>'.
return ExpectAndConsume(tok::greater, diag::err_expected_greater);
}

Просмотреть файл

@ -739,6 +739,7 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";

Просмотреть файл

@ -32,6 +32,7 @@ namespace clang {
class RecordDecl;
class EnumDecl;
class ObjcInterfaceDecl;
class ObjcProtocolDecl;
class Expr;
class SourceLocation;
class PointerType;
@ -204,7 +205,7 @@ public:
Vector, OCUVector,
FunctionNoProto, FunctionProto,
TypeName, Tagged,
ObjcInterface,
ObjcInterface, ObjcQualifiedInterface,
TypeOfExp, TypeOfTyp // GNU typeof extension.
};
private:
@ -831,6 +832,28 @@ public:
static bool classof(const ObjcInterfaceType *) { return true; }
};
/// - ObjcQualifiedInterfaceType - This class represense interface types
/// conforming to a list of protocols; such as, INTF<Proto1, Proto2, Proto1>.
class ObjcQualifiedInterfaceType : public Type {
// Interface type for this protocol conforming object type
ObjcInterfaceType *InterfaceType;
// List of protocols for this protocol conforming object type
// List is sorted on protocol name. No protocol is enterred more than once.
llvm::SmallVector<ObjcProtocolDecl*, 8> Protocols;
ObjcQualifiedInterfaceType(ObjcInterfaceType *T) :
Type(ObjcQualifiedInterface, QualType()), InterfaceType(T) { }
public:
ObjcInterfaceType *getInterfaceType() const { return InterfaceType; }
static bool classof(const Type *T) {
return T->getTypeClass() == ObjcQualifiedInterface;
}
static bool classof(const ObjcQualifiedInterfaceType *) { return true; }
};
/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
/// to detect TagType objects of structs/unions/classes.
class RecordType : public TagType {