Add Type::isIncompleteType, which implements the algorithm described in

C99 6.2.5.

llvm-svn: 39289
This commit is contained in:
Chris Lattner 2007-01-23 21:58:16 +00:00
parent d68e129e87
commit c0cb43e518
2 changed files with 28 additions and 0 deletions

View File

@ -27,6 +27,29 @@ bool Type::isVoidType() const {
return false;
}
/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
/// - a type that can describe objects, but which lacks information needed to
/// determine its size.
bool Type::isIncompleteType() const {
switch (getTypeClass()) {
default: return false;
case Builtin:
// Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
// be completed.
return isVoidType();
case Tagged:
// A tagged type (struct/union/enum/class) is incomplete if the decl is a
// forward declaration, but not a full definition (C99 6.2.5p22).
return !cast<TaggedType>(this)->getDecl()->isDefinition();
case Array:
// An array of unknown size is an incomplete type (C99 6.2.5p22).
// FIXME: Implement this.
return true; // cast<ArrayType>(this)-> blah.
}
}
const char *BuiltinType::getName() const {
switch (getKind()) {
default: assert(0 && "Unknown builtin type!");

View File

@ -185,6 +185,10 @@ public:
/// isVoidType - Helper method to determine if this is the 'void' type.
bool isVoidType() const;
/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
/// - a type that can describe objects, but which lacks information needed to
/// determine its size (e.g. void, or a fwd declared struct).
bool isIncompleteType() const;
virtual void getAsString(std::string &InnerString) const = 0;
@ -256,6 +260,7 @@ private:
TypeRef ElementType;
/// FIXME: Capture size for VLA or constant size.
/// Use this to implement Type::isIncompleteType.
ArrayType(TypeRef et, ArraySizeModifier sm, unsigned tq, Type *can)
: Type(Array, can), SizeModifier(sm), IndexTypeQuals(tq), ElementType(et) {}