Jlm
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
jlm::util::graph::GraphElement Class Referenceabstract

#include <GraphWriter.hpp>

Inheritance diagram for jlm::util::graph::GraphElement:
Inheritance graph
[legend]

Public Member Functions

virtual ~GraphElement ()=default
 
 GraphElement ()
 
 GraphElement (const GraphElement &other)=delete
 
 GraphElement (GraphElement &&other)=delete
 
GraphElementoperator= (const GraphElement &other)=delete
 
GraphElementoperator= (GraphElement &&other)=delete
 
virtual const char * GetIdPrefix () const =0
 
std::string GetFullId () const
 
virtual GraphGetGraph ()=0
 
const GraphGetGraph () const
 
void SetLabel (std::string label)
 
void AppendToLabel (std::string_view text, std::string_view sep="\n")
 
bool HasLabel () const
 
const std::string & GetLabel () const
 
std::string_view GetLabelOr (std::string_view otherwise) const
 
size_t GetUniqueIdSuffix () const
 
template<typename T >
void SetProgramObject (const T &object)
 
void RemoveProgramObject ()
 
bool HasProgramObject () const noexcept
 
uintptr_t GetProgramObject () const noexcept
 
void SetAttribute (const std::string &attribute, std::string value)
 
void SetAttributeObject (const std::string &attribute, uintptr_t object)
 
template<typename T >
void SetAttributeObject (const std::string &attribute, const T &object)
 
void SetAttributeGraphElement (const std::string &attribute, const GraphElement &element)
 
bool HasAttribute (const std::string &attribute) const
 
std::optional< std::string_view > GetAttributeString (const std::string &attribute) const
 
std::optional< uintptr_t > GetAttributeObject (const std::string &attribute) const
 
const GraphElementGetAttributeGraphElement (const std::string &attribute) const
 
bool RemoveAttribute (const std::string &attribute)
 
virtual void Finalize ()
 
bool IsFinalized () const
 
void OutputAttributes (std::ostream &out, AttributeOutputFormat format) const
 

Private Types

using AttributeValue = std::variant< std::string, const GraphElement *, uintptr_t >
 

Private Member Functions

void SetProgramObjectUintptr (uintptr_t object)
 

Private Attributes

std::string Label_
 
std::optional< size_t > UniqueIdSuffix_
 
uintptr_t ProgramObject_
 
std::unordered_map< std::string, AttributeValueAttributeMap_
 

Detailed Description

Definition at line 39 of file GraphWriter.hpp.

Member Typedef Documentation

◆ AttributeValue

using jlm::util::graph::GraphElement::AttributeValue = std::variant<std::string, const GraphElement *, uintptr_t>
private

Definition at line 269 of file GraphWriter.hpp.

Constructor & Destructor Documentation

◆ ~GraphElement()

virtual jlm::util::graph::GraphElement::~GraphElement ( )
virtualdefault

◆ GraphElement() [1/3]

jlm::util::graph::GraphElement::GraphElement ( )

Constructs a graph element with no label, attributes or associated program object

Definition at line 149 of file GraphWriter.cpp.

◆ GraphElement() [2/3]

jlm::util::graph::GraphElement::GraphElement ( const GraphElement other)
delete

◆ GraphElement() [3/3]

jlm::util::graph::GraphElement::GraphElement ( GraphElement &&  other)
delete

Member Function Documentation

◆ AppendToLabel()

void jlm::util::graph::GraphElement::AppendToLabel ( std::string_view  text,
std::string_view  sep = "\n" 
)

Appends the given text to the element's label. If the current label is non-empty, the separator string sep is inserted between them.

Definition at line 178 of file GraphWriter.cpp.

◆ Finalize()

void jlm::util::graph::GraphElement::Finalize ( )
virtual

Claims a unique id suffix for the element, if it doesn't already have one.

Reimplemented in jlm::util::graph::Graph, and jlm::util::graph::InOutNode.

Definition at line 332 of file GraphWriter.cpp.

◆ GetAttributeGraphElement()

const GraphElement * jlm::util::graph::GraphElement::GetAttributeGraphElement ( const std::string &  attribute) const

Retrieves the value of the given attribute, if it is assigned a graph element. Otherwise, if the attribute is assigned a program object, and there exists a GraphElement representing that program object, that is returned.

Returns
pointer to the GraphElement held in the attribute, or nullptr if it does not exist.

Definition at line 299 of file GraphWriter.cpp.

◆ GetAttributeObject()

std::optional< uintptr_t > jlm::util::graph::GraphElement::GetAttributeObject ( const std::string &  attribute) const

Retrieves the value of the given attribute, if it is assigned a program object. If the attribute does not exist, or is not holding a program object, std::nullopt is returned.

Returns
the object assigned to the attribute, or std::nullopt if it does not exist.

Definition at line 286 of file GraphWriter.cpp.

◆ GetAttributeString()

std::optional< std::string_view > jlm::util::graph::GraphElement::GetAttributeString ( const std::string &  attribute) const

Retrieves the value of the given attribute, if it exists and is assigned a string.

Returns
the attribute's string value, or std::nullopt if it does not exist.

Definition at line 273 of file GraphWriter.cpp.

◆ GetFullId()

std::string jlm::util::graph::GraphElement::GetFullId ( ) const

Gives the final unique ID of the GraphElement, such as "node3". Requires the GraphElement to be finalized.

Returns
the full id of the GraphElement, including unique suffix

Definition at line 157 of file GraphWriter.cpp.

◆ GetGraph() [1/2]

const Graph & jlm::util::graph::GraphElement::GetGraph ( ) const

Definition at line 166 of file GraphWriter.cpp.

◆ GetGraph() [2/2]

virtual Graph& jlm::util::graph::GraphElement::GetGraph ( )
pure virtual

Gets a reference to the graph this GraphElement belongs to

Implemented in jlm::util::graph::Graph, jlm::util::graph::Edge, jlm::util::graph::Node, and jlm::util::graph::Port.

◆ GetIdPrefix()

virtual const char* jlm::util::graph::GraphElement::GetIdPrefix ( ) const
pure virtual

Gets a short string that will serve as the base for a unique ID. This base should be a valid C-like identifier.

Returns
a string, such as "node", "i", "o", "graph"

Implemented in jlm::util::graph::Graph, jlm::util::graph::Edge, jlm::util::graph::ResultNode, jlm::util::graph::ArgumentNode, jlm::util::graph::OutputPort, jlm::util::graph::InputPort, and jlm::util::graph::Node.

◆ GetLabel()

const std::string & jlm::util::graph::GraphElement::GetLabel ( ) const
Returns
the GraphElement's label

Definition at line 197 of file GraphWriter.cpp.

◆ GetLabelOr()

std::string_view jlm::util::graph::GraphElement::GetLabelOr ( std::string_view  otherwise) const
Returns
the graph element's label, or if it is empty, the string otherwise

Definition at line 203 of file GraphWriter.cpp.

◆ GetProgramObject()

uintptr_t jlm::util::graph::GraphElement::GetProgramObject ( ) const
noexcept
Returns
the program object associated with this graph element.

Definition at line 241 of file GraphWriter.cpp.

◆ GetUniqueIdSuffix()

size_t jlm::util::graph::GraphElement::GetUniqueIdSuffix ( ) const
Returns
the unique suffix assigned to this element when finalized.
See also
IsFinalized() must return true before calling

Definition at line 211 of file GraphWriter.cpp.

◆ HasAttribute()

bool jlm::util::graph::GraphElement::HasAttribute ( const std::string &  attribute) const
Returns
true if an attribute with the given name attribute is defined

Definition at line 267 of file GraphWriter.cpp.

◆ HasLabel()

bool jlm::util::graph::GraphElement::HasLabel ( ) const
Returns
true if this graph element has a non-empty label

Definition at line 191 of file GraphWriter.cpp.

◆ HasProgramObject()

bool jlm::util::graph::GraphElement::HasProgramObject ( ) const
noexcept
Returns
true, if this GraphElement is associated with any program object

Definition at line 235 of file GraphWriter.cpp.

◆ IsFinalized()

bool jlm::util::graph::GraphElement::IsFinalized ( ) const
Returns
true if this GraphElement has been finalized, otherwise false.

Definition at line 342 of file GraphWriter.cpp.

◆ operator=() [1/2]

GraphElement& jlm::util::graph::GraphElement::operator= ( const GraphElement other)
delete

◆ operator=() [2/2]

GraphElement& jlm::util::graph::GraphElement::operator= ( GraphElement &&  other)
delete

◆ OutputAttributes()

void jlm::util::graph::GraphElement::OutputAttributes ( std::ostream &  out,
AttributeOutputFormat  format 
) const

Prints the attributes of the graph element.

Parameters
outthe stream output is written to.
formatthe output format to use.

Definition at line 348 of file GraphWriter.cpp.

◆ RemoveAttribute()

bool jlm::util::graph::GraphElement::RemoveAttribute ( const std::string &  attribute)

Removes the attribute with the given name attribute, if it exists.

Returns
true if the attribute existed, and was removed, false otherwise

Definition at line 326 of file GraphWriter.cpp.

◆ RemoveProgramObject()

void jlm::util::graph::GraphElement::RemoveProgramObject ( )

Removes the association of this GraphElement to any object in the program

Definition at line 229 of file GraphWriter.cpp.

◆ SetAttribute()

void jlm::util::graph::GraphElement::SetAttribute ( const std::string &  attribute,
std::string  value 
)

Assigns or overrides a given attribute on the element.

Parameters
attributethe name of the attribute
valuethe attribute value

Definition at line 247 of file GraphWriter.cpp.

◆ SetAttributeGraphElement()

void jlm::util::graph::GraphElement::SetAttributeGraphElement ( const std::string &  attribute,
const GraphElement element 
)

Assigns or overrides a given attribute on the element with a reference to a graph element. This allows associations between graph elements to be included in the output, across graphs. The element must be a part of the same GraphWriter instance.

Parameters
attributethe name of the attribute.
elementthe graph element whose id should be used as attribute value.

Definition at line 260 of file GraphWriter.cpp.

◆ SetAttributeObject() [1/2]

template<typename T >
void jlm::util::graph::GraphElement::SetAttributeObject ( const std::string &  attribute,
const T &  object 
)
inline

Helper for calling SetAttributeObject with a pointer to any type

Definition at line 182 of file GraphWriter.hpp.

◆ SetAttributeObject() [2/2]

void jlm::util::graph::GraphElement::SetAttributeObject ( const std::string &  attribute,
uintptr_t  object 
)

Assigns or overrides a given attribute on the element with the address of a program object. If this program object is associated with a GraphElement in the same GraphWriter, the attribute value becomes the id of the other GraphElement, instead of the address.

Parameters
attributethe name of the attribute.
objectthe address of a program object, must be non-null.

Definition at line 253 of file GraphWriter.cpp.

◆ SetLabel()

void jlm::util::graph::GraphElement::SetLabel ( std::string  label)

Sets the element's label. A label is text intended to be visible in all renderings of the graph. Use an empty string to signify no label.

Parameters
labelthe new label string

Definition at line 172 of file GraphWriter.cpp.

◆ SetProgramObject()

template<typename T >
void jlm::util::graph::GraphElement::SetProgramObject ( const T &  object)
inline

Graph elements often represent objects from the program. By making this association explicit, GraphElements can be looked up by program object. When using program objects as attributes, the association is used to refer to the unique id of its associated graph element, instead of the object's address. Within a graph, only one graph element can be associated with any given program object.

Template Parameters
Tthe type of the program object to associate with
Parameters
objectthe object to associate this GraphElement with

Definition at line 136 of file GraphWriter.hpp.

◆ SetProgramObjectUintptr()

void jlm::util::graph::GraphElement::SetProgramObjectUintptr ( uintptr_t  object)
private

Definition at line 218 of file GraphWriter.cpp.

Member Data Documentation

◆ AttributeMap_

std::unordered_map<std::string, AttributeValue> jlm::util::graph::GraphElement::AttributeMap_
private

Definition at line 270 of file GraphWriter.hpp.

◆ Label_

std::string jlm::util::graph::GraphElement::Label_
private

Definition at line 259 of file GraphWriter.hpp.

◆ ProgramObject_

uintptr_t jlm::util::graph::GraphElement::ProgramObject_
private

Definition at line 265 of file GraphWriter.hpp.

◆ UniqueIdSuffix_

std::optional<size_t> jlm::util::graph::GraphElement::UniqueIdSuffix_
private

Definition at line 262 of file GraphWriter.hpp.


The documentation for this class was generated from the following files: