no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / build / clang-plugin / CustomTypeAnnotation.h
blob453976915aa4c8b4fc50bddbf8527cd10651c486
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"
9 #include "plugin.h"
10 #include "llvm/ADT/BitmaskEnum.h"
12 class CustomTypeAnnotation {
13 enum ReasonKind {
14 RK_None,
15 RK_Direct,
16 RK_ArrayElement,
17 RK_BaseClass,
18 RK_Field,
19 RK_TemplateInherited,
20 RK_Implicit,
22 struct AnnotationReason {
23 QualType Type;
24 ReasonKind Kind;
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;
33 const char *Pretty;
34 ReasonCache Cache;
36 public:
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);
57 private:
58 AnnotationReason directAnnotationReason(QualType T);
59 AnnotationReason tmplArgAnnotationReason(ArrayRef<TemplateArgument> Args);
61 protected:
62 // Flags specifying which properties of the underlying type we want to visit.
63 enum VisitFlags {
64 VISIT_NONE = 0,
65 VISIT_FIELDS = 1,
66 VISIT_TMPL_ARGS = 2,
67 VISIT_BASES = 4,
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 {
80 return "";
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;
92 #endif