> 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.
lookup_objc_literal_interface_decl.patch
Description: Binary data
> On 14 Jul 2015, at 20:53, John McCall <rjmcc...@apple.com> wrote: > >> >> On Jul 12, 2015, at 12:53 PM, AlexDenisov <1101.deb...@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.
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits