1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef CustomTypeAnnotation_h__
6 #define CustomTypeAnnotation_h__
8 #include "CustomAttributes.h"
10 #include "llvm/ADT/BitmaskEnum.h"
12 class CustomTypeAnnotation
{
22 struct AnnotationReason
{
25 const FieldDecl
*Field
;
26 std::string ImplicitReason
;
28 bool valid() const { return Kind
!= RK_None
; }
30 typedef DenseMap
<void *, AnnotationReason
> ReasonCache
;
32 CustomAttributes Attribute
;
37 CustomTypeAnnotation(CustomAttributes Attribute
, const char *Pretty
)
38 : Attribute(Attribute
), Pretty(Pretty
){};
40 virtual ~CustomTypeAnnotation() {}
42 // Checks if this custom annotation "effectively affects" the given type.
43 bool hasEffectiveAnnotation(QualType T
) {
44 return directAnnotationReason(T
).valid();
46 void dumpAnnotationReason(BaseCheck
&Check
, QualType T
, SourceLocation Loc
);
48 void reportErrorIfPresent(BaseCheck
&Check
, QualType T
, SourceLocation Loc
,
49 const char *Error
, const char *Note
) {
50 if (hasEffectiveAnnotation(T
)) {
51 Check
.diag(Loc
, Error
, DiagnosticIDs::Error
) << T
;
52 Check
.diag(Loc
, Note
, DiagnosticIDs::Note
);
53 dumpAnnotationReason(Check
, T
, Loc
);
58 AnnotationReason
directAnnotationReason(QualType T
);
59 AnnotationReason
tmplArgAnnotationReason(ArrayRef
<TemplateArgument
> Args
);
62 // Flags specifying which properties of the underlying type we want to visit.
68 LLVM_MARK_AS_BITMASK_ENUM(VISIT_BASES
)
71 // Allow subclasses to apply annotations for reasons other than a direct
72 // annotation. A non-empty string return value means that the object D is
73 // annotated, and should contain the reason why.
75 // The subclass may also modify `VisitFlags` to change what properties of the
76 // type will be inspected to skip inspecting fields, force template arguments
77 // to be inspected, etc.
78 virtual std::string
getImplicitReason(const TagDecl
*D
,
79 VisitFlags
&Flags
) const {
84 extern CustomTypeAnnotation StackClass
;
85 extern CustomTypeAnnotation GlobalClass
;
86 extern CustomTypeAnnotation NonHeapClass
;
87 extern CustomTypeAnnotation HeapClass
;
88 extern CustomTypeAnnotation NonTemporaryClass
;
89 extern CustomTypeAnnotation TemporaryClass
;
90 extern CustomTypeAnnotation StaticLocalClass
;