GTIRB  v2.1.0
GrammaTech Intermediate Representation for Binaries: C++ API
Node.hpp
Go to the documentation of this file.
1 //===- Node.hpp -------------------------------------------------*- C++ -*-===//
2 //
3 // Copyright (C) 2020 GrammaTech, Inc.
4 //
5 // This code is licensed under the MIT license. See the LICENSE file in the
6 // project root for license terms.
7 //
8 // This project is sponsored by the Office of Naval Research, One Liberty
9 // Center, 875 N. Randolph Street, Arlington, VA 22203 under contract #
10 // N68335-17-C-0700. The content of the information does not necessarily
11 // reflect the position or policy of the Government and no official
12 // endorsement should be inferred.
13 //
14 //===----------------------------------------------------------------------===//
15 #ifndef GTIRB_NODE_H
16 #define GTIRB_NODE_H
17 
18 #include <gtirb/Casting.hpp>
19 #include <gtirb/Context.hpp>
20 #include <gtirb/Export.hpp>
21 #include <functional>
22 #include <string>
23 
26 
27 namespace gtirb {
28 class Node;
29 
40 public:
42 
43  // The enum constants below must be grouped according to the inheritance
44  // hierarchy such that all descendants of a type X must appear between the
45  // constant for X and LAST_X. This allows us to quickly check whether a type
46  // is a descendant of X by checking if the enum constant falls in that range.
47  enum class Kind {
48  Node,
49  CfgNode,
50  CodeBlock,
51  ProxyBlock,
52  LAST_CfgNode = ProxyBlock, // Mark last descendant of CfgNode
53  DataBlock,
54  IR,
55  Module,
56  Section,
57  Symbol,
59  LAST_Node = ByteInterval, // Mark last descendant of Node
60  };
62 
66  static Node* getByUUID(Context& C, const UUID& Uuid) {
67  return C.findNode(Uuid);
68  }
69 
73  static const Node* getByUUID(const Context& C, const UUID& Uuid) {
74  return C.findNode(Uuid);
75  }
76 
82  static Node* Create(Context& C) { return C.Create<Node>(C, Kind::Node); }
83 
85  Node(const Node&) = delete;
86 
88  Node(Node&&) = delete;
89 
91  ~Node() noexcept;
92 
94  Node& operator=(const Node&) = delete;
95 
97  Node& operator=(Node&&) = delete;
98 
102  const UUID& getUUID() const { return Uuid; }
103 
105  Kind getKind() const { return K; }
107 
109  static bool classof(const Node* N) { return classofKind(N->getKind()); }
110  static bool classofKind(Kind K) {
111  return K >= Kind::Node && K <= Kind::LAST_Node;
112  }
114 
115 protected:
117  Node(Context& C, Kind Knd);
118  Node(Context& C, Kind Knd, const UUID& U);
120 
121 private:
122  Kind K;
123  UUID Uuid;
124  // The Context object can never be null as it can only be passed to the Node
125  // constructor by reference. However, we don't want to store a reference to
126  // the Context object because we want to keep the Node class copyable and
127  // Context needs to own a move-only allocator.
128  Context* Ctx;
129 
130  friend class Context; // Enables Context::Create
131 };
132 
133 } // namespace gtirb
134 
135 #endif // GTIRB_NODE_H
gtirb::CodeBlock
A basic block.
Definition: CodeBlock.hpp:54
gtirb::Context::Create
NodeTy * Create(Args &&... TheArgs)
Create an object of type T.
Definition: Context.hpp:126
gtirb::Node
Represents the base of the Node class hierarchy.
Definition: Node.hpp:39
gtirb::CfgNode
Represents the base of types that can be inserted into the CFG.
Definition: CfgNode.hpp:30
gtirb::UUID
boost::uuids::uuid UUID
Represents a universally unique identifier used to identify Node objects across serialization boundar...
Definition: Context.hpp:36
gtirb::DataBlock
Represents a data object, possibly symbolic.
Definition: DataBlock.hpp:44
gtirb::Context
The context under which GTIRB operations occur.
Definition: Context.hpp:63
Context.hpp
Class gtirb::Context and related operators.
gtirb::Node::getByUUID
static const Node * getByUUID(const Context &C, const UUID &Uuid)
Retrieve a node by its UUID.
Definition: Node.hpp:73
gtirb::Section
Represents a named section of the binary.
Definition: Section.hpp:66
GTIRB_EXPORT_API
#define GTIRB_EXPORT_API
This macro controls the visibility of exported symbols (i.e. classes) in shared libraries....
Definition: Export.hpp:52
gtirb::Node::getByUUID
static Node * getByUUID(Context &C, const UUID &Uuid)
Retrieve a node by its UUID.
Definition: Node.hpp:66
gtirb
Main namespace for the GTIRB API.
Definition: Addr.hpp:28
Export.hpp
gtirb::ProxyBlock
A placeholder that serves as the endpoint (source or target) of a CFG edge.
Definition: ProxyBlock.hpp:49
gtirb::IR
A complete internal representation consisting of Modules (Module).
Definition: IR.hpp:76
Casting.hpp
The various casting and type checking operations that apply to gtirb::Node subclasses.
gtirb::Module
Represents a single binary (library or executable).
Definition: Module.hpp:107
gtirb::Node::Create
static Node * Create(Context &C)
Create a Node object in its default state.
Definition: Node.hpp:82
gtirb::ByteInterval
A contiguous region of bytes in a binary.
Definition: ByteInterval.hpp:116
gtirb::Symbol
Represents a Symbol, which maps a name to an object in the IR.
Definition: Symbol.hpp:43