From: Steve Naroff Date: Mon, 21 Jan 2008 22:59:18 +0000 (+0000) Subject: Add a predicate/getter when checking for incomplete array types ("[]"). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c06a69a3ef19cc6dbeed7f2acb9de28b66c45d4;p=clang Add a predicate/getter when checking for incomplete array types ("[]"). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46231 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Type.cpp b/AST/Type.cpp index bb031cb656..c078bee909 100644 --- a/AST/Type.cpp +++ b/AST/Type.cpp @@ -235,6 +235,22 @@ const VariableArrayType *Type::getAsVariablyModifiedType() const { return 0; } +bool Type::isIncompleteArrayType() const { + if (const VariableArrayType *VAT = getAsVariableArrayType()) { + if (!VAT->getSizeExpr()) + return true; + } + return false; +} + +const VariableArrayType *Type::getAsIncompleteArrayType() const { + if (const VariableArrayType *VAT = getAsVariableArrayType()) { + if (!VAT->getSizeExpr()) + return VAT; + } + return 0; +} + const RecordType *Type::getAsRecordType() const { // If this is directly a reference type, return it. if (const RecordType *RTy = dyn_cast(this)) diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index ce35c4c3f0..bdcef4a575 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -263,6 +263,10 @@ public: /// types that have a non-constant expression. This does not include "[]". bool isVariablyModifiedType() const; + /// isIncompleteArrayType (C99 6.2.5p22) - Return true for variable array + /// types that don't have any expression ("[]"). + bool isIncompleteArrayType() const; + /// Helper methods to distinguish type categories. All type predicates /// operate on the canonical type, ignoring typedefs. @@ -313,6 +317,7 @@ public: const ArrayType *getAsArrayType() const; const ConstantArrayType *getAsConstantArrayType() const; const VariableArrayType *getAsVariableArrayType() const; + const VariableArrayType *getAsIncompleteArrayType() const; const VariableArrayType *getAsVariablyModifiedType() const; const RecordType *getAsRecordType() const; const RecordType *getAsStructureType() const;