Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref / out params and loops #15

Open
twiglet opened this issue May 2, 2011 · 1 comment
Open

ref / out params and loops #15

twiglet opened this issue May 2, 2011 · 1 comment
Labels

Comments

@twiglet
Copy link
Owner

twiglet commented May 2, 2011

We don't properly handle ref / out params that are passed via calls in expressions in while conditions, switch scrutinees etc.

e.g.

while ( funReturnBool(ref param)) {

}
@twiglet
Copy link
Owner Author

twiglet commented Sep 3, 2012

class TC {

        public TC() {}

        public bool TCtest1(out string modifiedUrlString, string urlString){
        modifiedUrlString = urlString.ToUpper();
    return false;
    }

        public bool TCtest2(out string user, out string passwd, string urlString){
        user = urlString.ToUpper();
        passwd = urlString.ToLower();
    return true;
    }


        public void TCtest(string urlString)
        {

            string modifiedUrlString=null;
            string engineAuthUser=null;
            string engineAuthPassword=null;

            if (TCtest1(out modifiedUrlString, urlString))
            {
                System.Console.WriteLine(modifiedUrlString);
            }
            else if (TCtest2(out engineAuthUser, out engineAuthPassword, urlString))
            {
                if (!String.IsNullOrEmpty(engineAuthUser) && !String.IsNullOrEmpty(engineAuthPassword))
                {
                    System.Console.WriteLine(engineAuthUser + engineAuthPassword);
                }
                else
                {
                    System.Console.WriteLine("Null or Null");
                }
            }
            else
            {
            System.Console.WriteLine("They really didn't like us");
            }
        }

        public void TCtest_workaround(string urlString)
        {

            string modifiedUrlString=null;
            string engineAuthUser=null;
            string engineAuthPassword=null;

    bool optTCTest1 = TCtest1(out modifiedUrlString, urlString);
            if (optTCTest1)
            {
                System.Console.WriteLine(modifiedUrlString);
            }
            else {
        bool optTCTest2 = TCtest2(out engineAuthUser, out engineAuthPassword, urlString);
        if (optTCTest2)
                {
        if (!String.IsNullOrEmpty(engineAuthUser) && !String.IsNullOrEmpty(engineAuthPassword))
                    {
            System.Console.WriteLine(engineAuthUser + engineAuthPassword);
                    }
                    else
                    {
            System.Console.WriteLine("Null or Null");
                    }
        }
                else
                {
                    System.Console.WriteLine("They really didn't like us");
                }
           }
        }

gives

//

package Tester.RefOut;

import CS2JNet.JavaSupport.language.RefSupport;
import CS2JNet.System.StringSupport;

public class TC
{
public TC() throws Exception {
}

public boolean tCtest1(RefSupport<String> modifiedUrlString, String urlString) throws Exception {
    modifiedUrlString.setValue(urlString.toUpperCase());
    return false;
}

public boolean tCtest2(RefSupport<String> user, RefSupport<String> passwd, String urlString) throws Exception {
    user.setValue(urlString.toUpperCase());
    passwd.setValue(urlString.toLowerCase());
    return true;
}

public void tCtest(String urlString) throws Exception {
    String modifiedUrlString = null;
    String engineAuthUser = null;
    String engineAuthPassword = null;
    boolean boolVar___0 = tCtest1(refVar___0,urlString);
    if (boolVar___0)
    {
        System.out.println(modifiedUrlString);
    }
    else
    {
        RefSupport<String> refVar___0 = new RefSupport<String>();
        RefSupport<String> refVar___1 = new RefSupport<String>();
        RefSupport<String> refVar___2 = new RefSupport<String>();
        boolean boolVar___1 = tCtest2(refVar___1,refVar___2,urlString);
        modifiedUrlString = refVar___0.getValue();
        engineAuthUser = refVar___1.getValue();
        engineAuthPassword = refVar___2.getValue();
        if (boolVar___1)
        {
            if (!StringSupport.isNullOrEmpty(engineAuthUser) && !StringSupport.isNullOrEmpty(engineAuthPassword))
            {
                System.out.println(engineAuthUser + engineAuthPassword);
            }
            else
            {
                System.out.println("Null or Null");
            } 
        }
        else
        {
            System.out.println("They really didn't like us");
        } 
    } 
}

public void tCtest_workaround(String urlString) throws Exception {
    String modifiedUrlString = null;
    String engineAuthUser = null;
    String engineAuthPassword = null;
    RefSupport<String> refVar___3 = new RefSupport<String>();
    boolean optTCTest1 = tCtest1(refVar___3,urlString);
    modifiedUrlString = refVar___3.getValue();
    if (optTCTest1)
    {
        System.out.println(modifiedUrlString);
    }
    else
    {
        RefSupport<String> refVar___4 = new RefSupport<String>();
        RefSupport<String> refVar___5 = new RefSupport<String>();
        boolean optTCTest2 = tCtest2(refVar___4,refVar___5,urlString);
        engineAuthUser = refVar___4.getValue();
        engineAuthPassword = refVar___5.getValue();
        if (optTCTest2)
        {
            if (!StringSupport.isNullOrEmpty(engineAuthUser) && !StringSupport.isNullOrEmpty(engineAuthPassword))
            {
                System.out.println(engineAuthUser + engineAuthPassword);
            }
            else
            {
                System.out.println("Null or Null");
            } 
        }
        else
        {
            System.out.println("They really didn't like us");
        } 
    } 
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant