aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Type.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-07-06 15:59:29 +0000
committerDouglas Gregor <dgregor@apple.com>2009-07-06 15:59:29 +0000
commit7e7eb3da052a6d80ddf2377cab0384c798f73f75 (patch)
treed73b5a19683a56585be300d5c19bb12eb0ca37a7 /lib/AST/Type.cpp
parent6f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55 (diff)
Keep track of the Expr used to describe the size of an array type,
from Enea Zaffanella! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74831 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r--lib/AST/Type.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 4e061a9fbe..2b307c86e3 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -37,6 +37,18 @@ void Type::Destroy(ASTContext& C) {
C.Deallocate(this);
}
+void ConstantArrayWithExprType::Destroy(ASTContext& C) {
+ // FIXME: destruction of SizeExpr commented out due to resource contention.
+ // SizeExpr->Destroy(C);
+ // See FIXME in SemaDecl.cpp:1536: if we were able to either steal
+ // or clone the SizeExpr there, then here we could freely delete it.
+ // Since we do not know how to steal or clone, we keep a pointer to
+ // a shared resource, but we cannot free it.
+ // (There probably is a trivial solution ... for people knowing clang!).
+ this->~ConstantArrayWithExprType();
+ C.Deallocate(this);
+}
+
void VariableArrayType::Destroy(ASTContext& C) {
if (SizeExpr)
SizeExpr->Destroy(C);
@@ -163,6 +175,8 @@ bool Type::isDerivedType() const {
case Pointer:
case VariableArray:
case ConstantArray:
+ case ConstantArrayWithExpr:
+ case ConstantArrayWithoutExpr:
case IncompleteArray:
case FunctionProto:
case FunctionNoProto:
@@ -1339,6 +1353,29 @@ void ConstantArrayType::getAsStringInternal(std::string &S, const PrintingPolicy
getElementType().getAsStringInternal(S, Policy);
}
+void ConstantArrayWithExprType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
+ if (Policy.ConstantArraySizeAsWritten) {
+ std::string SStr;
+ llvm::raw_string_ostream s(SStr);
+ getSizeExpr()->printPretty(s, 0, Policy);
+ S += '[';
+ S += s.str();
+ S += ']';
+ getElementType().getAsStringInternal(S, Policy);
+ }
+ else
+ ConstantArrayType::getAsStringInternal(S, Policy);
+}
+
+void ConstantArrayWithoutExprType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
+ if (Policy.ConstantArraySizeAsWritten) {
+ S += "[]";
+ getElementType().getAsStringInternal(S, Policy);
+ }
+ else
+ ConstantArrayType::getAsStringInternal(S, Policy);
+}
+
void IncompleteArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const {
S += "[]";