forked from OSchip/llvm-project
Tweak priorities for some types and macros:
- In Objective-C, we prefer BOOL to bool for historic reasons; slightly penalize "bool". - Treat Nil macro as a NULL pointer constant. - Treat YES, NO, true, and false macros as constants. - Treat the bool macro as a type. llvm-svn: 114356
This commit is contained in:
parent
5e4734245d
commit
9dcf58a546
|
@ -81,7 +81,11 @@ enum {
|
|||
/// \brief The selector of the given message exactly matches the selector
|
||||
/// of the current method, which might imply that some kind of delegation
|
||||
/// is occurring.
|
||||
CCD_SelectorMatch = -3
|
||||
CCD_SelectorMatch = -3,
|
||||
|
||||
/// \brief Adjustment to the "bool" type in Objective-C, where the typedef
|
||||
/// "BOOL" is preferred.
|
||||
CCD_bool_in_ObjC = 1
|
||||
};
|
||||
|
||||
/// \brief Priority value factors by which we will divide or multiply the
|
||||
|
@ -122,9 +126,12 @@ QualType getDeclUsageType(ASTContext &C, NamedDecl *ND);
|
|||
///
|
||||
/// \param MacroName The name of the macro.
|
||||
///
|
||||
/// \param LangOpts Options describing the current language dialect.
|
||||
///
|
||||
/// \param PreferredTypeIsPointer Whether the preferred type for the context
|
||||
/// of this macro is a pointer type.
|
||||
unsigned getMacroUsagePriority(llvm::StringRef MacroName,
|
||||
const LangOptions &LangOpts,
|
||||
bool PreferredTypeIsPointer = false);
|
||||
|
||||
/// \brief Determine the libclang cursor kind associated with the given
|
||||
|
|
|
@ -1666,6 +1666,7 @@ void AugmentedCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &S,
|
|||
if (!Context.getPreferredType().isNull()) {
|
||||
if (C->Kind == CXCursor_MacroDefinition) {
|
||||
Priority = getMacroUsagePriority(C->Completion->getTypedText(),
|
||||
S.getLangOptions(),
|
||||
Context.getPreferredType()->isAnyPointerType());
|
||||
} else if (C->Type) {
|
||||
CanQualType Expected
|
||||
|
|
|
@ -1087,7 +1087,8 @@ static void AddTypeSpecifierResults(const LangOptions &LangOpts,
|
|||
|
||||
if (LangOpts.CPlusPlus) {
|
||||
// C++-specific
|
||||
Results.AddResult(Result("bool", CCP_Type));
|
||||
Results.AddResult(Result("bool", CCP_Type +
|
||||
(LangOpts.ObjC1? CCD_bool_in_ObjC : 0)));
|
||||
Results.AddResult(Result("class", CCP_Type));
|
||||
Results.AddResult(Result("wchar_t", CCP_Type));
|
||||
|
||||
|
@ -2308,15 +2309,25 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
|
|||
}
|
||||
|
||||
unsigned clang::getMacroUsagePriority(llvm::StringRef MacroName,
|
||||
const LangOptions &LangOpts,
|
||||
bool PreferredTypeIsPointer) {
|
||||
unsigned Priority = CCP_Macro;
|
||||
|
||||
// Treat the "nil" and "NULL" macros as null pointer constants.
|
||||
if (MacroName.equals("nil") || MacroName.equals("NULL")) {
|
||||
// Treat the "nil", "Nil" and "NULL" macros as null pointer constants.
|
||||
if (MacroName.equals("nil") || MacroName.equals("NULL") ||
|
||||
MacroName.equals("Nil")) {
|
||||
Priority = CCP_Constant;
|
||||
if (PreferredTypeIsPointer)
|
||||
Priority = Priority / CCF_SimilarTypeMatch;
|
||||
}
|
||||
}
|
||||
// Treat "YES", "NO", "true", and "false" as constants.
|
||||
else if (MacroName.equals("YES") || MacroName.equals("NO") ||
|
||||
MacroName.equals("true") || MacroName.equals("false"))
|
||||
Priority = CCP_Constant;
|
||||
// Treat "bool" as a type.
|
||||
else if (MacroName.equals("bool"))
|
||||
Priority = CCP_Type + (LangOpts.ObjC1? CCD_bool_in_ObjC : 0);
|
||||
|
||||
|
||||
return Priority;
|
||||
}
|
||||
|
@ -2394,6 +2405,7 @@ static void AddMacroResults(Preprocessor &PP, ResultBuilder &Results,
|
|||
M != MEnd; ++M) {
|
||||
Results.AddResult(Result(M->first,
|
||||
getMacroUsagePriority(M->first->getName(),
|
||||
PP.getLangOptions(),
|
||||
TargetTypeIsPointer)));
|
||||
}
|
||||
Results.ExitScope();
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
typedef signed char BOOL;
|
||||
#define YES ((BOOL)1)
|
||||
#define NO ((BOOL)0)
|
||||
#define bool _Bool
|
||||
@interface A
|
||||
- (int)method:(id)param1;
|
||||
|
||||
|
@ -10,6 +14,10 @@
|
|||
}
|
||||
@end
|
||||
|
||||
// RUN: c-index-test -code-completion-at=%s:9:2 %s | FileCheck -check-prefix=CHECK-CC1 %s
|
||||
// RUN: c-index-test -code-completion-at=%s:13:2 %s | FileCheck -check-prefix=CHECK-CC1 %s
|
||||
// CHECK-CC1: NotImplemented:{ResultType SEL}{TypedText _cmd} (80)
|
||||
// CHECK-CC1: TypedefDecl:{TypedText BOOL} (60)
|
||||
// CHECK-CC1: macro definition:{TypedText bool} (61)
|
||||
// CHECK-CC1: macro definition:{TypedText NO} (65)
|
||||
// CHECK-CC1: NotImplemented:{ResultType A *}{TypedText self} (8)
|
||||
// CHECK-CC1: macro definition:{TypedText YES} (65)
|
||||
|
|
Loading…
Reference in New Issue