MCPcopy Create free account
hub / github.com/chigraph/chigraph / renameLocalVariable

Method renameLocalVariable

libchigraph/src/GraphFunction.cpp:430–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

428}
429
430void GraphFunction::renameLocalVariable(std::string oldName, std::string newName) {
431 // invalidate the cache
432 module().updateLastEditTime();
433
434 bool setanything = false;
435 for (auto& var : mLocalVariables) {
436 if (var.name == oldName) {
437 var.name = newName;
438
439 setanything = true;
440 break;
441 }
442 }
443
444 // if it wans't found, then we don't have to update
445 if (!setanything) { return; }
446
447 // update existing nodes
448 auto setNodes = nodesWithType(module().fullName(), "_set_" + oldName);
449 for (const auto& node : setNodes) {
450 // create a new node type
451 std::unique_ptr<NodeType> ty;
452
453 auto res = module().nodeTypeFromName("_set_" + newName, node->type().toJSON(), &ty);
454 assert(!!res);
455
456 node->setType(std::move(ty));
457 }
458
459 auto getNodes = nodesWithType(module().fullName(), "_get_" + oldName);
460 for (const auto& node : getNodes) {
461 // create a new node type
462 std::unique_ptr<NodeType> ty;
463
464 auto res = module().nodeTypeFromName("_get_" + newName, node->type().toJSON(), &ty);
465 assert(!!res);
466
467 node->setType(std::move(ty));
468 }
469}
470
471void GraphFunction::retypeLocalVariable(boost::string_view name, DataType newType) {
472 // invalidate the cache

Callers 1

Calls 6

updateLastEditTimeMethod · 0.80
fullNameMethod · 0.80
typeMethod · 0.80
setTypeMethod · 0.80
nodeTypeFromNameMethod · 0.45
toJSONMethod · 0.45

Tested by

no test coverage detected