From 0643e333a3e433808e5e622c22b1d1e83f9883b4 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 29 Sep 2009 19:45:22 +0000 Subject: [PATCH] Introduce ObjCInterfaceLoc which provides type source information for ObjC interfaces. llvm-svn: 83097 --- clang/include/clang/AST/TypeLoc.h | 32 ++++++++++++++++++++++++ clang/include/clang/AST/TypeLocNodes.def | 1 + clang/lib/AST/TypeLoc.cpp | 18 +++++++++++++ clang/lib/Frontend/PCHReaderDecl.cpp | 3 +++ clang/lib/Frontend/PCHWriterDecl.cpp | 3 +++ clang/lib/Sema/SemaType.cpp | 3 +++ 6 files changed, 60 insertions(+) diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h index dfa69a979ea9..100003929d1c 100644 --- a/clang/include/clang/AST/TypeLoc.h +++ b/clang/include/clang/AST/TypeLoc.h @@ -154,6 +154,38 @@ public: static bool classof(const TypedefLoc *TL) { return true; } }; +/// \brief Wrapper for source info for ObjC interfaces. +class ObjCInterfaceLoc : public TypeSpecLoc { + struct Info { + SourceLocation NameLoc; + }; + +public: + SourceLocation getNameLoc() const { + return static_cast(Data)->NameLoc; + } + void setNameLoc(SourceLocation Loc) { + static_cast(Data)->NameLoc = Loc; + } + SourceRange getSourceRange() const { + return SourceRange(getNameLoc(), getNameLoc()); + } + + ObjCInterfaceDecl *getIFaceDecl() const { + return cast(Ty)->getDecl(); + } + + /// \brief Returns the size of the type source info data block that is + /// specific to this type. + unsigned getLocalDataSize() const { return sizeof(Info); } + + /// \brief Returns the size of the type source info data block. + unsigned getFullDataSize() const { return getLocalDataSize(); } + + static bool classof(const TypeLoc *TL); + static bool classof(const TypedefLoc *TL) { return true; } +}; + /// \brief Wrapper for source info for ObjC protocol lists. class ObjCProtocolListLoc : public TypeSpecLoc { struct Info { diff --git a/clang/include/clang/AST/TypeLocNodes.def b/clang/include/clang/AST/TypeLocNodes.def index de20182c0ee6..107ea85479f9 100644 --- a/clang/include/clang/AST/TypeLocNodes.def +++ b/clang/include/clang/AST/TypeLocNodes.def @@ -37,6 +37,7 @@ TYPESPEC_TYPELOC(DefaultTypeSpecLoc, Type) TYPESPEC_TYPELOC(TypedefLoc, TypedefType) +TYPESPEC_TYPELOC(ObjCInterfaceLoc, ObjCInterfaceType) TYPESPEC_TYPELOC(ObjCProtocolListLoc, ObjCProtocolListType) DECLARATOR_TYPELOC(PointerLoc, PointerType) DECLARATOR_TYPELOC(BlockPointerLoc, BlockPointerType) diff --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp index fbd7caa3268e..1337def2a050 100644 --- a/clang/lib/AST/TypeLoc.cpp +++ b/clang/lib/AST/TypeLoc.cpp @@ -229,6 +229,24 @@ bool TypedefLoc::classof(const TypeLoc *TL) { return TypedefLocChecker().Visit(*TL); } +//===----------------------------------------------------------------------===// +// ObjCInterfaceLoc Implementation +//===----------------------------------------------------------------------===// + +namespace { + +class ObjCInterfaceLocChecker : + public TypeLocVisitor { +public: + bool VisitObjCInterfaceLoc(ObjCInterfaceLoc TyLoc) { return true; } +}; + +} + +bool ObjCInterfaceLoc::classof(const TypeLoc *TL) { + return ObjCInterfaceLocChecker().Visit(*TL); +} + //===----------------------------------------------------------------------===// // ObjCProtocolListLoc Implementation //===----------------------------------------------------------------------===// diff --git a/clang/lib/Frontend/PCHReaderDecl.cpp b/clang/lib/Frontend/PCHReaderDecl.cpp index 550f4dba7990..9b28e8bac79c 100644 --- a/clang/lib/Frontend/PCHReaderDecl.cpp +++ b/clang/lib/Frontend/PCHReaderDecl.cpp @@ -179,6 +179,9 @@ void TypeLocReader::VisitDefaultTypeSpecLoc(DefaultTypeSpecLoc TyLoc) { void TypeLocReader::VisitTypedefLoc(TypedefLoc TyLoc) { TyLoc.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); } +void TypeLocReader::VisitObjCInterfaceLoc(ObjCInterfaceLoc TyLoc) { + TyLoc.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); +} void TypeLocReader::VisitObjCProtocolListLoc(ObjCProtocolListLoc TyLoc) { TyLoc.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); TyLoc.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); diff --git a/clang/lib/Frontend/PCHWriterDecl.cpp b/clang/lib/Frontend/PCHWriterDecl.cpp index 7a8f3e850212..9573d43c7173 100644 --- a/clang/lib/Frontend/PCHWriterDecl.cpp +++ b/clang/lib/Frontend/PCHWriterDecl.cpp @@ -177,6 +177,9 @@ void TypeLocWriter::VisitDefaultTypeSpecLoc(DefaultTypeSpecLoc TyLoc) { void TypeLocWriter::VisitTypedefLoc(TypedefLoc TyLoc) { Writer.AddSourceLocation(TyLoc.getNameLoc(), Record); } +void TypeLocWriter::VisitObjCInterfaceLoc(ObjCInterfaceLoc TyLoc) { + Writer.AddSourceLocation(TyLoc.getNameLoc(), Record); +} void TypeLocWriter::VisitObjCProtocolListLoc(ObjCProtocolListLoc TyLoc) { Writer.AddSourceLocation(TyLoc.getLAngleLoc(), Record); Writer.AddSourceLocation(TyLoc.getRAngleLoc(), Record); diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 89e9e4942b5a..333895b6c09a 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1299,6 +1299,9 @@ static void FillTypeSpecLoc(TypeLoc TSL, const DeclSpec &DS) { if (TypedefLoc *TL = dyn_cast(&TSL)) { TL->setNameLoc(DS.getTypeSpecTypeLoc()); + } else if (ObjCInterfaceLoc *TL = dyn_cast(&TSL)) { + TL->setNameLoc(DS.getTypeSpecTypeLoc()); + } else if (ObjCProtocolListLoc *PLL = dyn_cast(&TSL)) { assert(PLL->getNumProtocols() == DS.getNumProtocolQualifiers()); PLL->setLAngleLoc(DS.getProtocolLAngleLoc());