summaryrefslogtreecommitdiff
path: root/clang-plugin/nullability-checker.h
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2013-12-10 13:11:20 +0000
committerPhilip Withnall <philip.withnall@collabora.co.uk>2013-12-10 13:11:20 +0000
commit2be05e5c86dff0ffd45e20f580a7e34ab29636a8 (patch)
treed21697350d705668ce7cc901bdd97c7672f5b1a0 /clang-plugin/nullability-checker.h
parentdedfa41b70c3d225ea8cdfedc05796eb2ea8f2d3 (diff)
clang-plugin: Add a nullability checker for function parameters
This checks that the three sources of nullability information for function parameters (nonnull attributes, (allow-none) annotations and precondition assertions) agree on whether each parameter should be non-NULL. It emits errors if any conflict, and warnings if the nullability of a parameter is ambiguous.
Diffstat (limited to 'clang-plugin/nullability-checker.h')
-rw-r--r--clang-plugin/nullability-checker.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/clang-plugin/nullability-checker.h b/clang-plugin/nullability-checker.h
new file mode 100644
index 0000000..c254089
--- /dev/null
+++ b/clang-plugin/nullability-checker.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * gnome-clang
+ * Copyright © 2013 Collabora Ltd.
+ *
+ * gnome-clang is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * gnome-clang is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gnome-clang. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Philip Withnall <philip.withnall@collabora.co.uk>
+ */
+
+#ifndef GNOME_CLANG_NULLABILITY_CHECKER_H
+#define GNOME_CLANG_NULLABILITY_CHECKER_H
+
+#include <clang/AST/AST.h>
+#include <clang/AST/ASTConsumer.h>
+#include <clang/AST/RecursiveASTVisitor.h>
+#include <clang/Frontend/CompilerInstance.h>
+
+#include "gir-manager.h"
+
+using namespace clang;
+
+class NullabilityVisitor : public RecursiveASTVisitor<NullabilityVisitor> {
+public:
+ explicit NullabilityVisitor (CompilerInstance& compiler,
+ const GirManager& gir_manager) :
+ _compiler (compiler), _context (compiler.getASTContext ()),
+ _gir_manager (gir_manager) {}
+
+private:
+ CompilerInstance& _compiler;
+ const ASTContext& _context;
+ const GirManager& _gir_manager;
+
+public:
+ bool TraverseFunctionDecl (FunctionDecl* func);
+};
+
+class NullabilityConsumer : public ASTConsumer {
+public:
+ NullabilityConsumer (CompilerInstance& compiler,
+ const GirManager& gir_manager) :
+ _visitor (compiler, gir_manager) {}
+
+private:
+ NullabilityVisitor _visitor;
+
+public:
+ virtual void HandleTranslationUnit (ASTContext& context);
+};
+
+#endif /* !GNOME_CLANG_NULLABILITY_CHECKER_H */