[cfe-commits] r83094 - in /cfe/trunk: include/clang/AST/TypeLoc.h include/clang/AST/TypeLocNodes.def lib/AST/TypeLoc.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaType.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Tue Sep 29 12:43:35 PDT 2009
Author: akirtzidis
Date: Tue Sep 29 14:43:35 2009
New Revision: 83094
URL: http://llvm.org/viewvc/llvm-project?rev=83094&view=rev
Log:
Introduce ObjCProtocolListLoc for keeping source location information for protocol references.
Modified:
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/AST/TypeLocNodes.def
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=83094&r1=83093&r2=83094&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Tue Sep 29 14:43:35 2009
@@ -150,6 +150,73 @@
static bool classof(const TypedefLoc *TL) { return true; }
};
+/// \brief Wrapper for source info for ObjC protocol lists.
+class ObjCProtocolListLoc : public TypeSpecLoc {
+ struct Info {
+ SourceLocation LAngleLoc, RAngleLoc;
+ };
+ // SourceLocations are stored after Info, one for each Protocol.
+ SourceLocation *getProtocolLocArray() const {
+ return reinterpret_cast<SourceLocation*>(static_cast<Info*>(Data) + 1);
+ }
+
+public:
+ SourceLocation getLAngleLoc() const {
+ return static_cast<Info*>(Data)->LAngleLoc;
+ }
+ void setLAngleLoc(SourceLocation Loc) {
+ static_cast<Info*>(Data)->LAngleLoc = Loc;
+ }
+
+ SourceLocation getRAngleLoc() const {
+ return static_cast<Info*>(Data)->RAngleLoc;
+ }
+ void setRAngleLoc(SourceLocation Loc) {
+ static_cast<Info*>(Data)->RAngleLoc = Loc;
+ }
+
+ unsigned getNumProtocols() const {
+ return cast<ObjCProtocolListType>(Ty)->getNumProtocols();
+ }
+
+ SourceLocation getProtocolLoc(unsigned i) const {
+ assert(i < getNumProtocols() && "Index is out of bounds!");
+ return getProtocolLocArray()[i];
+ }
+ void setProtocolLoc(unsigned i, SourceLocation Loc) {
+ assert(i < getNumProtocols() && "Index is out of bounds!");
+ getProtocolLocArray()[i] = Loc;
+ }
+
+ ObjCProtocolDecl *getProtocol(unsigned i) const {
+ assert(i < getNumProtocols() && "Index is out of bounds!");
+ return *(cast<ObjCProtocolListType>(Ty)->qual_begin() + i);
+ }
+
+ TypeLoc getBaseTypeLoc() const {
+ void *Next = static_cast<char*>(Data) + getLocalDataSize();
+ return TypeLoc(cast<ObjCProtocolListType>(Ty)->getBaseType(), Next);
+ }
+
+ SourceRange getSourceRange() const {
+ return SourceRange(getLAngleLoc(), getRAngleLoc());
+ }
+
+ /// \brief Returns the size of the type source info data block that is
+ /// specific to this type.
+ unsigned getLocalDataSize() const {
+ return sizeof(Info) + getNumProtocols() * sizeof(SourceLocation);
+ }
+
+ /// \brief Returns the size of the type source info data block.
+ unsigned getFullDataSize() const {
+ return getLocalDataSize() + getBaseTypeLoc().getFullDataSize();
+ }
+
+ static bool classof(const TypeLoc *TL);
+ static bool classof(const ObjCProtocolListLoc *TL) { return true; }
+};
+
/// \brief Wrapper for source info for pointers.
class PointerLoc : public DeclaratorLoc {
struct Info {
Modified: cfe/trunk/include/clang/AST/TypeLocNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLocNodes.def?rev=83094&r1=83093&r2=83094&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TypeLocNodes.def (original)
+++ cfe/trunk/include/clang/AST/TypeLocNodes.def Tue Sep 29 14:43:35 2009
@@ -37,6 +37,7 @@
TYPESPEC_TYPELOC(DefaultTypeSpecLoc, Type)
TYPESPEC_TYPELOC(TypedefLoc, TypedefType)
+TYPESPEC_TYPELOC(ObjCProtocolListLoc, ObjCProtocolListType)
DECLARATOR_TYPELOC(PointerLoc, PointerType)
DECLARATOR_TYPELOC(BlockPointerLoc, BlockPointerType)
DECLARATOR_TYPELOC(MemberPointerLoc, MemberPointerType)
Modified: cfe/trunk/lib/AST/TypeLoc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypeLoc.cpp?rev=83094&r1=83093&r2=83094&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypeLoc.cpp (original)
+++ cfe/trunk/lib/AST/TypeLoc.cpp Tue Sep 29 14:43:35 2009
@@ -83,6 +83,7 @@
/// \brief Returns the size of the type source info data block.
unsigned TypeLoc::getFullDataSize() const {
+ if (isNull()) return 0;
return TypeSizer().Visit(*this);
}
@@ -98,6 +99,7 @@
#include "clang/AST/TypeLocNodes.def"
TypeLoc VisitTypeSpecLoc(TypeLoc TyLoc) { return TypeLoc(); }
+ TypeLoc VisitObjCProtocolListLoc(ObjCProtocolListLoc TL);
TypeLoc VisitTypeLoc(TypeLoc TyLoc) {
assert(0 && "A declarator loc wrapper was not handled!");
@@ -107,6 +109,10 @@
}
+TypeLoc NextLoc::VisitObjCProtocolListLoc(ObjCProtocolListLoc TL) {
+ return TL.getBaseTypeLoc();
+}
+
TypeLoc NextLoc::VisitPointerLoc(PointerLoc TL) {
return TL.getPointeeLoc();
}
@@ -224,6 +230,24 @@
}
//===----------------------------------------------------------------------===//
+// ObjCProtocolListLoc Implementation
+//===----------------------------------------------------------------------===//
+
+namespace {
+
+class ObjCProtocolListLocChecker :
+ public TypeLocVisitor<ObjCProtocolListLocChecker, bool> {
+public:
+ bool VisitObjCProtocolListLoc(ObjCProtocolListLoc TyLoc) { return true; }
+};
+
+}
+
+bool ObjCProtocolListLoc::classof(const TypeLoc *TL) {
+ return ObjCProtocolListLocChecker().Visit(*TL);
+}
+
+//===----------------------------------------------------------------------===//
// PointerLoc Implementation
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=83094&r1=83093&r2=83094&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Tue Sep 29 14:43:35 2009
@@ -179,6 +179,12 @@
void TypeLocReader::VisitTypedefLoc(TypedefLoc TyLoc) {
TyLoc.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
}
+void TypeLocReader::VisitObjCProtocolListLoc(ObjCProtocolListLoc TyLoc) {
+ TyLoc.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ TyLoc.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ for (unsigned i = 0, e = TyLoc.getNumProtocols(); i != e; ++i)
+ TyLoc.setProtocolLoc(i, SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
void TypeLocReader::VisitPointerLoc(PointerLoc TyLoc) {
TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
}
Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=83094&r1=83093&r2=83094&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Tue Sep 29 14:43:35 2009
@@ -177,6 +177,12 @@
void TypeLocWriter::VisitTypedefLoc(TypedefLoc TyLoc) {
Writer.AddSourceLocation(TyLoc.getNameLoc(), Record);
}
+void TypeLocWriter::VisitObjCProtocolListLoc(ObjCProtocolListLoc TyLoc) {
+ Writer.AddSourceLocation(TyLoc.getLAngleLoc(), Record);
+ Writer.AddSourceLocation(TyLoc.getRAngleLoc(), Record);
+ for (unsigned i = 0, e = TyLoc.getNumProtocols(); i != e; ++i)
+ Writer.AddSourceLocation(TyLoc.getProtocolLoc(i), Record);
+}
void TypeLocWriter::VisitPointerLoc(PointerLoc TyLoc) {
Writer.AddSourceLocation(TyLoc.getStarLoc(), Record);
}
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=83094&r1=83093&r2=83094&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Sep 29 14:43:35 2009
@@ -449,7 +449,7 @@
//
QualType adjustParameterType(QualType T);
QualType ConvertDeclSpecToType(const DeclSpec &DS, SourceLocation DeclLoc,
- bool &IsInvalid);
+ bool &IsInvalid, QualType &SourceTy);
void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
QualType BuildPointerType(QualType T, unsigned Quals,
SourceLocation Loc, DeclarationName Entity);
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=83094&r1=83093&r2=83094&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Sep 29 14:43:35 2009
@@ -4075,7 +4075,8 @@
// friend templates because ActOnTag never produces a ClassTemplateDecl
// for a TUK_Friend.
bool invalid = false;
- QualType T = ConvertDeclSpecToType(DS, Loc, invalid);
+ QualType SourceTy;
+ QualType T = ConvertDeclSpecToType(DS, Loc, invalid, SourceTy);
if (invalid) return DeclPtrTy();
// This is definitely an error in C++98. It's probably meant to
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=83094&r1=83093&r2=83094&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Sep 29 14:43:35 2009
@@ -51,14 +51,16 @@
/// object.
/// \param DS the declaration specifiers
/// \param DeclLoc The location of the declarator identifier or invalid if none.
+/// \param SourceTy QualType representing the type as written in source form.
/// \returns The type described by the declaration specifiers. This function
/// never returns null.
QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS,
SourceLocation DeclLoc,
- bool &isInvalid) {
+ bool &isInvalid, QualType &SourceTy) {
// FIXME: Should move the logic from DeclSpec::Finish to here for validity
// checking.
QualType Result;
+ SourceTy = Result;
switch (DS.getTypeSpecType()) {
case DeclSpec::TST_void:
@@ -103,6 +105,9 @@
case DeclSpec::TST_unspecified:
// "<proto1,proto2>" is an objc qualified ID with a missing id.
if (DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers()) {
+ SourceTy = Context.getObjCProtocolListType(QualType(),
+ (ObjCProtocolDecl**)PQ,
+ DS.getNumProtocolQualifiers());
Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy,
(ObjCProtocolDecl**)PQ,
DS.getNumProtocolQualifiers());
@@ -214,7 +219,11 @@
Result = GetTypeFromParser(DS.getTypeRep());
if (DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers()) {
- if (const ObjCInterfaceType *Interface = Result->getAs<ObjCInterfaceType>())
+ SourceTy = Context.getObjCProtocolListType(Result,
+ (ObjCProtocolDecl**)PQ,
+ DS.getNumProtocolQualifiers());
+ if (const ObjCInterfaceType *
+ Interface = Result->getAs<ObjCInterfaceType>()) {
// It would be nice if protocol qualifiers were only stored with the
// ObjCObjectPointerType. Unfortunately, this isn't possible due
// to the following typedef idiom (which is uncommon, but allowed):
@@ -227,7 +236,7 @@
Result = Context.getObjCInterfaceType(Interface->getDecl(),
(ObjCProtocolDecl**)PQ,
DS.getNumProtocolQualifiers());
- else if (Result->isObjCIdType())
+ } else if (Result->isObjCIdType())
// id<protocol-list>
Result = Context.getObjCObjectPointerType(Context.ObjCBuiltinIdTy,
(ObjCProtocolDecl**)PQ, DS.getNumProtocolQualifiers());
@@ -369,6 +378,8 @@
Result = Context.getQualifiedType(Result, Quals);
}
+ if (SourceTy.isNull())
+ SourceTy = Result;
return Result;
}
@@ -839,6 +850,10 @@
// Determine the type of the declarator. Not all forms of declarator
// have a type.
QualType T;
+ // The QualType referring to the type as written in source code. We can't use
+ // T because it can change due to semantic analysis.
+ QualType SourceTy;
+
switch (D.getKind()) {
case Declarator::DK_Abstract:
case Declarator::DK_Normal:
@@ -851,7 +866,7 @@
T = Context.DependentTy;
} else {
bool isInvalid = false;
- T = ConvertDeclSpecToType(DS, D.getIdentifierLoc(), isInvalid);
+ T = ConvertDeclSpecToType(DS, D.getIdentifierLoc(), isInvalid, SourceTy);
if (isInvalid)
D.setInvalidType(true);
else if (OwnedDecl && DS.isTypeSpecOwned())
@@ -869,6 +884,9 @@
T = Context.VoidTy;
break;
}
+
+ if (SourceTy.isNull())
+ SourceTy = T;
if (T == Context.UndeducedAutoTy) {
int Error = -1;
@@ -919,9 +937,6 @@
Name = D.getIdentifier();
bool ShouldBuildInfo = DInfo != 0;
- // The QualType referring to the type as written in source code. We can't use
- // T because it can change due to semantic analysis.
- QualType SourceTy = T;
// Walk the DeclTypeInfo, building the recursive type as we go.
// DeclTypeInfos are ordered from the identifier out, which is
@@ -1278,6 +1293,27 @@
return T;
}
+static void FillTypeSpecLoc(TypeLoc TSL, const DeclSpec &DS) {
+ if (TSL.isNull()) return;
+
+ if (TypedefLoc *TL = dyn_cast<TypedefLoc>(&TSL)) {
+ TL->setNameLoc(DS.getTypeSpecTypeLoc());
+
+ } else if (ObjCProtocolListLoc *PLL = dyn_cast<ObjCProtocolListLoc>(&TSL)) {
+ assert(PLL->getNumProtocols() == DS.getNumProtocolQualifiers());
+ PLL->setLAngleLoc(DS.getProtocolLAngleLoc());
+ PLL->setRAngleLoc(DS.getSourceRange().getEnd());
+ for (unsigned i = 0; i != DS.getNumProtocolQualifiers(); ++i)
+ PLL->setProtocolLoc(i, DS.getProtocolLocs()[i]);
+ FillTypeSpecLoc(PLL->getBaseTypeLoc(), DS);
+
+ } else {
+ //FIXME: Other typespecs.
+ DefaultTypeSpecLoc &DTL = cast<DefaultTypeSpecLoc>(TSL);
+ DTL.setStartLoc(DS.getSourceRange().getBegin());
+ }
+}
+
/// \brief Create and instantiate a DeclaratorInfo with type source information.
///
/// \param T QualType referring to the type as written in source code.
@@ -1343,14 +1379,8 @@
CurrTL = CurrTL.getNextTypeLoc();
}
-
- if (TypedefLoc *TL = dyn_cast<TypedefLoc>(&CurrTL)) {
- TL->setNameLoc(D.getDeclSpec().getTypeSpecTypeLoc());
- } else {
- //FIXME: Other typespecs.
- DefaultTypeSpecLoc &DTL = cast<DefaultTypeSpecLoc>(CurrTL);
- DTL.setStartLoc(D.getDeclSpec().getSourceRange().getBegin());
- }
+
+ FillTypeSpecLoc(CurrTL, D.getDeclSpec());
return DInfo;
}
More information about the cfe-commits
mailing list