Skip to content
Snippets Groups Projects
Commit 71909cd6 authored by Franck Dary's avatar Franck Dary
Browse files

Checking for cycles in action attach

parent 2465f80b
No related branches found
No related tags found
No related merge requests found
......@@ -358,7 +358,30 @@ Action Action::attach(Object governorObject, int governorIndex, Object dependent
govLineIndex = config.getStack(governorIndex);
}
return addHypothesisRelative(Config::headColName, dependentObject, dependentIndex, std::to_string(govLineIndex)).appliable(config, action);
int depLineIndex = 0;
if (dependentObject == Object::Buffer)
{
depLineIndex = config.getWordIndex() + dependentIndex;
if (!config.has(0, depLineIndex, 0))
return false;
}
else
{
if (!config.hasStack(dependentIndex))
return false;
depLineIndex = config.getStack(dependentIndex);
}
// Check for cycles
while (govLineIndex != depLineIndex)
{
try
{
govLineIndex = std::stoi(config.getLastNotEmptyHypConst(Config::headColName, govLineIndex));
} catch(std::exception &) {return true;}
}
return false;
};
return {Type::Write, apply, undo, appliable};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment