summaryrefslogtreecommitdiffstats
path: root/translate.cxx
diff options
context:
space:
mode:
authorfche <fche>2005-06-03 21:01:35 +0000
committerfche <fche>2005-06-03 21:01:35 +0000
commit553d27a587615e4b242a89bf1a7af93b71f050f0 (patch)
tree1ca4e5d35908208e5d533bb32e22b6aa567221b8 /translate.cxx
parent63a7c90e365874972925e886ed50941f5620bdfe (diff)
downloadsystemtap-steved-553d27a587615e4b242a89bf1a7af93b71f050f0.tar.gz
systemtap-steved-553d27a587615e4b242a89bf1a7af93b71f050f0.tar.xz
systemtap-steved-553d27a587615e4b242a89bf1a7af93b71f050f0.zip
2005-06-03 Frank Ch. Eigler <fche@redhat.com>
* TODO: Removed entries already represented in bugzilla. * elaborate.cxx: Rewrite type inference for several operators. * main.cxx (main): For -p2 runs, print types of function/probe locals. * parse.cxx (scan): Identify more two-character operators. (parse_comparison): Support the whole suite. * translate.cxx (visit_unary_expression, logical_or_expr, logical_and_expr, comparison,ternary_expression): New support. * testsuite/parseok/semok.stp: Clever new test. * testsuite/transok/four.stp: New test. * testsuite/*: Some tweaked tests for syntax changes.
Diffstat (limited to 'translate.cxx')
-rw-r--r--translate.cxx86
1 files changed, 80 insertions, 6 deletions
diff --git a/translate.cxx b/translate.cxx
index f53e2952..972e188c 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -709,7 +709,7 @@ c_unparser::visit_binary_expression (binary_expression* e)
if (e->type != pe_long ||
e->left->type != pe_long ||
e->right->type != pe_long)
- throw semantic_error ("expected string types", e->tok);
+ throw semantic_error ("expected numeric types", e->tok);
o->line() << "(";
e->left->visit (this);
@@ -722,36 +722,66 @@ c_unparser::visit_binary_expression (binary_expression* e)
throw semantic_error ("not yet implemented", e->tok);
}
+
void
c_unparser::visit_unary_expression (unary_expression* e)
{
- throw semantic_error ("not yet implemented", e->tok);
+ if (e->type != pe_long ||
+ e->operand->type != pe_long)
+ throw semantic_error ("expected numeric types", e->tok);
+
+ o->line() << e->op << " (";
+ e->operand->visit (this);
+ o->line() << ")";
}
+
void
c_unparser::visit_pre_crement (pre_crement* e)
{
throw semantic_error ("not yet implemented", e->tok);
}
+
void
c_unparser::visit_post_crement (post_crement* e)
{
throw semantic_error ("not yet implemented", e->tok);
}
+
void
c_unparser::visit_logical_or_expr (logical_or_expr* e)
{
- throw semantic_error ("not yet implemented", e->tok);
+ if (e->type != pe_long ||
+ e->left->type != pe_long ||
+ e->right->type != pe_long)
+ throw semantic_error ("expected numeric types", e->tok);
+
+ o->line() << "(";
+ e->left->visit (this);
+ o->line() << ") " << e->op << " (";
+ e->right->visit (this);
+ o->line() << ")";
}
+
void
c_unparser::visit_logical_and_expr (logical_and_expr* e)
{
- throw semantic_error ("not yet implemented", e->tok);
+ if (e->type != pe_long ||
+ e->left->type != pe_long ||
+ e->right->type != pe_long)
+ throw semantic_error ("expected numeric types", e->tok);
+
+ o->line() << "(";
+ e->left->visit (this);
+ o->line() << ") " << e->op << " (";
+ e->right->visit (this);
+ o->line() << ")";
}
+
void
c_unparser::visit_array_in (array_in* e)
{
@@ -762,7 +792,37 @@ c_unparser::visit_array_in (array_in* e)
void
c_unparser::visit_comparison (comparison* e)
{
- throw semantic_error ("not yet implemented", e->tok);
+ o->line() << "(";
+
+ if (e->left->type == pe_string)
+ {
+ if (e->left->type != pe_string ||
+ e->right->type != pe_string)
+ throw semantic_error ("expected string types", e->tok);
+
+ o->line() << "strncmp (";
+ e->left->visit (this);
+ o->line() << ", ";
+ e->right->visit (this);
+ o->line() << ", MAXSTRINGLEN";
+ o->line() << ") " << e->op << " 0";
+ }
+ else if (e->left->type == pe_long)
+ {
+ if (e->left->type != pe_long ||
+ e->right->type != pe_long)
+ throw semantic_error ("expected numeric types", e->tok);
+
+ o->line() << "(";
+ e->left->visit (this);
+ o->line() << ") " << e->op << " (";
+ e->right->visit (this);
+ o->line() << ")";
+ }
+ else
+ throw semantic_error ("unexpected type", e->left->tok);
+
+ o->line() << ")";
}
@@ -811,7 +871,21 @@ c_unparser::visit_exponentiation (exponentiation* e)
void
c_unparser::visit_ternary_expression (ternary_expression* e)
{
- throw semantic_error ("not yet implemented", e->tok);
+ if (e->cond->type != pe_long)
+ throw semantic_error ("expected numeric condition", e->cond->tok);
+
+ if (e->truevalue->type != e->falsevalue->type ||
+ e->type != e->truevalue->type ||
+ (e->truevalue->type != pe_long && e->truevalue->type != pe_string))
+ throw semantic_error ("expected matching types", e->tok);
+
+ o->line() << "((";
+ e->cond->visit (this);
+ o->line() << ") ? (";
+ e->truevalue->visit (this);
+ o->line() << ") : (";
+ e->falsevalue->visit (this);
+ o->line() << "))";
}