Skip to content

Commit 9c5f0d6

Browse files
committed
1. refactor inclusion checking
2. ensure pre.lsta == pre.hsl and optionally post.lsta == post.hsl
1 parent 1eb3759 commit 9c5f0d6

File tree

4 files changed

+135
-93
lines changed

4 files changed

+135
-93
lines changed

include/autoq/aut_description.hh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace AUTOQ
3737
template <typename T> constexpr auto support_fraction_simplification = requires (T x) {
3838
x.fraction_simplification();
3939
};
40-
template<typename T> constexpr auto concrete_like = std::is_same_v<T, AUTOQ::Symbol::Concrete> || std::is_same_v<T, AUTOQ::Symbol::Index>;
4140

4241
template <typename TT>
4342
struct AUTOQ::Automata
@@ -134,12 +133,12 @@ public: // methods
134133

135134
/******************************************************/
136135
/* inclusion.cc: checks language inclusion of two TAs */
137-
bool operator<=(const Automata &o) const; // requires concrete_like<TT>;
138-
bool operator>=(const Automata &o) const requires concrete_like<TT> { return o <= *this; }
139-
bool operator==(const Automata &o) const requires concrete_like<TT> { return (*this <= o) && (o <= *this); }
140-
bool operator!=(const Automata &o) const requires concrete_like<TT> { return !(*this == o); }
141-
bool operator<(const Automata &o) const requires concrete_like<TT> { return (*this <= o) && !(o <= *this); }
142-
bool operator>(const Automata &o) const requires concrete_like<TT> { return o < *this; }
136+
bool operator<=(const Automata &o) const;
137+
bool operator>=(const Automata &o) const { return o <= *this; }
138+
bool operator==(const Automata &o) const { return (*this <= o) && (o <= *this); }
139+
bool operator!=(const Automata &o) const { return !(*this == o); }
140+
bool operator<(const Automata &o) const { return (*this <= o) && !(o <= *this); }
141+
bool operator>(const Automata &o) const { return o < *this; }
143142
// The above comparison is done after amplitude comparison.
144143
/******************************************************/
145144

src/inclusion.cc

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ bool AUTOQ::Automata<AUTOQ::Symbol::Index>::operator<=(const Automata<AUTOQ::Sym
282282
return true;
283283
}
284284

285-
template <>
286-
bool AUTOQ::Automata<AUTOQ::Symbol::Concrete>::operator<=(const Automata<AUTOQ::Symbol::Concrete> &autB) const {
285+
template <typename Symbol>
286+
bool AUTOQ::Automata<Symbol>::operator<=(const Automata<Symbol> &autB) const {
287287
// migrate instance variables
288288
Automata<AUTOQ::Symbol::Index> aut1;
289289
aut1.name = this->name;
@@ -325,7 +325,13 @@ bool AUTOQ::Automata<AUTOQ::Symbol::Concrete>::operator<=(const Automata<AUTOQ::
325325
if (i == symbol_map.size()) {
326326
symbol_map.push_back(symbol);
327327
}
328-
if (i == symbol_map.size() || symbol_map.at(i).valueEqual(symbol)) {
328+
bool eq;
329+
if constexpr (std::is_same_v<Symbol, AUTOQ::Symbol::Concrete>) {
330+
eq = symbol_map.at(i).valueEqual(symbol);
331+
} else {
332+
eq = symbol_map.at(i) == symbol;
333+
}
334+
if (i == symbol_map.size() || eq) {
329335
Automata<AUTOQ::Symbol::Index>::SymbolTag symbol_tag2 = {AUTOQ::Symbol::Index(symbol.is_leaf(), i), symbol_tag.tag()};
330336
for (const auto &out_ins : t.second) {
331337
const auto &out = out_ins.first;
@@ -345,7 +351,13 @@ bool AUTOQ::Automata<AUTOQ::Symbol::Concrete>::operator<=(const Automata<AUTOQ::
345351
if (i == symbol_map.size()) {
346352
symbol_map.push_back(symbol);
347353
}
348-
if (i == symbol_map.size() || symbol_map.at(i).valueEqual(symbol)) {
354+
bool eq;
355+
if constexpr (std::is_same_v<Symbol, AUTOQ::Symbol::Concrete>) {
356+
eq = symbol_map.at(i).valueEqual(symbol);
357+
} else {
358+
eq = symbol_map.at(i) == symbol;
359+
}
360+
if (i == symbol_map.size() || eq) {
349361
Automata<AUTOQ::Symbol::Index>::SymbolTag symbol_tag2 = {AUTOQ::Symbol::Index(symbol.is_leaf(), i), symbol_tag.tag()};
350362
for (const auto &out_ins : t.second) {
351363
const auto &out = out_ins.first;
@@ -378,11 +390,6 @@ bool AUTOQ::Automata<AUTOQ::Symbol::Concrete>::operator<=(const Automata<AUTOQ::
378390
return result;
379391
}
380392

381-
template <typename Symbol>
382-
bool AUTOQ::Automata<Symbol>::operator<=(const Automata<Symbol> &) const {
383-
THROW_AUTOQ_ERROR("The operator <= is not defined for the given type of automata.");
384-
}
385-
386393
bool AUTOQ::check_validity(Constraint C, const PredicateAutomata::Symbol &ps, const SymbolicAutomata::Symbol &te) {
387394
std::string str(ps);
388395
/* Replace all real(.) in C.content with .R and
@@ -742,6 +749,7 @@ bool operator<=(const AUTOQ::SymbolicAutomata &autA, const AUTOQ::PredicateAutom
742749
// https://bytefreaks.net/programming-2/c/c-undefined-reference-to-templated-class-function
743750
template struct AUTOQ::Automata<AUTOQ::Symbol::Concrete>;
744751
template struct AUTOQ::Automata<AUTOQ::Symbol::Symbolic>;
752+
template struct AUTOQ::Automata<AUTOQ::Symbol::Predicate>;
745753

746754
// #define MIN
747755

src/timbuk_parser-nobison.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ AUTOQ::Automata<Symbol> AUTOQ::Parsing::TimbukParser<Symbol>::parse_hsl_from_ist
13711371
while (std::getline(*is, line))
13721372
{
13731373
line = AUTOQ::String::trim(line);
1374-
std::cout<<line<<std::endl;
1374+
// std::cout<<line<<std::endl;
13751375
if (line.empty())
13761376
{
13771377
continue;

0 commit comments

Comments
 (0)