+void IR2MIDICompiler::CheckForRecursion(const std::string& trackBlockName, const AST::SourceLocation& location)
+{
+ auto it = std::find_if(
+ m_TrackBlockCompilationStack.begin(),
+ m_TrackBlockCompilationStack.end(),
+ [&trackBlockName] (auto&& x)
+ {
+ return x.Name == trackBlockName;
+ }
+ );
+
+ if (it != m_TrackBlockCompilationStack.end())
+ {
+ AddMessage(
+ Message::MessageItem{
+ Message::MessageKind::Error,
+ Message::MessageID::TrackBlockCompilationRecursion,
+ GetSourceName(),
+ location,
+ {trackBlockName}
+ }
+ );
+
+ if (m_TrackBlockCompilationStack.size() > 1)
+ {
+ std::for_each(
+ m_TrackBlockCompilationStack.rbegin(),
+ m_TrackBlockCompilationStack.rend() - 1,
+ [this] (auto&& x)
+ {
+ this->AddMessage(
+ Message::MessageItem{
+ Message::MessageKind::Note,
+ Message::MessageID::TrackBlockCompilationBackTrace,
+ this->GetSourceName(),
+ x.Location,
+ {x.Name}
+ }
+ );
+ }
+ );
+ }
+
+ throw Exceptions::MessageException(
+ Message::MessageItem{
+ Message::MessageKind::Note,
+ Message::MessageID::TrackBlockCompilationBackTraceEntryPoint,
+ GetSourceName(),
+ {},
+ {m_TrackBlockCompilationStack.at(0).Name}
+ }
+ );
+ }
+}
+