/// \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
///
/// \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
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));
}
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;
}
M != MEnd; ++M) {
Results.AddResult(Result(M->first,
getMacroUsagePriority(M->first->getName(),
+ PP.getLangOptions(),
TargetTypeIsPointer)));
}
Results.ExitScope();
+typedef signed char BOOL;
+#define YES ((BOOL)1)
+#define NO ((BOOL)0)
+#define bool _Bool
@interface A
- (int)method:(id)param1;
}
@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)