[cfe-commits] r43257 - in /cfe/trunk: Driver/RewriteTest.cpp Lex/Preprocessor.cpp clang.xcodeproj/project.pbxproj include/clang/AST/DeclObjC.h
Steve Naroff
snaroff at apple.com
Tue Oct 23 17:53:00 PDT 2007
On Oct 23, 2007, at 5:41 PM, Chris Lattner wrote:
>> - Add rewrite rule for @class.
>> - Add setter/getter to ObjcClassDecl.
>> - Predefined key runtime functions.
>
> Hey Steve,
>
>> +void RewriteTest::RewriteForwardClassDecl(ObjcClassDecl
>> *ClassDecl) {
>> + int numDecls = ClassDecl->getNumForwardDecls();
>> + ObjcInterfaceDecl **ForwardDecls = ClassDecl->getForwardDecls();
>> +
>> + // Get the start location and compute the semi location.
>> + SourceLocation startLoc = ClassDecl->getLocation();
>> + const char *startBuf = SM->getCharacterData(startLoc);
>> + const char *semiPtr = startBuf;
>> + while (semiPtr && (*semiPtr != ';')) semiPtr++;
>
> This loop looks equivalent to strchr(semiptr, ';'), except that you
> mean "while (*semiptr && ...". Please use strchr if possible.
Sure...
>
>> + // Translate to typedef's that forward reference structs with
>> the same name
>> + // as the class. As a convenience, we include the original
>> declaration
>> + // as a comment.
>> + std::string typedefString;
>> + typedefString += "// ";
>> + typedefString.append(startBuf, semiPtr-startBuf+1);
>> + typedefString += "\n";
>
> Nice!
>
>> =====================================================================
>> =========
>> --- cfe/trunk/Lex/Preprocessor.cpp (original)
>> +++ cfe/trunk/Lex/Preprocessor.cpp Tue Oct 23 15:20:08 2007
>> @@ -392,6 +392,23 @@
>> DefineBuiltinMacro(Buf, "NO=(BOOL)0");
>> DefineBuiltinMacro(Buf, "Nil=0");
>> DefineBuiltinMacro(Buf, "nil=0");
>> + ObjcType = "OBJC_EXPORT const char *sel_getName(SEL sel);\n";
>> + Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
>> + ObjcType = "OBJC_EXPORT SEL sel_getUid(const char *str);\n";
>> + Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
>> +
>> + // Predefine ObjC primitive functions, traditionally declared in
>> + // <objc/objc-runtime.h>. Unlike the declarations above, we
>> don't protect
>> + // these with a header guard (since multiple identical
>> function declarations
>> + // don't result in an error.
>> + ObjcType = "OBJC_EXPORT id objc_getClass(const char *name);\n";
>> + Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
>> + ObjcType = "OBJC_EXPORT id objc_getMetaClass(const char
>> *name);\n";
>> + Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
>> + ObjcType = "OBJC_EXPORT id objc_msgSend(id self, SEL op, ...);
>> \n";
>> + Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
>> + ObjcType = "OBJC_EXPORT id objc_msgSendSuper(struct
>> objc_super *super, SEL op, ...);\n";
>> + Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
>
> This impacts normal objective C code that isn't being
> 'translated'. Are you sure this is the right answer? It seems
> better for the translator itself to inject decls for these
> functions if they don't exist, instead of unconditionally cramming
> them into the preprocessor. Unlike "id", these aren't "part of the
> language".
>
While I agree, this solution is simpler (for now). In practice, I
don't think predefining these functions creates any problems.
I can add a FIXME...
snaroff
> -Chris
>
>
More information about the cfe-commits
mailing list