Files
whetstone_DSL/editor/src/LanguageSeamFrameDetector.h

52 lines
1.7 KiB
C
Raw Normal View History

#pragma once
#include "PolyglotStackTraceDecoder.h"
#include <string>
#include <vector>
namespace whetstone {
class LanguageSeamFrameDetector {
public:
// Returns indices of all frames where isBoundary == true.
std::vector<int> detectSeams(const std::vector<StackFrame>& frames) const {
std::vector<int> seams;
for (int i = 0; i < static_cast<int>(frames.size()); ++i)
if (frames[i].isBoundary) seams.push_back(i);
return seams;
}
// Index of first seam frame, -1 if none.
int primarySeam(const std::vector<StackFrame>& frames) const {
for (int i = 0; i < static_cast<int>(frames.size()); ++i)
if (frames[i].isBoundary) return i;
return -1;
}
int seamCount(const std::vector<StackFrame>& frames) const {
return static_cast<int>(detectSeams(frames).size());
}
// Unique languages in order of first appearance.
std::vector<std::string> frameLanguages(const std::vector<StackFrame>& frames) const {
std::vector<std::string> result;
for (const auto& f : frames) {
bool found = false;
for (const auto& l : result) if (l == f.language) { found = true; break; }
if (!found) result.push_back(f.language);
}
return result;
}
// True if any adjacent pair transitions from fromLang to toLang.
bool crossesBoundary(const std::vector<StackFrame>& frames,
const std::string& fromLang,
const std::string& toLang) const {
for (std::size_t i = 0; i + 1 < frames.size(); ++i)
if (frames[i].language == fromLang && frames[i+1].language == toLang)
return true;
return false;
}
};
} // namespace whetstone