From ecb01e666665efabd2aa76a76f6080e2a78965fa Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 1 Nov 2007 17:18:37 +0000 Subject: [PATCH] Remaining work to collect objective-c's type qualifiers and use them to encode method types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43617 91177308-0d34-0410-b5e6-96231b3b80d8 --- AST/ASTContext.cpp | 23 +++++++++++++++++++++-- Sema/SemaDecl.cpp | 25 +++++++++++++++++++++++++ include/clang/AST/ASTContext.h | 4 ++++ include/clang/AST/Decl.h | 2 ++ include/clang/AST/DeclObjC.h | 1 + test/Sema/method-encoding-2.m | 11 +++++++++++ 6 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 test/Sema/method-encoding-2.m diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp index 37b5300f1d..acba398fb3 100644 --- a/AST/ASTContext.cpp +++ b/AST/ASTContext.cpp @@ -915,7 +915,8 @@ int ASTContext::getObjcEncodingTypeSize(QualType type) { void ASTContext::getObjcEncodingForMethodDecl(ObjcMethodDecl *Decl, std::string& S) { - // TODO: First encode type qualifer, 'in', 'inout', etc. for the return type. + // Encode type qualifer, 'in', 'inout', etc. for the return type. + getObjcEncodingForTypeQualifier(Decl->getObjcDeclQualifier(), S); // Encode result type. getObjcEncodingForType(Decl->getResultType(), S); // Compute size of all parameters. @@ -941,8 +942,10 @@ void ASTContext::getObjcEncodingForMethodDecl(ObjcMethodDecl *Decl, ParmOffset = 2 * PtrSize; for (int i = 0; i < NumOfParams; i++) { QualType PType = Decl->getParamDecl(i)->getType(); - // TODO: Process argument qualifiers for user supplied arguments; such as, + // Process argument qualifiers for user supplied arguments; such as, // 'in', 'inout', etc. + getObjcEncodingForTypeQualifier( + Decl->getParamDecl(i)->getObjcDeclQualifier(), S); getObjcEncodingForType(PType, S); S += llvm::utostr(ParmOffset); ParmOffset += getObjcEncodingTypeSize(PType); @@ -1054,6 +1057,22 @@ void ASTContext::getObjcEncodingForType(QualType T, std::string& S) const assert(0 && "@encode for type not implemented!"); } +void ASTContext::getObjcEncodingForTypeQualifier(Decl::ObjcDeclQualifier QT, + std::string& S) const { + if (QT & Decl::OBJC_TQ_In) + S += 'n'; + if (QT & Decl::OBJC_TQ_Inout) + S += 'N'; + if (QT & Decl::OBJC_TQ_Out) + S += 'o'; + if (QT & Decl::OBJC_TQ_Bycopy) + S += 'O'; + if (QT & Decl::OBJC_TQ_Byref) + S += 'R'; + if (QT & Decl::OBJC_TQ_Oneway) + S += 'V'; +} + void ASTContext::setBuiltinVaListType(QualType T) { assert(BuiltinVaListType.isNull() && "__builtin_va_list type already set!"); diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index ee5327f0cd..437ec30930 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1968,6 +1968,27 @@ void Sema::ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *classDecl, } } +/// CvtQTToAstBitMask - utility routine to produce an AST bitmask for +/// objective-c's type qualifier from the parser version of the same info. +static Decl::ObjcDeclQualifier +CvtQTToAstBitMask(ObjcDeclSpec::ObjcDeclQualifier PQTVal) { + Decl::ObjcDeclQualifier ret = Decl::OBJC_TQ_None; + if (PQTVal & ObjcDeclSpec::DQ_In) + ret = (Decl::ObjcDeclQualifier)(ret | Decl::OBJC_TQ_In); + if (PQTVal & ObjcDeclSpec::DQ_Inout) + ret = (Decl::ObjcDeclQualifier)(ret | Decl::OBJC_TQ_Inout); + if (PQTVal & ObjcDeclSpec::DQ_Out) + ret = (Decl::ObjcDeclQualifier)(ret | Decl::OBJC_TQ_Out); + if (PQTVal & ObjcDeclSpec::DQ_Bycopy) + ret = (Decl::ObjcDeclQualifier)(ret | Decl::OBJC_TQ_Bycopy); + if (PQTVal & ObjcDeclSpec::DQ_Byref) + ret = (Decl::ObjcDeclQualifier)(ret | Decl::OBJC_TQ_Byref); + if (PQTVal & ObjcDeclSpec::DQ_Oneway) + ret = (Decl::ObjcDeclQualifier)(ret | Decl::OBJC_TQ_Oneway); + + return ret; +} + Sema::DeclTy *Sema::ActOnMethodDeclaration( SourceLocation MethodLoc, SourceLocation EndLoc, tok::TokenKind MethodType, ObjcDeclSpec &ReturnQT, TypeTy *ReturnType, @@ -1988,6 +2009,8 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration( argType = Context.getObjcIdType(); ParmVarDecl* Param = new ParmVarDecl(SourceLocation(/*FIXME*/), ArgNames[i], argType, VarDecl::None, 0); + Param->setObjcDeclQualifier( + CvtQTToAstBitMask(ArgQT[i].getObjcDeclQualifier())); Params.push_back(Param); } QualType resultDeclType; @@ -2004,6 +2027,8 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration( ObjcMethodDecl::Optional : ObjcMethodDecl::Required); ObjcMethod->setMethodParams(&Params[0], Sel.getNumArgs()); + ObjcMethod->setObjcDeclQualifier( + CvtQTToAstBitMask(ReturnQT.getObjcDeclQualifier())); return ObjcMethod; } diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index f4c5d02988..d8dc9d4992 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -185,6 +185,10 @@ public: // Return the ObjC type encoding for a given type. void getObjcEncodingForType(QualType t, std::string &S) const; + // Put the string version of type qualifiers into S. + void getObjcEncodingForTypeQualifier(Decl::ObjcDeclQualifier QT, + std::string &S) const; + /// getObjcEncodingForMethodDecl - Return the encoded type for this method /// declaration. void getObjcEncodingForMethodDecl(ObjcMethodDecl *Decl, std::string &S); diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 10d4c06cd4..2e72e74fc1 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -294,6 +294,8 @@ public: bool hasGlobalStorage() const { return !hasAutoStorage(); } ObjcDeclQualifier getObjcDeclQualifier() const { return objcDeclQualifier; } + void setObjcDeclQualifier(ObjcDeclQualifier QTVal) + { objcDeclQualifier = QTVal; } // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index dcff5ea36e..8c8a1a4ecb 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -253,6 +253,7 @@ public: virtual ~ObjcMethodDecl(); ObjcDeclQualifier getObjcDeclQualifier() const { return objcDeclQualifier; } + void setObjcDeclQualifier(ObjcDeclQualifier QV) { objcDeclQualifier = QV; } // Location information, modeled after the Stmt API. SourceLocation getLocStart() const { return getLocation(); } diff --git a/test/Sema/method-encoding-2.m b/test/Sema/method-encoding-2.m new file mode 100644 index 0000000000..b7a5e733da --- /dev/null +++ b/test/Sema/method-encoding-2.m @@ -0,0 +1,11 @@ +// RUN: clang -rewrite-test %s + +@interface Intf +- (in out bycopy id) address:(byref inout void *)location with:(out oneway unsigned **)arg2; +- (id) another:(void *)location with:(unsigned **)arg2; +@end + +@implementation Intf +- (in out bycopy id) address:(byref inout void *)location with:(out oneway unsigned **)arg2{} +- (id) another:(void *)location with:(unsigned **)arg2 {} +@end -- 2.40.0