File indexing completed on 2024-05-12 04:37:43
0001 /* 0002 SPDX-FileCopyrightText: 2010-2011 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #ifndef KDEVPLATFORM_CONTROLFLOWNODE_H 0008 #define KDEVPLATFORM_CONTROLFLOWNODE_H 0009 #include <language/editor/rangeinrevision.h> 0010 #include <language/languageexport.h> 0011 0012 namespace KDevelop { 0013 /** @brief Class that represents a node in the control flow graph 0014 0015 This class will provide us the information to know how to navigate in a ControlFlowGraph. 0016 It has two methods (next and alternative) that will tell us what are the next nodes and 0017 nodeRange and conditionRange that will tell us the code ranges that this nodes is located at. 0018 */ 0019 class KDEVPLATFORMLANGUAGE_EXPORT ControlFlowNode 0020 { 0021 public: 0022 /** Defines the type of the node in terms of what's on the next and alternative method */ 0023 enum Type { 0024 Conditional, /**< It's a conditional node. alternative and next are available, also conditionRange returns a valid range. */ 0025 Sequential, /**< It's a node where we just have a next node, we always know where it's going to go as a next step. */ 0026 Exit /**< It's the end node, it will either return to the caller or finish execution depending on the context. */ 0027 }; 0028 0029 /** Constructs an empty node with no next or alternative nodes */ 0030 ControlFlowNode(); 0031 0032 /** @returns the node type by checking the node's next and alternative value */ 0033 Type type() const; 0034 0035 /** Sets where is this range going to start to @p cursor*/ 0036 void setStartCursor(const CursorInRevision& cursor); 0037 0038 /** Sets where is this range going to end to @p cursor*/ 0039 void setEndCursor(const CursorInRevision& cursor); 0040 0041 /** Sets the condition range to @p range */ 0042 void setConditionRange(const KDevelop::RangeInRevision& range); 0043 0044 /** Sets @p next to be the node that will be executed after this one */ 0045 void setNext(ControlFlowNode* next); 0046 0047 /** Sets @p alt to be the alternative to next. Converts this node into a conditional node */ 0048 void setAlternative(ControlFlowNode* alt); 0049 0050 /** @returns the node to be executed next */ 0051 ControlFlowNode* next() const; 0052 0053 /** @returns the node to be executed next alternatively */ 0054 ControlFlowNode* alternative() const; 0055 0056 /** @returns the node range as in what range area does the node affect. */ 0057 KDevelop::RangeInRevision nodeRange() const; 0058 0059 /** @returns the node range as in what range does its condition affect. */ 0060 KDevelop::RangeInRevision conditionRange() const; 0061 0062 private: 0063 KDevelop::RangeInRevision m_nodeRange; 0064 KDevelop::RangeInRevision m_conditionRange; 0065 0066 ControlFlowNode* m_next = nullptr; 0067 ControlFlowNode* m_alternative = nullptr; 0068 }; 0069 } 0070 #endif // KDEVPLATFORM_FLUXNODE_H