aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaType.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-06-29 00:50:08 +0000
committerChris Lattner <sabre@nondot.org>2008-06-29 00:50:08 +0000
commitc9b346d7b3b24f8bf940735cc812893dfcef1d4b (patch)
tree48baac51e6b3774bdf863f3bac3e9a2caf2d586c /lib/Sema/SemaType.cpp
parent803d08039c5194cf51071ed1d8fbc5b18b3ec38b (diff)
make type attribute processing static instead of methods on Sema.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52881 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaType.cpp')
-rw-r--r--lib/Sema/SemaType.cpp82
1 files changed, 42 insertions, 40 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 8fadd80f8b..4bee2de994 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -169,7 +169,7 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS) {
// See if there are any attributes on the declspec that apply to the type (as
// opposed to the decl).
if (const AttributeList *AL = DS.getAttributes())
- ProcessTypeAttributes(Result, AL);
+ ProcessTypeAttributeList(Result, AL);
// Apply const/volatile/restrict qualifiers to T.
if (unsigned TypeQuals = DS.getTypeQualifiers()) {
@@ -256,11 +256,6 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
// Apply the pointer typequals to the pointer object.
T = Context.getPointerType(T).getQualifiedType(DeclType.Ptr.TypeQuals);
-
- // See if there are any attributes on the pointer that apply to it.
- if (const AttributeList *AL = DeclType.Ptr.AttrList)
- ProcessTypeAttributes(T, AL);
-
break;
case DeclaratorChunk::Reference:
if (const ReferenceType *RT = T->getAsReferenceType()) {
@@ -286,10 +281,6 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
// Handle restrict on references.
if (DeclType.Ref.HasRestrict)
T.addRestrict();
-
- // See if there are any attributes on the pointer that apply to it.
- if (const AttributeList *AL = DeclType.Ref.AttrList)
- ProcessTypeAttributes(T, AL);
break;
case DeclaratorChunk::Array: {
DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
@@ -454,12 +445,16 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
}
break;
}
+
+ // See if there are any attributes on this declarator chunk.
+ if (const AttributeList *AL = DeclType.getAttrs())
+ ProcessTypeAttributeList(T, AL);
}
// If there were any type attributes applied to the decl itself (not the
// type, apply the type attribute to the type!)
if (const AttributeList *Attrs = D.getAttributes())
- ProcessTypeAttributes(T, Attrs);
+ ProcessTypeAttributeList(T, Attrs);
return T;
}
@@ -518,51 +513,58 @@ Sema::TypeResult Sema::ActOnTypeName(Scope *S, Declarator &D) {
return T.getAsOpaquePtr();
}
-void Sema::ProcessTypeAttributes(QualType &Result, const AttributeList *AL) {
- // Scan through and apply attributes to this type where it makes sense. Some
- // attributes (such as __address_space__, __vector_size__, etc) apply to the
- // type, but others can be present in the type specifiers even though they
- // apply to the decl. Here we apply type attributes and ignore the rest.
- for (; AL; AL = AL->getNext()) {
- // If this is an attribute we can handle, do so now, otherwise, add it to
- // the LeftOverAttrs list for rechaining.
- switch (AL->getKind()) {
- default: break;
- case AttributeList::AT_address_space:
- Result = HandleAddressSpaceTypeAttribute(Result, *AL);
- continue;
- }
- }
-}
+
+
+//===----------------------------------------------------------------------===//
+// Type Attribute Processing
+//===----------------------------------------------------------------------===//
/// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the
-/// specified type.
-QualType Sema::HandleAddressSpaceTypeAttribute(QualType Type,
- const AttributeList &Attr) {
+/// specified type. The attribute contains 1 argument, the id of the address
+/// space for the type.
+static void HandleAddressSpaceTypeAttribute(QualType &Type,
+ const AttributeList &Attr, Sema &S){
// If this type is already address space qualified, reject it.
// Clause 6.7.3 - Type qualifiers: "No type shall be qualified by qualifiers
// for two or more different address spaces."
if (Type.getAddressSpace()) {
- Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers);
- return Type;
+ S.Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers);
+ return;
}
// Check the attribute arguments.
if (Attr.getNumArgs() != 1) {
- Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments,
- std::string("1"));
- return Type;
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments,
+ std::string("1"));
+ return;
}
Expr *ASArgExpr = static_cast<Expr *>(Attr.getArg(0));
llvm::APSInt addrSpace(32);
- if (!ASArgExpr->isIntegerConstantExpr(addrSpace, Context)) {
- Diag(Attr.getLoc(), diag::err_attribute_address_space_not_int,
- ASArgExpr->getSourceRange());
- return Type;
+ if (!ASArgExpr->isIntegerConstantExpr(addrSpace, S.Context)) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_address_space_not_int,
+ ASArgExpr->getSourceRange());
+ return;
}
unsigned ASIdx = static_cast<unsigned>(addrSpace.getZExtValue());
- return Context.getASQualType(Type, ASIdx);
+ Type = S.Context.getASQualType(Type, ASIdx);
+}
+
+void Sema::ProcessTypeAttributeList(QualType &Result, const AttributeList *AL) {
+ // Scan through and apply attributes to this type where it makes sense. Some
+ // attributes (such as __address_space__, __vector_size__, etc) apply to the
+ // type, but others can be present in the type specifiers even though they
+ // apply to the decl. Here we apply type attributes and ignore the rest.
+ for (; AL; AL = AL->getNext()) {
+ // If this is an attribute we can handle, do so now, otherwise, add it to
+ // the LeftOverAttrs list for rechaining.
+ switch (AL->getKind()) {
+ default: break;
+ case AttributeList::AT_address_space:
+ HandleAddressSpaceTypeAttribute(Result, *AL, *this);
+ break;
+ }
+ }
}