diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-24 03:33:13 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-24 03:33:13 +0000 |
commit | 077bf5e2f48acfa9e7d69429b6e4ba86ea14896d (patch) | |
tree | 55c540d3cfe45fb990f27b56635fcec5865bcc16 /lib/Sema | |
parent | d0fd3b747c46211c481021ffb9cabd5635f918ed (diff) |
Rename Selector::getName() to Selector::getAsString(), and add
a new NamedDecl::getAsString() method.
Change uses of Selector::getName() to just pass in a Selector
where possible (e.g. to diagnostics) instead of going through
an std::string.
This also adds new formatters for objcinstance and objcclass
as described in the dox.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59933 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/Sema.cpp | 17 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 11 | ||||
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 26 |
4 files changed, 34 insertions, 22 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index be21c36073..6b913fb215 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -23,22 +23,33 @@ using namespace clang; /// ConvertQualTypeToStringFn - This function is used to pretty print the /// specified QualType as a string in diagnostics. static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, - const char *Modifier, unsigned ML, + const char *Modifier, unsigned ModLen, const char *Argument, unsigned ArgLen, llvm::SmallVectorImpl<char> &Output) { - assert(ML == 0 && ArgLen == 0 && "Invalid modifier for QualType argument"); std::string S; if (Kind == Diagnostic::ak_qualtype) { QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast<void*>(Val))); - + // FIXME: Playing with std::string is really slow. S = Ty.getAsString(); + + assert(ModLen == 0 && ArgLen == 0 && + "Invalid modifier for QualType argument"); + } else { assert(Kind == Diagnostic::ak_declarationname); DeclarationName N = DeclarationName::getFromOpaqueInteger(Val); S = N.getAsString(); + + if (ModLen == 9 && !memcmp(Modifier, "objcclass", 9) && ArgLen == 0) + S = '+' + S; + else if (ModLen == 12 && !memcmp(Modifier, "objcinstance", 12) && ArgLen==0) + S = '-' + S; + else + assert(ModLen == 0 && ArgLen == 0 && + "Invalid modifier for DeclarationName argument"); } Output.append(S.begin(), S.end()); } diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 410c25486b..de588c58fb 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1317,7 +1317,7 @@ public: /// \param [out] ReturnType - The return type of the send. /// \return true iff there were any incompatible types. bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, - ObjCMethodDecl *Method, const char *PrefixStr, + ObjCMethodDecl *Method, bool isClassMessage, SourceLocation lbrac, SourceLocation rbrac, QualType &ReturnType); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index cc54e890cf..64fd6c515d 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -805,8 +805,7 @@ void Sema::AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method) { if (!match) { // We have a new signature for an existing method - add it. // This is extremely rare. Only 1% of Cocoa selectors are "overloaded". - struct ObjCMethodList *OMI = new ObjCMethodList(Method, FirstMethod.Next); - FirstMethod.Next = OMI; + FirstMethod.Next = new ObjCMethodList(Method, FirstMethod.Next);; } } } @@ -824,7 +823,7 @@ ObjCMethodDecl *Sema::LookupInstanceMethodInGlobalPool(Selector Sel, issueWarning = true; } if (issueWarning && (MethList.Method && MethList.Next)) { - Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel.getName() << R; + Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R; Diag(MethList.Method->getLocStart(), diag::note_using_decl) << MethList.Method->getSourceRange(); for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) @@ -905,7 +904,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, if (isInterfaceDeclKind && PrevMethod && !match || checkIdenticalMethods && match) { Diag(Method->getLocation(), diag::err_duplicate_method_decl) - << Method->getSelector().getName(); + << Method->getDeclName(); Diag(PrevMethod->getLocation(), diag::note_previous_declaration); } else { insMethods.push_back(Method); @@ -922,7 +921,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, if (isInterfaceDeclKind && PrevMethod && !match || checkIdenticalMethods && match) { Diag(Method->getLocation(), diag::err_duplicate_method_decl) - << Method->getSelector().getName(); + << Method->getDeclName(); Diag(PrevMethod->getLocation(), diag::note_previous_declaration); } else { clsMethods.push_back(Method); @@ -1115,7 +1114,7 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration( if (PrevMethod) { // You can never have two method definitions with the same name. Diag(ObjCMethod->getLocation(), diag::err_duplicate_method_decl) - << ObjCMethod->getSelector().getName(); + << ObjCMethod->getDeclName(); Diag(PrevMethod->getLocation(), diag::note_previous_declaration); } return ObjCMethod; diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index f587dd6ae2..2225d6758f 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -109,7 +109,7 @@ Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId, bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, ObjCMethodDecl *Method, - const char *PrefixStr, + bool isClassMessage, SourceLocation lbrac, SourceLocation rbrac, QualType &ReturnType) { if (!Method) { @@ -117,13 +117,15 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, for (unsigned i = 0; i != NumArgs; i++) DefaultArgumentPromotion(Args[i]); - Diag(lbrac, diag::warn_method_not_found) - << PrefixStr << Sel.getName() << SourceRange(lbrac, rbrac); + unsigned DiagID = isClassMessage ? diag::warn_class_method_not_found : + diag::warn_inst_method_not_found; + Diag(lbrac, DiagID) + << Sel << isClassMessage << SourceRange(lbrac, rbrac); ReturnType = Context.getObjCIdType(); return false; - } else { - ReturnType = Method->getResultType(); } + + ReturnType = Method->getResultType(); unsigned NumNamedArgs = Sel.getNumArgs(); assert(NumArgs >= NumNamedArgs && "Too few arguments for selector!"); @@ -261,7 +263,7 @@ Sema::ExprResult Sema::ActOnClassMessage( if (!Method) Method = ClassDecl->lookupInstanceMethod(Sel); - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "+", + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, true, lbrac, rbrac, returnType)) return true; @@ -304,7 +306,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (ObjCInterfaceDecl *SuperDecl = ClassDecl->getSuperClass()) Method = SuperDecl->lookupInstanceMethod(Sel); } - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, @@ -318,7 +320,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, Sel, SourceRange(lbrac,rbrac)); if (!Method) Method = FactoryMethodPool[Sel].Method; - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, @@ -340,7 +342,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (!Method) Method = LookupInstanceMethodInGlobalPool( Sel, SourceRange(lbrac,rbrac)); - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, @@ -361,7 +363,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, } if (!Method) Diag(lbrac, diag::warn_method_not_found_in_protocol) - << "-" << Sel.getName() << RExpr->getSourceRange(); + << Sel << RExpr->getSourceRange(); } else if (const ObjCInterfaceType *OCIReceiver = ReceiverCType->getAsPointerToObjCInterfaceType()) { // We allow sending a message to a pointer to an interface (an object). @@ -383,7 +385,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (!Method && !OCIReceiver->qual_empty()) Diag(lbrac, diag::warn_method_not_found_in_protocol) - << "-" << Sel.getName() << SourceRange(lbrac, rbrac); + << Sel << SourceRange(lbrac, rbrac); } else { Diag(lbrac, diag::error_bad_receiver_type) << RExpr->getType().getAsString() << RExpr->getSourceRange(); @@ -403,7 +405,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, Method = LookupInstanceMethodInGlobalPool( Sel, SourceRange(lbrac,rbrac)); } - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, |