diff options
-rw-r--r-- | src/document.cc | 3 | ||||
-rw-r--r-- | src/value.cc | 88 |
2 files changed, 88 insertions, 3 deletions
diff --git a/src/document.cc b/src/document.cc index 3c04ed57..da7db95e 100644 --- a/src/document.cc +++ b/src/document.cc @@ -158,7 +158,8 @@ optional<const char *> document_t::lookup_name(nameid_t id) const } } else if (names) { - int index = id - 1000; + assert(id >= 1000); + std::size_t index = id - 1000; typedef names_t::nth_index<0>::type names_by_random_access; const names_by_random_access& random_access = names->get<0>(); if (index < random_access.size()) diff --git a/src/value.cc b/src/value.cc index 9c50f830..ecd95705 100644 --- a/src/value.cc +++ b/src/value.cc @@ -86,6 +86,9 @@ value_t& value_t::operator=(const value_t& val) if (type() == val.type()) switch (type()) { + case VOID: + assert(false); + return *this; case BOOLEAN: as_boolean_lval() = val.as_boolean(); return *this; @@ -110,6 +113,8 @@ value_t& value_t::operator=(const value_t& val) case SEQUENCE: as_sequence_lval() = val.as_sequence(); return *this; + default: + break; } switch (val.type()) { @@ -338,6 +343,8 @@ value_t& value_t::operator+=(const value_t& val) case AMOUNT: as_datetime_lval() += date_duration(val.as_amount().to_long()); return *this; + default: + break; } break; @@ -358,6 +365,8 @@ value_t& value_t::operator+=(const value_t& val) in_place_cast(BALANCE_PAIR); as_balance_pair_lval() += val.as_balance_pair(); return *this; + default: + break; } break; @@ -392,6 +401,8 @@ value_t& value_t::operator+=(const value_t& val) in_place_cast(BALANCE_PAIR); as_balance_pair_lval() += val.as_balance_pair(); return *this; + default: + break; } break; @@ -410,6 +421,8 @@ value_t& value_t::operator+=(const value_t& val) in_place_cast(BALANCE_PAIR); as_balance_pair_lval() += val.as_balance_pair(); return *this; + default: + break; } break; @@ -427,8 +440,13 @@ value_t& value_t::operator+=(const value_t& val) case BALANCE_PAIR: as_balance_pair_lval() += val.as_balance_pair(); return *this; + default: + break; } break; + + default: + break; } throw_(value_error, "Cannot add " << label() << " to " << val.label()); @@ -469,6 +487,8 @@ value_t& value_t::operator-=(const value_t& val) case AMOUNT: as_datetime_lval() -= date_duration(val.as_amount().to_long()); return *this; + default: + break; } break; @@ -492,6 +512,8 @@ value_t& value_t::operator-=(const value_t& val) as_balance_pair_lval() -= val.as_balance_pair(); in_place_simplify(); return *this; + default: + break; } break; @@ -534,6 +556,8 @@ value_t& value_t::operator-=(const value_t& val) as_balance_pair_lval() -= val.as_balance_pair(); in_place_simplify(); return *this; + default: + break; } break; @@ -556,6 +580,8 @@ value_t& value_t::operator-=(const value_t& val) as_balance_pair_lval() -= val.as_balance_pair(); in_place_simplify(); return *this; + default: + break; } break; @@ -577,8 +603,13 @@ value_t& value_t::operator-=(const value_t& val) as_balance_pair_lval() -= val.as_balance_pair(); in_place_simplify(); return *this; + default: + break; } break; + + default: + break; } throw_(value_error, "Cannot subtract " << label() << " from " << val.label()); @@ -616,6 +647,8 @@ value_t& value_t::operator*=(const value_t& val) case AMOUNT: set_amount(val.as_amount() * as_long()); return *this; + default: + break; } break; @@ -624,7 +657,6 @@ value_t& value_t::operator*=(const value_t& val) case INTEGER: as_amount_lval() *= val.as_long(); return *this; - case AMOUNT: if (as_amount().commodity() == val.as_amount().commodity() || ! val.as_amount().has_commodity()) { @@ -632,6 +664,8 @@ value_t& value_t::operator*=(const value_t& val) return *this; } break; + default: + break; } break; @@ -646,6 +680,8 @@ value_t& value_t::operator*=(const value_t& val) return *this; } break; + default: + break; } break; @@ -660,8 +696,13 @@ value_t& value_t::operator*=(const value_t& val) return *this; } break; + default: + break; } break; + + default: + break; } throw_(value_error, "Cannot multiply " << label() << " with " << val.label()); @@ -683,6 +724,8 @@ value_t& value_t::operator/=(const value_t& val) case AMOUNT: set_amount(val.as_amount() / as_long()); return *this; + default: + break; } break; @@ -699,6 +742,8 @@ value_t& value_t::operator/=(const value_t& val) return *this; } break; + default: + break; } break; @@ -713,6 +758,8 @@ value_t& value_t::operator/=(const value_t& val) return *this; } break; + default: + break; } break; @@ -727,8 +774,13 @@ value_t& value_t::operator/=(const value_t& val) return *this; } break; + default: + break; } break; + + default: + break; } throw_(value_error, "Cannot divide " << label() << " by " << val.label()); @@ -987,6 +1039,8 @@ void value_t::in_place_cast(type_t cast_type) case STRING: set_string(as_boolean() ? "true" : "false"); return; + default: + break; } break; @@ -1004,6 +1058,8 @@ void value_t::in_place_cast(type_t cast_type) case STRING: set_string(lexical_cast<string>(as_long())); return; + default: + break; } break; @@ -1021,6 +1077,8 @@ void value_t::in_place_cast(type_t cast_type) case STRING: set_string(as_amount().to_string()); return; + default: + break; } break; @@ -1045,6 +1103,8 @@ void value_t::in_place_cast(type_t cast_type) case BALANCE_PAIR: set_balance_pair(as_balance()); return; + default: + break; } break; @@ -1069,6 +1129,8 @@ void value_t::in_place_cast(type_t cast_type) case BALANCE: set_balance(as_balance_pair().quantity); return; + default: + break; } break; @@ -1084,12 +1146,16 @@ void value_t::in_place_cast(type_t cast_type) } break; } - case AMOUNT: set_amount(as_string()); return; + default: + break; } break; + + default: + break; } throw_(value_error, @@ -1118,6 +1184,8 @@ void value_t::in_place_negate() *this = as_xml_node()->to_value(); in_place_negate(); return; + default: + break; } throw_(value_error, "Cannot negate " << label()); @@ -1180,6 +1248,9 @@ value_t value_t::value(const optional<moment_t>& moment) const } case XML_NODE: return as_xml_node()->to_value().value(moment); + + default: + break; } throw_(value_error, "Cannot find the value of " << label()); @@ -1204,6 +1275,8 @@ void value_t::in_place_reduce() *this = as_xml_node()->to_value(); in_place_reduce(); // recurse break; + default: + break; } throw_(value_error, "Cannot reduce " << label()); @@ -1222,6 +1295,8 @@ value_t value_t::round() const return as_balance_pair().round(); case XML_NODE: return as_xml_node()->to_value().round(); + default: + break; } throw_(value_error, "Cannot round " << label()); @@ -1251,6 +1326,8 @@ value_t value_t::unround() const throw_(value_error, "Cannot un-round a pointer"); case SEQUENCE: throw_(value_error, "Cannot un-round a sequence"); + default: + break; } assert(false); return value_t(); @@ -1509,6 +1586,10 @@ void value_t::print(std::ostream& out, const int first_width, const int latter_width) const { switch (type()) { + case VOID: + out << "NULL"; + break; + case BOOLEAN: case DATETIME: case INTEGER: @@ -1546,6 +1627,9 @@ void value_t::print(std::ostream& out, const int first_width, case BALANCE_PAIR: as_balance_pair().print(out, first_width, latter_width); break; + default: + assert(false); + break; } } |