Fixed a problem in the use of boost::variant<>.

This commit is contained in:
John Wiegley 2007-05-14 23:20:34 +00:00
parent ba86b7f410
commit b36d24481d
4 changed files with 71 additions and 65 deletions

View file

@ -144,13 +144,13 @@ optional<const char *> document_t::lookup_name(nameid_t id) const
if (id < 1000) {
switch (id) {
case CURRENT:
return "CURRENT";
return ".";
case PARENT:
return "PARENT";
return "..";
case ROOT:
return "ROOT";
return "";
case ALL:
return "ALL";
return "*";
default:
assert(id >= 10);

View file

@ -142,19 +142,19 @@ static int read_and_report(ledger::report_t * report, int argc, char * argv[],
else if (verb == "xpath")
;
else if (verb == "parse") {
xml::xpath_t expr(*arg);
xml::xpath_t expr(*arg);
xml::document_t temp(xml::LEDGER_NODE);
IF_INFO() {
std::cout << "Value expression tree:" << std::endl;
expr.dump(std::cout);
std::cout << std::endl;
std::cout << "Value expression parsed was:" << std::endl;
expr.print(std::cout);
expr.print(std::cout, temp);
std::cout << std::endl << std::endl;
std::cout << "Result of calculation: ";
}
xml::document_t temp(xml::LEDGER_NODE);
std::cout << expr.calc(temp, report).strip_annotations() << std::endl;
return 0;
@ -254,7 +254,7 @@ static int read_and_report(ledger::report_t * report, int argc, char * argv[],
expr.dump(*out);
*out << std::endl;
*out << "Value expression parsed was:" << std::endl;
expr.print(*out);
expr.print(*out, xml_document);
*out << std::endl << std::endl;
*out << "Result of calculation: ";
}
@ -266,7 +266,7 @@ static int read_and_report(ledger::report_t * report, int argc, char * argv[],
else if (verb == "xpath") {
std::cout << "XPath parsed:" << std::endl;
xml::xpath_t xpath(*arg);
xpath.print(*out);
xpath.print(*out, xml_document);
*out << std::endl;
#if 0

View file

@ -575,7 +575,7 @@ xpath_t::parse_value_term(std::istream& in, flags_t tflags) const
// An identifier followed by ( represents a function call
tok = next_token(in, tflags);
if (tok.kind == token_t::LPAREN) {
node->kind = op_t::FUNC_NAME;
node = new op_t(op_t::FUNC_NAME);
node->set_string(ident);
ptr_op_t call_node(new op_t(op_t::O_EVAL));
@ -1779,6 +1779,7 @@ void xpath_t::context::describe(std::ostream& out) const throw()
#endif
bool xpath_t::op_t::print(std::ostream& out,
document_t& document,
const bool relaxed,
const ptr_op_t& op_to_find,
unsigned long * start_pos,
@ -1836,9 +1837,17 @@ bool xpath_t::op_t::print(std::ostream& out,
break;
}
case NODE_ID:
out << '%' << as_name();
case ATTR_ID:
out << '@';
// fall through...
case NODE_ID: {
optional<const char *> name = document.lookup_name(as_name());
if (name)
out << *name;
else
out << '#' << as_name();
break;
}
case NODE_NAME:
case FUNC_NAME:
@ -1863,194 +1872,194 @@ bool xpath_t::op_t::print(std::ostream& out,
case O_NOT:
out << "!";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
break;
case O_NEG:
out << "-";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
break;
case O_UNION:
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " | ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
break;
case O_ADD:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " + ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_SUB:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " - ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_MUL:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " * ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_DIV:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " / ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_NEQ:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " != ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_EQ:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " == ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_LT:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " < ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_LTE:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " <= ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_GT:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " > ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_GTE:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " >= ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_AND:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " & ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_OR:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " | ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_QUES:
out << "(";
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " ? ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_COLON:
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << " : ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
break;
case O_COMMA:
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ", ";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
break;
case O_DEFINE:
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << '=';
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
break;
case O_EVAL:
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << "(";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << ")";
break;
case O_FIND:
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << "/";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
break;
case O_RFIND:
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << "//";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
break;
case O_PRED:
if (left() && left()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (left() && left()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << "[";
if (right() && right()->print(out, relaxed, op_to_find, start_pos, end_pos))
if (right() && right()->print(out, document, relaxed, op_to_find, start_pos, end_pos))
found = true;
out << "]";
break;

View file

@ -311,7 +311,7 @@ public:
value_t& as_value() {
assert(kind == VALUE);
value_t * val = boost::get<scoped_ptr<value_t> >(data).get();
value_t * val = boost::get<shared_ptr<value_t> >(data).get();
assert(val);
return *val;
}
@ -418,6 +418,7 @@ public:
static ptr_op_t defer_sequence(value_t::sequence_t& result_seq);
bool print(std::ostream& out,
document_t& document,
const bool relaxed = true,
const ptr_op_t& op_to_find = NULL,
unsigned long * start_pos = NULL,
@ -510,12 +511,13 @@ public:
}
bool print(std::ostream& out,
document_t& document,
const bool relaxed,
const ptr_op_t op_to_find,
unsigned long * start_pos,
unsigned long * end_pos) const {
if (ptr)
ptr->print(out, relaxed, op_to_find, start_pos, end_pos);
ptr->print(out, document, relaxed, op_to_find, start_pos, end_pos);
return true;
}
@ -613,8 +615,8 @@ public:
return temp.calc(top, scope);
}
void print(std::ostream& out) const {
print(out, true, NULL, NULL, NULL);
void print(std::ostream& out, xml::document_t& document) const {
print(out, document, true, NULL, NULL, NULL);
}
void dump(std::ostream& out) const {
if (ptr)
@ -624,11 +626,6 @@ public:
friend class scope_t;
};
inline std::ostream& operator<<(std::ostream& out, const xpath_t::op_t& op) {
op.print(out);
return out;
}
inline void intrusive_ptr_add_ref(xpath_t::op_t * op) {
op->acquire();
}