[cfe-dev] Objective-C @defs support
David Chisnall
csdavec at swansea.ac.uk
Sat Jun 21 12:31:40 PDT 2008
On 21 Jun 2008, at 19:24, Chris Lattner wrote:
> On Jun 18, 2008, at 7:28 AM, David Chisnall wrote:
>> This patch adds parsing and code generation support for @defs
>> directives (which allow you to create a C structure with the same
>> layout as an Objective-C object).
>
> The patch looks great, some minor issues:
>
> +++ lib/Parse/ParseDecl.cpp (working copy)
>
> Please update the grammar to indicate the changes you're making to
> the parser.
Done.
> @@ -736,18 +736,33 @@
> + if(!Tok.is(tok::at)) {
>
> Space after the 'if' please.
Done.
> + ConsumeToken();
>
> Not ok. This consumes the token after the @ even though you don't
> know what it is. If it is <eof>, you're hosed :). You need to
> think of a recovery strategy here, what should happen if an "@" is
> seen without defs after it?
Fixed
> + if (!Tok.is(tok::l_paren)) Diag(Tok,
> diag::err_expected_lparen);
> + ConsumeParen();
>
> Likewise, and below. Also, please use ExpectAndConsume where
> possible.
>
> + llvm::SmallVector<DeclTy*, 16> Fields;
> + Actions.ActOnDefs(CurScope, Tok.getLocation(),
> Tok.getIdentifierInfo(),
> + Fields);
> + FieldDecls.insert(FieldDecls.end(), Fields.begin(),
> Fields.end());
> + ConsumeToken();
> + if (!Tok.is(tok::r_paren)) Diag(Tok,
> diag::err_expected_rparen);
> + ConsumeParen();
> + }
Done. Lots of errors happen now with nonsense input.
> +++ lib/Sema/SemaDecl.cpp (working copy)
>
> +static void CollectIvars(ObjCInterfaceDecl *Class,
> + llvm::SmallVector<Sema::DeclTy*, 16> &ivars) {
> + if(Class->getSuperClass()) {
> + CollectIvars(Class->getSuperClass(), ivars);
> + }
> + for (ObjCInterfaceDecl::ivar_iterator iter=Class->ivar_begin() ;
> + iter!=Class->ivar_end() ; iter++) {
> + ivars.push_back(*iter);
> + }
>
> Can this be: ivars.append(Class->ivar_begin(), Class->ivar_end())?
Yes - it was a loop so I could dump the ivar names as they were found
and check they were in the right order.
> +}
> +
> +void Sema::ActOnDefs(Scope *S, SourceLocation DeclStart,
> IdentifierInfo
> + *ClassName, llvm::SmallVector<DeclTy*, 16> &Decls) {
> + ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName);
> + if (!Class) Diag(DeclStart, diag::err_undef_interface, ClassName-
> >getName());
> + CollectIvars(Class, Decls);
> +}
> +
>
> comments please!
Added.
> +++ lib/CodeGen/CodeGenTypes.cpp (working copy)
> @@ -149,7 +149,7 @@
>
> What is this patch doing? It seems unrelated.
Hmm, in fact it might be. Ignore it for now (or commit it
separately). It's just a few cleanups of the CodeGenTypes stuff.
defs.m is the file I am using to test this. It outputs two lines in
the form %d: %d. If both numbers on each line match then it worked.
Compile with ccc defs.m -lobjc. Advice on how to turn this into an
automated clang test welcome...
David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: defs.diff
Type: application/octet-stream
Size: 6361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080621/ed6b5312/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: defs.m
Type: application/octet-stream
Size: 433 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080621/ed6b5312/attachment-0001.obj>
More information about the cfe-dev
mailing list