diff options
author | Josh Stone <jistone@redhat.com> | 2010-02-23 18:45:22 -0800 |
---|---|---|
committer | Josh Stone <jistone@redhat.com> | 2010-02-23 19:11:30 -0800 |
commit | 29b1a9b7ff6ccff926e47c1077ea6089d3307a65 (patch) | |
tree | 996e12b308b7059c25abcc8f42d0bc0eabac8b55 /elaborate.cxx | |
parent | c7005ee1ba902de01a8863661a2031bfd45d3d40 (diff) | |
download | systemtap-steved-29b1a9b7ff6ccff926e47c1077ea6089d3307a65.tar.gz systemtap-steved-29b1a9b7ff6ccff926e47c1077ea6089d3307a65.tar.xz systemtap-steved-29b1a9b7ff6ccff926e47c1077ea6089d3307a65.zip |
PR10719 cont'd: const-fold string concatenation
We can concat literal strings directly and discard empty strings.
* elaborate.cxx (const_folder::visit_concatenation): Implement.
Diffstat (limited to 'elaborate.cxx')
-rw-r--r-- | elaborate.cxx | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/elaborate.cxx b/elaborate.cxx index 4e5c63c8..565d1b86 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -3166,8 +3166,30 @@ const_folder::visit_comparison (comparison* e) void const_folder::visit_concatenation (concatenation* e) { - // TODO - update_visitor::visit_concatenation (e); + literal_string* left = get_string (e->left); + literal_string* right = get_string (e->right); + + if (left && right) + { + if (session.verbose>2) + clog << "Collapsing constant concatenation " << *e->tok << endl; + relaxed_p = false; + + literal_string* n = new literal_string (*left); + n->tok = e->tok; + n->value.append(right->value); + n->visit (this); + } + else if ((left && left->value.empty()) || + (right && right->value.empty())) + { + if (session.verbose>2) + clog << "Collapsing identity concatenation " << *e->tok << endl; + relaxed_p = false; + provide(left ? e->right : e->left); + } + else + provide (e); } void |