Support nested parenthesis in peephole function arguments (#1967300)
[fw/sdcc] / src / SDCCpeeph.c
index 075cad2abc12af5ba428411386de4a84553bac5b..e413d49930edb78bdfff6292ef757c5aa3eae650 100644 (file)
@@ -1269,9 +1269,18 @@ callFuncByName (char *fname,
       /* and there can be no additional conditions.             */
       if (c == '(')
         {
-          cmdTerm = funcArgs;
-          while ((c = *cmdTerm) && c != ')')
-            cmdTerm++;
+
+          int num_parenthesis = 0;
+          cmdTerm = funcArgs;          
+
+          while ((c = *cmdTerm) && (c != ')' || num_parenthesis))
+            {
+              if (c == '(')
+                num_parenthesis++;
+              else if (c == ')')
+                num_parenthesis--;
+              cmdTerm++;
+            }
           *cmdTerm = '\0';  /* terminate the arguments */
           if (c == ')')
             {