[PATCH][ObjC] Cleanup ObjCInterfaceDecl lookup for ObjC literals

AlexDenisov 1101.debian at gmail.com
Thu Jul 23 08:33:54 PDT 2015


> Then, on the Sema side, you should define an enum that corresponds to
> the different cases in that second parameter.

I just reused ObjCLiteralKind, seems it fits for this task very well.

> If you do this, you should be able to unify all the different diagnostics for
> NSNumber/NSArray/NSValue.

Merged all specific errors into one err_undeclared_objc_literal_class, as you suggested.

New version attached.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: lookup_objc_literal_interface_decl.patch
Type: application/octet-stream
Size: 21510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150723/a224a4c3/attachment.obj>
-------------- next part --------------



> On 14 Jul 2015, at 20:53, John McCall <rjmccall at apple.com> wrote:
> 
>> 
>> On Jul 12, 2015, at 12:53 PM, AlexDenisov <1101.debian at gmail.com> wrote:
>> 
>> ObjC literals (NSDictionary, NSArray, Boxed Expressions) use the same
>> code to instantiate ObjCInterfaceDecl of corresponding classes.
>> 
>> The patch extracts duplicated code into one method and unifies
>> validation of the ObjCInterfaceDecl’s.
>> 
>> Also, diagnostic for NSDictionary/NSArray was changed a bit.
>> Before:
>> 
>> @class NSDictionary;
>> // …
>> id dictionary = @{}; // expected-error {{declaration of 'dictionaryWithObjects:forKeys:count:' is missing in NSDictionary class}}
>> 
>> After:
>> 
>> @class NSDictionary; // expected-note {{forward declaration of class here}}
>> // …
>> id dictionary = @{}; // expected-error {{NSDictionary must be available to use Objective-C dictionary literals}}
> 
> Hmm.  This is a lot better, but “available” is still a bit imprecise; it would be better if this were just slightly more explicit:
>  error: definition of class NSDictionary must be available to use Objective-C dictionary literals
> 
> +/// \brief Validates ObjCInterfaceDecl availability.
> +/// ObjCInterfaceDecl, used to create ObjC literals, should be defined
> +/// if clang not in a debugger mode.
> +static bool ValidateObjCLiteralInterfaceDecl(Sema &S, ObjCInterfaceDecl *Decl,
> +                                          SourceLocation Loc, unsigned DiagID) {
> +  if (!Decl) {
> +    S.Diag(Loc, DiagID);
> +    return false;
> +  } else if (!Decl->hasDefinition() && !S.getLangOpts().DebuggerObjCLiteral) {
> +    S.Diag(Loc, DiagID);
> +    S.Diag(Decl->getLocation(), diag::note_forward_class);
> +    return false;
> +  }
> 
> For the benefit of people using non-standard NSAPI classes, please also
> change this diagnostic so that the class name is a parameter.  Something like:
> 
> def err_undeclared_objc_literal_class : Error<
>  “definition of class %0 must be available to use Objective-C “
>  "%select{array|dictionary|…}1 literals">;
> 
> Then, on the Sema side, you should define an enum that corresponds to
> the different cases in that second parameter.
> 
> If you do this, you should be able to unify all the different diagnostics for
> NSNumber/NSArray/NSValue.
> 
> The rest of the patch looks good.
> 
> John.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150723/a224a4c3/attachment.sig>


More information about the cfe-commits mailing list