| chigraph master Systems programming language written for beginners in LLVM

Public Member Functions | List of all members
chi::GraphModule Struct Reference

Module that holds graph functions. More...

`#include <chi/GraphModule.hpp>`

Inheritance diagram for chi::GraphModule:
[legend]
Collaboration diagram for chi::GraphModule:
[legend]

## Public Member Functions
| GraphModule (Context &cont, boost::filesystem::path fullName, const std::vector< boost::filesystem::path > &dependencies={})
| Construct a GraphModule. More...
| GraphModule (const GraphModule &)=delete
| GraphModule (GraphModule &&)=delete
Result | addDependency (boost::filesystem::path newDepFullPath)
| Add a dependency to the module Loads the module from context() if it isn't already loaded. More...
Result | addForwardDeclarations (llvm::Module &module) const override
| Adds forward declartions for the functions in this module. More...
Context & | context () const
| Get the Context that this module belongs to. More...
boost::bimap< unsigned, NodeInstance * > | createLineNumberAssoc () const
| Create the associations from line number and function in debug info. More...
const std::set< boost::filesystem::path > & | dependencies () const
| Get the dependencies. More...
std::string | fullName () const
| Get the full name of the module. More...
boost::filesystem::path | fullNamePath () const
| Get the full name of the module in a path. More...
Result | generateModule (llvm::Module &module) override
| Generate a llvm::Module from the module. More...
std::time_t | lastEditTime () const
| Get the time that this module was last edited. More...
Result | nodeTypeFromName (boost::string_view name, const nlohmann::json &jsonData, std::unique_ptr< NodeType > *toFill) override
| Create a node type that is in the module from the name and json. More...
std::vector< std::string > | nodeTypeNames () const override
| Get the possible node type names. More...
GraphModule & | operator= (const GraphModule &)=delete
GraphModule & | operator= (GraphModule &&)=delete
bool | removeDependency (std::string depName)
| Remove a dependency Does not unload from context. More...
Result | saveToDisk () const
| Serialize to disk in the context. More...
std::string | shortName () const
| Get the short name of the module (the last bit) More...
boost::filesystem::path | sourceFilePath () const
| Get the path to the source file It's not garunteed to exist, because it could have not been saved. More...
DataType | typeFromName (boost::string_view name) override
| Get a DataType from the name. More...
std::vector< std::string > | typeNames () const override
| Get the possible DataType names. More...
void | updateLastEditTime (std::time_t newLastEditTime=std::time(nullptr))
| Update the last edit time, signifying that it's been edited. More...
Function Creation and Manipulation
GraphFunction * | getOrCreateFunction (std::string name, std::vector< NamedDataType > dataIns, std::vector< NamedDataType > dataOuts, std::vector< std::string > execIns, std::vector< std::string > execOuts, bool *inserted=nullptr)
| Create a new function if it does't already exist. More...
bool | removeFunction (boost::string_view name, bool deleteReferences=true)
| Remove a function from the module. More...
void | removeFunction (GraphFunction &func, bool deleteReferences=true)
| Remove a function from the module. More...
GraphFunction * | functionFromName (boost::string_view name) const
| Get a function from the name. More...
const std::vector< std::unique_ptr< GraphFunction > > & | functions () const
| Get functions. More...
Struct Creation and Manipulation
const std::vector< std::unique_ptr< GraphStruct > > & | structs () const
GraphStruct * | structFromName (boost::string_view name) const
| Get a struct by name. More...
GraphStruct * | getOrCreateStruct (std::string name, bool *inserted=nullptr)
| Create a new struct in the module. More...
bool | removeStruct (boost::string_view name)
| Remove a struct from the module by name. More...
void | removeStruct (GraphStruct &tyToDel)
| Remove a struct from the module by pointer. More...
C Support
void | setCEnabled (bool newValue)
| Set if C support is enabled. More...
bool | cEnabled () const
| Gets if C support is enabled. More...
Result | createNodeTypeFromCCode (boost::string_view code, boost::string_view functionName, std::vector< std::string > clangArgs, std::unique_ptr< NodeType > *toFill)
| From C code, create a NodeType. More...
boost::filesystem::path | pathToCSources () const
| Get the path to the .c directory. It is not garunteed to exist, even if cEnabled() is true.

## Detailed Description

Module that holds graph functions.

Definition at line 16 of file GraphModule.hpp.

## Constructor & Destructor Documentation

## ◆ GraphModule()

chi::GraphModule::GraphModule | ( | Context & | cont,
|  | boost::filesystem::path | fullName,
|  | const std::vector< boost::filesystem::path > & | dependencies = `{}`
| ) |  |

Construct a GraphModule.

Parameters

  cont | The context
  fullName | The full name of the module
  dependencies | The dependencies

Definition at line 409 of file GraphModule.cpp.

References chi::ChiModule::addDependency().

Here is the call graph for this function:

## Member Function Documentation

## ◆ addDependency()

Result chi::ChiModule::addDependency | ( | boost::filesystem::path | newDepFullPath | ) |
| inherited

Add a dependency to the module Loads the module from context() if it isn't already loaded.

Parameters

  newDepFullPath | The dependency, full path

Returns
  The result

Definition at line 13 of file ChiModule.cpp.

References chi::ChiModule::context(), and chi::Context::loadModule().

Referenced by chi::ChiModule::dependencies(), and GraphModule().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ addForwardDeclarations()

Result chi::GraphModule::addForwardDeclarations | ( | llvm::Module & | module | ) | const
| override virtual

Adds forward declartions for the functions in this module.

Parameters

  module | The module to add forward declartions to

Returns
  The Result

Implements chi::ChiModule.

Definition at line 425 of file GraphModule.cpp.

References chi::ChiModule::fullName(), and chi::mangleFunctionName().

Here is the call graph for this function:

## ◆ cEnabled()

bool chi::GraphModule::cEnabled | ( |  | ) | const
| inline

Gets if C support is enabled.

Returns
  true if C support is enabled

Definition at line 136 of file GraphModule.hpp.

References createNodeTypeFromCCode().

Referenced by generateModule(), chi::graphModuleToJson(), nodeTypeFromName(), and nodeTypeNames().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ context()

Context& chi::ChiModule::context | ( |  | ) | const
| inline inherited

Get the Context that this module belongs to.

Returns
  The context

Definition at line 68 of file ChiModule.hpp.

References chi::ChiModule::addForwardDeclarations(), and chi::ChiModule::generateModule().

Referenced by chi::ChiModule::addDependency(), chi::createGraphFunctionDeclarationFromJson(), createNodeTypeFromCCode(), generateModule(), chi::jsonToGraphStruct(), chi::LangModule::LangModule(), chi::Debugger::nodeFromFrame(), nodeTypeFromName(), removeFunction(), saveToDisk(), sourceFilePath(), chi::Debugger::start(), and chi::LangModule::typeFromName().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ createLineNumberAssoc()

boost::bimap< unsigned int, NodeInstance * > chi::GraphModule::createLineNumberAssoc | ( |  | ) | const

Create the associations from line number and function in debug info.

Returns
  A bimap of function to line number

Definition at line 794 of file GraphModule.cpp.

References functions().

Referenced by chi::FunctionCompiler::initialize(), chi::lineNumberFromNode(), and chi::Debugger::nodeFromFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ createNodeTypeFromCCode()

Result chi::GraphModule::createNodeTypeFromCCode | ( | boost::string_view | code,
|  | boost::string_view | functionName,
|  | std::vector< std::string > | clangArgs,
|  | std::unique_ptr< NodeType > * | toFill
| ) |  |

From C code, create a NodeType.

Parameters

  code | The code
  functionName | the function to call
  clangArgs | Extra arguments to pass to clang
  toFill | The unique_ptr to fill

Precondition
  toFill must not be nullptr (the unique_ptr it points to can be though)

Returns
  The Result

Definition at line 866 of file GraphModule.cpp.

References chi::Result::addEntry(), chi::compileCToLLVM(), chi::ChiModule::context(), pathToCSources(), chi::stringifyLLVMType(), and chi::Context::typeFromModule().

Referenced by cEnabled().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ dependencies()

const std::set<boost::filesystem::path>& chi::ChiModule::dependencies | ( |  | ) | const
| inline inherited

Get the dependencies.

Returns
  The dependencies

Definition at line 83 of file ChiModule.hpp.

References chi::ChiModule::addDependency().

Referenced by chi::Context::compileModule(), and chi::graphModuleToJson().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ fullName()

std::string chi::ChiModule::fullName | ( |  | ) | const
| inline inherited

Get the full name of the module.

Returns
  The full name

Definition at line 61 of file ChiModule.hpp.

Referenced by addForwardDeclarations(), chi::Context::addModuleFromJson(), chi::Context::compileModule(), chi::createGraphFunctionDeclarationFromJson(), chi::FunctionCompiler::initialize(), nodeTypeFromName(), chi::NodeType::qualifiedName(), chi::DataType::qualifiedName(), chi::GraphFunction::qualifiedName(), removeFunction(), sourceFilePath(), chi::validateFunctionConnectionsAreTwoWay(), chi::validateFunctionEntryType(), chi::validateFunctionExecOutputs(), and chi::validateFunctionNodeInputs().

Here is the caller graph for this function:

## ◆ fullNamePath()

boost::filesystem::path chi::ChiModule::fullNamePath | ( |  | ) | const
| inline inherited

Get the full name of the module in a path.

Returns
  The full name, as a boost::filesystem::path

Definition at line 64 of file ChiModule.hpp.

Referenced by chi::Context::compileModule().

Here is the caller graph for this function:

## ◆ functionFromName()

GraphFunction * chi::GraphModule::functionFromName | ( | boost::string_view | name | ) | const

Get a function from the name.

Parameters

  name | The name to get

Returns
  The GraphFunction or nullptr if it doesn't exist

Definition at line 598 of file GraphModule.cpp.

Referenced by getOrCreateFunction(), chi::Debugger::nodeFromFrame(), nodeTypeFromName(), and removeFunction().

Here is the caller graph for this function:

## ◆ functions()

const std::vector<std::unique_ptr<GraphFunction> >& chi::GraphModule::functions | ( |  | ) | const
| inline

Get functions.

Returns
  The functions

Definition at line 95 of file GraphModule.hpp.

References getOrCreateStruct(), removeStruct(), and structFromName().

Referenced by createLineNumberAssoc(), and chi::graphModuleToJson().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ generateModule()

Result chi::GraphModule::generateModule | ( | llvm::Module & | module | ) |
| override virtual

Generate a llvm::Module from the module.

Usually called by Context::compileModule

Parameters

  module | The llvm::Module to fill into – must be already filled with forward declarations of dependencies

Returns
  The Result

Implements chi::ChiModule.

Definition at line 435 of file GraphModule.cpp.

References cEnabled(), chi::compileCToLLVM(), chi::ChiModule::context(), and pathToCSources().

Here is the call graph for this function:

## ◆ getOrCreateFunction()

GraphFunction * chi::GraphModule::getOrCreateFunction | ( | std::string | name,
|  | std::vector< NamedDataType > | dataIns,
|  | std::vector< NamedDataType > | dataOuts,
|  | std::vector< std::string > | execIns,
|  | std::vector< std::string > | execOuts,
|  | bool * | inserted = `nullptr`
| ) |  |

Create a new function if it does't already exist.

Parameters

  name | The name of the new function
  dataIns | The data inputs to the function
  dataOuts | The data outputs to the function
  execIns | The exec inputs to the function
  execOuts | The exec outputs to the function
  inserted | Pointer of a bool to fill; sets to true if it was inserted and false if it already existed

Returns
  The function

Definition at line 545 of file GraphModule.cpp.

References functionFromName(), and chi::ChiModule::updateLastEditTime().

Referenced by chi::createGraphFunctionDeclarationFromJson().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ getOrCreateStruct()

GraphStruct * chi::GraphModule::getOrCreateStruct | ( | std::string | name,
|  | bool * | inserted = `nullptr`
| ) |  |

Create a new struct in the module.

Parameters

  name | The name of the struct
  inserted | True if the struct was new, optional

Returns
  The new struct

Definition at line 824 of file GraphModule.cpp.

References structFromName(), and chi::ChiModule::updateLastEditTime().

Referenced by functions(), and chi::jsonToGraphStruct().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ lastEditTime()

std::time_t chi::ChiModule::lastEditTime | ( |  | ) | const
| inline inherited

Get the time that this module was last edited.

Returns
  The `std::time_t` at which it was last edited

Definition at line 101 of file ChiModule.hpp.

Referenced by chi::Context::compileModule().

Here is the caller graph for this function:

## ◆ nodeTypeFromName()

Result chi::GraphModule::nodeTypeFromName | ( | boost::string_view | name,
|  | const nlohmann::json & | jsonData,
|  | std::unique_ptr< NodeType > * | toFill
| ) |  |
| override virtual

Create a node type that is in the module from the name and json.

Parameters

  name | The name of the node type to create
  jsonData | The extra JSON data for the node

Return values

  toFill | The NodeType object to fill

Precondition
  toFill isn't null (the value the unique_ptr points to be can be null, but not the pointer to the unique_ptr)

Returns
  The result

Implements chi::ChiModule.

Definition at line 606 of file GraphModule.cpp.

References chi::Result::addEntry(), cEnabled(), chi::ChiModule::context(), chi::ChiModule::fullName(), functionFromName(), chi::parseColonPair(), chi::parseObjectPair(), structFromName(), and chi::Context::typeFromModule().

Referenced by chi::GraphStruct::dataType(), chi::GraphFunction::renameLocalVariable(), chi::GraphFunction::retypeLocalVariable(), and chi::GraphStruct::setName().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ nodeTypeNames()

std::vector< std::string > chi::GraphModule::nodeTypeNames | ( |  | ) | const
| override virtual

Get the possible node type names.

Returns
  A std::vector of the possible names

Implements chi::ChiModule.

Definition at line 779 of file GraphModule.cpp.

References cEnabled().

Here is the call graph for this function:

## ◆ removeDependency()

bool chi::ChiModule::removeDependency | ( | std::string | depName | ) |
| inline inherited

Remove a dependency Does not unload from context.

Parameters

  depName | The name of the dependency to remove

Returns
  If one was removed

Definition at line 95 of file ChiModule.hpp.

## ◆ removeFunction() [1/2]

bool chi::GraphModule::removeFunction | ( | boost::string_view | name,
|  | bool | deleteReferences = `true`
| ) |  |

Remove a function from the module.

Parameters

  name | The name of the function to remove
  deleteReferences | should all the references in the context be deleted?

Returns
  True if there was a function matching name that was removed

Definition at line 568 of file GraphModule.cpp.

References functionFromName(), and chi::ChiModule::updateLastEditTime().

Here is the call graph for this function:

## ◆ removeFunction() [2/2]

void chi::GraphModule::removeFunction | ( | GraphFunction & | func,
|  | bool | deleteReferences = `true`
| ) |  |

Remove a function from the module.

Parameters

  func | The function to remove
  deleteReferences | should all the references in the context be deleted?

Definition at line 581 of file GraphModule.cpp.

References chi::ChiModule::context(), chi::Context::findInstancesOfType(), chi::ChiModule::fullName(), chi::GraphFunction::name(), and chi::ChiModule::updateLastEditTime().

Here is the call graph for this function:

## ◆ removeStruct() [1/2]

bool chi::GraphModule::removeStruct | ( | boost::string_view | name | ) |

Remove a struct from the module by name.

Parameters

  name | The name of the struct to remove

Returns
  True if a struct was actually removed, false if no struct by that name existed

Definition at line 840 of file GraphModule.cpp.

References chi::ChiModule::updateLastEditTime().

Referenced by functions(), and removeStruct().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ removeStruct() [2/2]

void chi::GraphModule::removeStruct | ( | GraphStruct & | tyToDel | ) |

Remove a struct from the module by pointer.

Parameters

  tyToDel | Struct to delete, must be in this module

Precondition
  `tyToDel->module() == this`

Definition at line 855 of file GraphModule.cpp.

References chi::GraphStruct::module(), chi::GraphStruct::name(), and removeStruct().

Here is the call graph for this function:

## ◆ saveToDisk()

Result chi::GraphModule::saveToDisk | ( |  | ) | const

Serialize to disk in the context.

Returns
  The Result

Definition at line 514 of file GraphModule.cpp.

References chi::Result::addEntry(), chi::ChiModule::context(), chi::graphModuleToJson(), and sourceFilePath().

Here is the call graph for this function:

## ◆ setCEnabled()

void chi::GraphModule::setCEnabled | ( | bool | newValue | ) |
| inline

Set if C support is enabled.

Parameters

  newValue | true to enable C support, false to disable it

Definition at line 132 of file GraphModule.hpp.

## ◆ shortName()

std::string chi::ChiModule::shortName | ( |  | ) | const
| inline inherited

Get the short name of the module (the last bit)

Returns
  The name

Definition at line 58 of file ChiModule.hpp.

Referenced by chi::Context::compileModule(), pathToCSources(), and chi::validateFunction().

Here is the caller graph for this function:

## ◆ sourceFilePath()

boost::filesystem::path chi::GraphModule::sourceFilePath | ( |  | ) | const

Get the path to the source file It's not garunteed to exist, because it could have not been saved.

Returns
  The path

Definition at line 862 of file GraphModule.cpp.

References chi::ChiModule::context(), chi::ChiModule::fullName(), and chi::Context::workspacePath().

Referenced by pathToCSources(), saveToDisk(), and chi::Debugger::setBreakpoint().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ structFromName()

GraphStruct * chi::GraphModule::structFromName | ( | boost::string_view | name | ) | const

Get a struct by name.

Parameters

  name | The name of the struct

Returns
  The struct or nullptr if not found

Definition at line 817 of file GraphModule.cpp.

Referenced by functions(), getOrCreateStruct(), nodeTypeFromName(), and typeFromName().

Here is the caller graph for this function:

## ◆ typeFromName()

DataType chi::GraphModule::typeFromName | ( | boost::string_view | name | ) |
| override virtual

Get a DataType from the name.

Parameters

  name | The name of the type

Returns
  The data type, or an invalid DataType if failed

Implements chi::ChiModule.

Definition at line 771 of file GraphModule.cpp.

References structFromName().

Here is the call graph for this function:

## ◆ typeNames()

std::vector< std::string > chi::GraphModule::typeNames | ( |  | ) | const
| override virtual

Get the possible DataType names.

Returns
  A `std::vector` of all the names of types this module has

Implements chi::ChiModule.

Definition at line 416 of file GraphModule.cpp.

## ◆ updateLastEditTime()

void chi::ChiModule::updateLastEditTime | ( | std::time_t | newLastEditTime = `std::time(nullptr)` | ) |
| inline inherited

Update the last edit time, signifying that it's been edited.

Parameters

  newLastEditTime | The new time, or current time for default

Definition at line 105 of file ChiModule.hpp.

Referenced by chi::GraphFunction::addDataInput(), chi::GraphFunction::addDataOutput(), chi::GraphFunction::addExecInput(), chi::GraphFunction::addExecOutput(), chi::GraphStruct::addType(), chi::connectData(), chi::connectExec(), chi::disconnectData(), chi::disconnectExec(), getOrCreateFunction(), chi::GraphFunction::getOrCreateLocalVariable(), getOrCreateStruct(), chi::GraphFunction::getOrInsertEntryNode(), chi::GraphFunction::insertNode(), chi::Context::loadModule(), chi::GraphStruct::modifyType(), chi::GraphFunction::removeDataInput(), chi::GraphFunction::removeDataOutput(), chi::GraphFunction::removeExecInput(), chi::GraphFunction::removeExecOutput(), removeFunction(), chi::GraphFunction::removeLocalVariable(), chi::GraphFunction::removeNode(), removeStruct(), chi::GraphStruct::removeType(), chi::GraphFunction::renameDataInput(), chi::GraphFunction::renameDataOutput(), chi::GraphFunction::renameExecInput(), chi::GraphFunction::renameExecOutput(), chi::GraphFunction::renameLocalVariable(), chi::GraphFunction::retypeDataInput(), chi::GraphFunction::retypeLocalVariable(), chi::GraphStruct::setName(), chi::GraphFunction::setName(), and chi::NodeInstance::setType().

Here is the caller graph for this function:

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

- lib/core/include/chi/GraphModule.hpp
- lib/core/src/GraphModule.cpp