/*
 * Copyright Likewise Software
 * All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the license, or (at
 * your option) any later version.
 *
 * This library 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 Lesser
 * General Public License for more details.  You should have received a copy
 * of the GNU Lesser General Public License along with this program.  If
 * not, see <http://www.gnu.org/licenses/>.
 *
 * LIKEWISE SOFTWARE MAKES THIS SOFTWARE AVAILABLE UNDER OTHER LICENSING
 * TERMS AS WELL.  IF YOU HAVE ENTERED INTO A SEPARATE LICENSE AGREEMENT
 * WITH LIKEWISE SOFTWARE, THEN YOU MAY ELECT TO USE THE SOFTWARE UNDER THE
 * TERMS OF THAT SOFTWARE LICENSE AGREEMENT INSTEAD OF THE TERMS OF THE GNU
 * LESSER GENERAL PUBLIC LICENSE, NOTWITHSTANDING THE ABOVE NOTICE.  IF YOU
 * HAVE QUESTIONS, OR WISH TO REQUEST A COPY OF THE ALTERNATE LICENSING
 * TERMS OFFERED BY LIKEWISE SOFTWARE, PLEASE CONTACT LIKEWISE SOFTWARE AT
 * license@likewisesoftware.com
 */

/*
 * Copyright (C) Likewise Software. All rights reserved.
 *
 * Module Name:
 *
 *        invariant.h
 *
 * Abstract:
 *
 *        Macros for code invariants
 *
 * Authors
 *
 *        Brian Koropoff (bkoropoff@likewise.com)
 */

#ifndef __LW_INVARIANT_H__
#define __LW_INVARIANT_H__

#include <lw/assert.h>

/**
 * @file lw/invariant.h
 * @brief Code invariant macros
 */

/**
 * @defgroup invariant Code invariants
 * @brief Code invariant macros
 *
 * This module contains macros for denoting invariants and other
 * hints for static analysis within code.  These macros will only
 * be active when @a LW_STATIC_ANALYSIS is defined during building.
 */

/*@{*/

#if defined (LW_STATIC_ANALYSIS)
#define LW_SA_INVARIANT(Expr) LW_RTL_ASSERT(Expr)
#define LW_SA_IGNORE(Var) __LwSaConsume((void*) &(Var))
static inline void __LwSaConsume(void*a) { return; }
#else
/**
 * @brief Indicate static analysis invariant
 *
 * Asserts that @a Expr is true for the purpose of static analysis.
 * This will help static analysis tools trim impossible data flow paths,
 * reducing spurious warnings.
 *
 * @param[in] Expr the expression to evaluate
 */
#define LW_SA_INVARIANT(Expr)
/**
 * @brief Indicate unused value
 *
 * Indicates that the last value assigned to @a Var is unused on purpose,
 * silencing certain static analysis warnings.
 *
 * @param[in] Var the variable
 */
#define LW_SA_IGNORE(Var)
#endif

/*@}*/

#endif /* __LW_INVARIANT_H__ */
