From: Josh Stone Date: Wed, 24 Feb 2010 02:45:22 +0000 (-0800) Subject: PR10719 cont'd: const-fold string concatenation X-Git-Tag: release-1.2~175 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=29b1a9b7ff6ccff926e47c1077ea6089d3307a65;p=systemtap.git PR10719 cont'd: const-fold string concatenation We can concat literal strings directly and discard empty strings. * elaborate.cxx (const_folder::visit_concatenation): Implement. --- diff --git a/elaborate.cxx b/elaborate.cxx index 4e5c63c8e..565d1b86c 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