From: Chris Lattner Date: Sun, 29 Jun 2008 00:50:08 +0000 (+0000) Subject: make type attribute processing static instead of methods on Sema. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c9b346d7b3b24f8bf940735cc812893dfcef1d4b;p=clang 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 --- diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index cf910d2612..3e687b9659 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -193,7 +193,7 @@ public: // Type Analysis / Processing: SemaType.cpp. // QualType ConvertDeclSpecToType(const DeclSpec &DS); - void ProcessTypeAttributes(QualType &Result, const AttributeList *AL); + void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL); QualType GetTypeForDeclarator(Declarator &D, Scope *S); @@ -305,13 +305,6 @@ private: void ProcessDeclAttributes(Decl *D, const Declarator &PD); void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList); - /// HandleAddressSpaceTypeAttribute - this attribute is only applicable to - /// objects without automatic storage duration. - /// The raw attribute contains 1 argument, the id of the address space - /// for the type. - QualType HandleAddressSpaceTypeAttribute(QualType curType, - const AttributeList &Attr); - void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, bool &IncompleteImpl); 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(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(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; + } + } }