diff options
-rwxr-xr-x | decoder/cfg.cc | 4 | ||||
-rwxr-xr-x | decoder/cfg_format.h | 3 | ||||
-rwxr-xr-x | decoder/nt_span.h | 22 | ||||
-rwxr-xr-x | utils/named_enum.h | 4 |
4 files changed, 22 insertions, 11 deletions
diff --git a/decoder/cfg.cc b/decoder/cfg.cc index aa9e5f30..8fc5b10f 100755 --- a/decoder/cfg.cc +++ b/decoder/cfg.cc @@ -22,8 +22,8 @@ WordID BinName(CFG::BinRhs const& b,CFG::NTs const& N,CFG::NTs const& M) int n=w; if (n>0) o << TD::Convert(n); \ else { \ int i=-n; \ - CFG::NT const&nt = i<nn?N[i]:M[i-nn]; \ - o << nt.from << i; } \ + if (i<nn) o<<N[i].from<<i; else o<<M[i-nn].from; \ + } \ } while(0) BinNameOWORD(b.first); diff --git a/decoder/cfg_format.h b/decoder/cfg_format.h index ccf6e3fa..d56d42f2 100755 --- a/decoder/cfg_format.h +++ b/decoder/cfg_format.h @@ -67,7 +67,8 @@ struct CFGFormat { o<<nt_prefix; if (nt_span) cfg.print_nt_name(o,id); - o<<id; + else + o<<id; } template <class CFG> diff --git a/decoder/nt_span.h b/decoder/nt_span.h index 46234b07..a918f301 100755 --- a/decoder/nt_span.h +++ b/decoder/nt_span.h @@ -8,10 +8,15 @@ struct Span { int l,r; Span() : l(-1) { } + bool is_null() const { return l<0; } + void print(std::ostream &o,char const* for_null="") const { + if (is_null()) + o<<for_null; + else + o<<'<'<<l<<','<<r<<'>'; + } friend inline std::ostream &operator<<(std::ostream &o,Span const& s) { - if (s.l<0) - return o; - return o<<'<'<<s.l<<','<<s.r<<'>'; + s.print(o);return o; } }; @@ -20,10 +25,15 @@ struct NTSpan { WordID nt; // awkward: this is a positive index, used in TD. but represented as negative in mixed terminal/NT space in rules/hgs. NTSpan() : nt(0) { } // prints as possibly empty name (whatever you set of nt,s will show) + void print(std::ostream &o,char const* for_span_null="_",char const* for_null="") const { + if (nt>0) { + o<<TD::Convert(nt); + s.print(o,for_span_null); + } else + s.print(o,for_null); + } friend inline std::ostream &operator<<(std::ostream &o,NTSpan const& t) { - if (t.nt>0) - o<<TD::Convert(t.nt); - return o << t.s; + t.print(o);return o; } }; diff --git a/utils/named_enum.h b/utils/named_enum.h index b459b4a9..447dff78 100755 --- a/utils/named_enum.h +++ b/utils/named_enum.h @@ -74,9 +74,9 @@ inline void throw_enum_error(std::string const& enumtype,std::string const& msg) /// declare the access function and define enum values #define DECLARE_NAMED_ENUM_T(DEF,EnumType) \ - typedef enum { \ + enum EnumType { \ DEF(NAMED_ENUM_VALUE,EnumType) \ - } EnumType; \ + }; \ const char *GetName(EnumType dummy); \ EnumType Get ## EnumType (const char *string); \ inline EnumType Get ## EnumType (std::string const& s) { return Get ## EnumType (s.c_str()); } \ |