From 2be05e5c86dff0ffd45e20f580a7e34ab29636a8 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 10 Dec 2013 13:11:20 +0000 Subject: 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. --- clang-plugin/nullability-checker.h | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 clang-plugin/nullability-checker.h (limited to 'clang-plugin/nullability-checker.h') 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 . + * + * Authors: + * Philip Withnall + */ + +#ifndef GNOME_CLANG_NULLABILITY_CHECKER_H +#define GNOME_CLANG_NULLABILITY_CHECKER_H + +#include +#include +#include +#include + +#include "gir-manager.h" + +using namespace clang; + +class NullabilityVisitor : public RecursiveASTVisitor { +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 */ -- cgit v1.2.3