[cfe-commits] r43617 - in /cfe/trunk: AST/ASTContext.cpp Sema/SemaDecl.cpp include/clang/AST/ASTContext.h include/clang/AST/Decl.h include/clang/AST/DeclObjC.h test/Sema/method-encoding-2.m
Fariborz Jahanian
fjahanian at apple.com
Thu Nov 1 10:18:41 PDT 2007
Author: fjahanian
Date: Thu Nov 1 12:18:37 2007
New Revision: 43617
URL: http://llvm.org/viewvc/llvm-project?rev=43617&view=rev
Log:
Remaining work to collect objective-c's type qualifiers and use them to encode
method types.
Added:
cfe/trunk/test/Sema/method-encoding-2.m
Modified:
cfe/trunk/AST/ASTContext.cpp
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclObjC.h
Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=43617&r1=43616&r2=43617&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Thu Nov 1 12:18:37 2007
@@ -915,7 +915,8 @@
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 @@
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 @@
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!");
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=43617&r1=43616&r2=43617&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Thu Nov 1 12:18:37 2007
@@ -1968,6 +1968,27 @@
}
}
+/// 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 @@
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 @@
ObjcMethodDecl::Optional :
ObjcMethodDecl::Required);
ObjcMethod->setMethodParams(&Params[0], Sel.getNumArgs());
+ ObjcMethod->setObjcDeclQualifier(
+ CvtQTToAstBitMask(ReturnQT.getObjcDeclQualifier()));
return ObjcMethod;
}
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=43617&r1=43616&r2=43617&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Nov 1 12:18:37 2007
@@ -185,6 +185,10 @@
// 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);
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=43617&r1=43616&r2=43617&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Nov 1 12:18:37 2007
@@ -294,6 +294,8 @@
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) {
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=43617&r1=43616&r2=43617&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Nov 1 12:18:37 2007
@@ -253,6 +253,7 @@
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(); }
Added: cfe/trunk/test/Sema/method-encoding-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/method-encoding-2.m?rev=43617&view=auto
==============================================================================
--- cfe/trunk/test/Sema/method-encoding-2.m (added)
+++ cfe/trunk/test/Sema/method-encoding-2.m Thu Nov 1 12:18:37 2007
@@ -0,0 +1,11 @@
+// RUN: clang -rewrite-test %s
+
+ at interface Intf
+- (in out bycopy id) address:(byref inout void *)location with:(out oneway unsigned **)arg2;
+- (id) another:(void *)location with:(unsigned **)arg2;
+ at end
+
+ at implementation Intf
+- (in out bycopy id) address:(byref inout void *)location with:(out oneway unsigned **)arg2{}
+- (id) another:(void *)location with:(unsigned **)arg2 {}
+ at end
More information about the cfe-commits
mailing list