aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ASTContext.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-08-05 05:36:45 +0000
committerDouglas Gregor <dgregor@apple.com>2009-08-05 05:36:45 +0000
commit50d62d1b4a98adbc83de8f8cd1379ea1c25656f7 (patch)
treeacbdf51eb2a3ea3b6b4a7db47c97e97233d83b55 /lib/AST/ASTContext.cpp
parent4ed459851eef142f2059af7ae487484e8a14fc67 (diff)
Introduce the canonical type smart pointers, and use them in a few places to
tighten up the static type system. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78164 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r--lib/AST/ASTContext.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index c4740843e5..ad46bcdca7 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2070,18 +2070,19 @@ QualType ASTContext::getPointerDiffType() const {
/// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
/// to be free of any of these, allowing two canonical types to be compared
/// for exact equality with a simple pointer comparison.
-QualType ASTContext::getCanonicalType(QualType T) {
+CanQualType ASTContext::getCanonicalType(QualType T) {
QualType CanType = T.getTypePtr()->getCanonicalTypeInternal();
// If the result has type qualifiers, make sure to canonicalize them as well.
unsigned TypeQuals = T.getCVRQualifiers() | CanType.getCVRQualifiers();
- if (TypeQuals == 0) return CanType;
+ if (TypeQuals == 0)
+ return CanQualType::CreateUnsafe(CanType);
// If the type qualifiers are on an array type, get the canonical type of the
// array with the qualifiers applied to the element type.
ArrayType *AT = dyn_cast<ArrayType>(CanType);
if (!AT)
- return CanType.getQualifiedType(TypeQuals);
+ return CanQualType::CreateUnsafe(CanType.getQualifiedType(TypeQuals));
// Get the canonical version of the element with the extra qualifiers on it.
// This can recursively sink qualifiers through multiple levels of arrays.
@@ -2089,25 +2090,29 @@ QualType ASTContext::getCanonicalType(QualType T) {
NewEltTy = getCanonicalType(NewEltTy);
if (ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT))
- return getConstantArrayType(NewEltTy, CAT->getSize(),CAT->getSizeModifier(),
- CAT->getIndexTypeQualifier());
+ return CanQualType::CreateUnsafe(
+ getConstantArrayType(NewEltTy, CAT->getSize(),
+ CAT->getSizeModifier(),
+ CAT->getIndexTypeQualifier()));
if (IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT))
- return getIncompleteArrayType(NewEltTy, IAT->getSizeModifier(),
- IAT->getIndexTypeQualifier());
+ return CanQualType::CreateUnsafe(
+ getIncompleteArrayType(NewEltTy, IAT->getSizeModifier(),
+ IAT->getIndexTypeQualifier()));
if (DependentSizedArrayType *DSAT = dyn_cast<DependentSizedArrayType>(AT))
- return getDependentSizedArrayType(NewEltTy,
- DSAT->getSizeExpr(),
- DSAT->getSizeModifier(),
- DSAT->getIndexTypeQualifier(),
- DSAT->getBracketsRange());
+ return CanQualType::CreateUnsafe(
+ getDependentSizedArrayType(NewEltTy,
+ DSAT->getSizeExpr(),
+ DSAT->getSizeModifier(),
+ DSAT->getIndexTypeQualifier(),
+ DSAT->getBracketsRange()));
VariableArrayType *VAT = cast<VariableArrayType>(AT);
- return getVariableArrayType(NewEltTy,
- VAT->getSizeExpr(),
- VAT->getSizeModifier(),
- VAT->getIndexTypeQualifier(),
- VAT->getBracketsRange());
+ return CanQualType::CreateUnsafe(getVariableArrayType(NewEltTy,
+ VAT->getSizeExpr(),
+ VAT->getSizeModifier(),
+ VAT->getIndexTypeQualifier(),
+ VAT->getBracketsRange()));
}
TemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) {
@@ -2250,7 +2255,7 @@ const ArrayType *ASTContext::getAsArrayType(QualType T) {
// If we get here, we either have type qualifiers on the type, or we have
// sugar such as a typedef in the way. If we have type qualifiers on the type
- // we must propagate them down into the elemeng type.
+ // we must propagate them down into the element type.
unsigned CVRQuals = T.getCVRQualifiers();
unsigned AddrSpace = 0;
Type *Ty = T.getTypePtr();