File indexing completed on 2024-05-12 04:37:43

0001 /*
0002     SPDX-FileCopyrightText: 2010 Aleix Pol Gonzalez <aleixpol@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef KDEVPLATFORM_DATAACCESS_H
0008 #define KDEVPLATFORM_DATAACCESS_H
0009 
0010 #include <language/languageexport.h>
0011 #include <language/editor/rangeinrevision.h>
0012 
0013 namespace KDevelop {
0014 class Declaration;
0015 
0016 /**
0017  * @brief Represents a data access in some code
0018  *
0019  * This class provides the position of a data access in the code
0020  * and tells us whether it's writing or reading the data.
0021  */
0022 class KDEVPLATFORMLANGUAGE_EXPORT DataAccess
0023 {
0024 public:
0025     /** Defines the flags that will tell what this data access is about */
0026     enum DataAccessFlag {
0027         None = 0,
0028         Read = 1,     /**< This data access reads data */
0029         Write = 2,    /**< This data access writes data */
0030         Call = 4      /**< This call is modifying some outsider data*/
0031     };
0032     Q_DECLARE_FLAGS(DataAccessFlags, DataAccessFlag)
0033 
0034     /** Constructs a DataAccess instance with its @p cur position and
0035      * its @p flags DataAccessFlags that will tell us how is it modifying the data.
0036      * In case it's a Write, a @p range can be provided
0037      */
0038     DataAccess(const CursorInRevision& cur, DataAccessFlags flags, const KDevelop::RangeInRevision& range);
0039 
0040     /** Checks the flags and returns if it's reading the data */
0041     bool isRead()  const;
0042 
0043     /** Checks the flags and returns if it's writing the data */
0044     bool isWrite() const;
0045 
0046     /** Checks the flags and returns if it's just some call */
0047     bool isCall() const;
0048 
0049     /** @returns the cursor */
0050     KDevelop::CursorInRevision pos() const;
0051 
0052     /** @returns the flags that specify how is this access interacting with the data */
0053     DataAccessFlags flags() const;
0054 
0055     /** @returns the range that contains the written value in case it's a Write access */
0056     KDevelop::RangeInRevision value() const;
0057 
0058 private:
0059     DataAccessFlags m_flags;
0060     KDevelop::CursorInRevision m_pos;
0061     KDevelop::RangeInRevision m_value;
0062 };
0063 }
0064 
0065 #endif