#include "clang/AST/TypeNodes.def"
TagFirst = Record, TagLast = Enum
};
-
+
+protected:
+ enum { TypeClassBitSize = 6 };
+
private:
QualType CanonicalType;
/// TypeClass bitfield - Enum that specifies what subclass this belongs to.
/// Note that this should stay at the end of the ivars for Type so that
/// subclasses can pack their bitfields into the same word.
- unsigned TC : 6;
+ unsigned TC : TypeClassBitSize;
Type(const Type&); // DO NOT IMPLEMENT.
void operator=(const Type&); // DO NOT IMPLEMENT.
}
static bool classof(const ObjCObjectPointerType *) { return true; }
};
-
+
// Inline function definitions.
/// getUnqualifiedType - Return the type without any qualifiers.
BlockSemaInfo *PrevBlockInfo;
};
+/// \brief Holds a QualType and a DeclaratorInfo* that came out of a declarator
+/// parsing.
+///
+/// LocInfoType is a "transient" type, only needed for passing to/from Parser
+/// and Sema, when we want to preserve type source info for a parsed type.
+/// It will not participate in the type system semantics in any way.
+class LocInfoType : public Type {
+ enum {
+ // The last number that can fit in Type's TC.
+ // Avoids conflict with an existing Type class.
+ LocInfo = (1 << TypeClassBitSize) - 1
+ };
+
+ DeclaratorInfo *DeclInfo;
+
+ LocInfoType(QualType ty, DeclaratorInfo *DInfo)
+ : Type((TypeClass)LocInfo, ty, ty->isDependentType()), DeclInfo(DInfo) {
+ assert(getTypeClass() == (TypeClass)LocInfo && "LocInfo didn't fit in TC?");
+ }
+ friend class Sema;
+
+public:
+ QualType getType() const { return getCanonicalTypeInternal(); }
+ DeclaratorInfo *getDeclaratorInfo() const { return DeclInfo; }
+
+ virtual void getAsStringInternal(std::string &Str,
+ const PrintingPolicy &Policy) const;
+
+ static bool classof(const Type *T) {
+ return T->getTypeClass() == (TypeClass)LocInfo;
+ }
+ static bool classof(const LocInfoType *) { return true; }
+};
+
/// Sema - This implements semantic analysis and AST building for C.
class Sema : public Action {
Sema(const Sema&); // DO NOT IMPLEMENT
/// unit.
bool CompleteTranslationUnit;
+ llvm::BumpPtrAllocator BumpAlloc;
+
/// \brief The number of SFINAE diagnostics that have been trapped.
unsigned NumSFINAEErrors;
unsigned Skip = 0, TagDecl **OwnedDecl = 0);
DeclaratorInfo *GetDeclaratorInfoForDeclarator(Declarator &D, QualType T,
unsigned Skip);
+ /// \brief Create a LocInfoType to hold the given QualType and DeclaratorInfo.
+ QualType CreateLocInfoType(QualType T, DeclaratorInfo *DInfo);
DeclarationName GetNameForDeclarator(Declarator &D);
bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range);
bool CheckDistantExceptionSpec(QualType T);
return DInfo;
}
+/// \brief Create a LocInfoType to hold the given QualType and DeclaratorInfo.
+QualType Sema::CreateLocInfoType(QualType T, DeclaratorInfo *DInfo) {
+ // FIXME: LocInfoTypes are "transient", only needed for passing to/from Parser
+ // and Sema during declaration parsing. Try deallocating/caching them when
+ // it's appropriate, instead of allocating them and keeping them around.
+ LocInfoType *LocT = (LocInfoType*)BumpAlloc.Allocate(sizeof(LocInfoType), 8);
+ new (LocT) LocInfoType(T, DInfo);
+ assert(LocT->getTypeClass() != T->getTypeClass() &&
+ "LocInfoType's TypeClass conflicts with an existing Type class");
+ return QualType(LocT, 0);
+}
+
+void LocInfoType::getAsStringInternal(std::string &Str,
+ const PrintingPolicy &Policy) const {
+ assert(false && "LocInfoType should not be used in the type system");
+}
+
/// CheckSpecifiedExceptionType - Check if the given type is valid in an
/// exception specification. Incomplete types, or pointers to incomplete types
/// other than void are not allowed.