]> sourceware.org Git - systemtap.git/commitdiff
PR10719 cont'd: const-fold string concatenation
authorJosh Stone <jistone@redhat.com>
Wed, 24 Feb 2010 02:45:22 +0000 (18:45 -0800)
committerJosh Stone <jistone@redhat.com>
Wed, 24 Feb 2010 03:11:30 +0000 (19:11 -0800)
We can concat literal strings directly and discard empty strings.

* elaborate.cxx (const_folder::visit_concatenation): Implement.

elaborate.cxx

index 4e5c63c8ef92743ad1798d0f6bcfa8266388bf67..565d1b86c9bb7bc06428cdd6e395c2d88700a794 100644 (file)
@@ -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
This page took 0.031695 seconds and 5 git commands to generate.