示例#1
0
 public static ICFunction AddNodeToList(ICFunction ret)
 {
     // If this node already exists use the existing one and ignore this one!
     if (BaseFunction.AllNodes.ContainsKey(ret)) return BaseFunction.AllNodes[ret];
     BaseFunction.AllNodes[ret] = ret;
     return ret;
 }
示例#2
0
 public void SetComplexFunctions(string functionString, NodeLabelCallback FunctionCallback, string seperator)
 {
     string[]     ss  = functionString.Split(new string[] { seperator }, StringSplitOptions.None);
     ICFunction[] cft = new ICFunction[ss.Length];
     for (int i = 0; i < ss.Length; i++)
     {
         cft[i] = BaseFunction.CreateNode(ss[i], FunctionCallback);
     }
     ComplexFunctions = cft;
 }
示例#3
0
 public static ICFunction AddNodeToList(ICFunction ret)
 {
     // If this node already exists use the existing one and ignore this one!
     if (BaseFunction.AllNodes.ContainsKey(ret))
     {
         return(BaseFunction.AllNodes[ret]);
     }
     BaseFunction.AllNodes[ret] = ret;
     return(ret);
 }
示例#4
0
 public static void SetCallbackFunction(ICFunction function, NodeLabelCallback callback)
 {
     if (function is OutsourcedFunction)
     {
         (function as OutsourcedFunction).Callback = callback;
     }
     foreach (ICFunction child in function.Children)
     {
         SetCallbackFunction(child, callback);
     }
 }
        private void writeFunctionDefinition(StreamWriter writer, ICFunction method, string mockClassName)
        {
            List<string> arguments = functionArgumentTypes(method);
            arguments.RemoveAll(str => String.IsNullOrEmpty(str));
            string returntype = "void";
            if (string.IsNullOrWhiteSpace(method.ReturnValue.Name) == false)
            {
                returntype = method.ReturnValue.Name;
            }
            writer.Write(returnFunctionHeader(method.Name));
            string parameters = "";

            if (arguments.Count() > 0)
            {
                writer.Write(returntype + " " + method.Name + "");
                int count = 0;
                List<string> withValues = new List<string>();
                List<string> Values = new List<string>();
                foreach (string argument in arguments)
                {
                    withValues.Add(argument + " l_arg" + count);
                    Values.Add(" l_arg" + count);
                    count++;
                }
                writer.Write("(" + String.Join(",", withValues.ToArray()) + ")");
                parameters = String.Join(",", Values.ToArray());

            }
            else
            {
                writer.WriteLine(returntype + " " + method.Name + "()");

            }
            writer.WriteLine("{");
            if (returntype != "void")
            {
                writer.WriteLine("  if(NULL != " + mockClassName + "::mp_Instance)");
                writer.WriteLine("  {");
                writer.WriteLine("    return " + mockClassName + "::mp_Instance->mocked_" + method.Name + "(" + parameters + ");");
                writer.WriteLine("  }");
                writer.WriteLine("  else");
                writer.WriteLine("  {");
                writer.WriteLine("    " + mockClassName + " l_MockObject;");

                writer.WriteLine("    return l_MockObject.mocked_" + method.Name + "(" + parameters + ");");
                writer.WriteLine("  }");
            }
            else
            {
                writer.WriteLine("  if(NULL != " + mockClassName + "::mp_Instance)");
                writer.WriteLine("  {");
                writer.WriteLine("     " + mockClassName + "::mp_Instance->mocked_" + method.Name + "(" + parameters + ");");
                writer.WriteLine("  }");
                writer.WriteLine("  else");
                writer.WriteLine("  {");
                writer.WriteLine("    " + mockClassName + " l_MockObject;");
                writer.WriteLine("      l_MockObject.mocked_" + method.Name + "(" + parameters + ");");
                writer.WriteLine("  }");
            }

            writer.WriteLine("}");
        }
 private List<string> functionArgumentTypes(ICFunction function)
 {
     List<string> arguments = new List<string>();
     foreach (ICVariable param in function.Parameters)
     {
         arguments.Add(param.Type.Name);
     }
     return arguments;
 }
示例#7
0
 public static string FunctionsToString(ICFunction[] ComplexFunctions, string seperator)
 {
     string s = "";
     if (ComplexFunctions == null || ComplexFunctions.Length < 1) return s;
     s += "" + ComplexFunctions[0];
     for (int i = 1; i < ComplexFunctions.Length; i++)
         s += seperator + ComplexFunctions[i];
     return s;
 }
示例#8
0
        TreeNode getFunctionNode(ICFunction function)
        {
            TreeNode functionNode = new TreeNode(function.Name);
            try
            {

                functionNode.Tag = function;
                functionNode.ImageIndex = 1;
                functionNode.SelectedImageIndex = 1;

                TreeNode returnNode = new TreeNode(function.ReturnValue.Name);
                returnNode.Tag = function.ReturnValue;
                returnNode.ImageIndex = 2;
                returnNode.SelectedImageIndex = 2;
                functionNode.Nodes.Add(returnNode);
                foreach (ICVariable arg in function.Parameters)
                {
                    TreeNode argument = new TreeNode(arg.Type.Name + ":" + arg.Name);
                    argument.Tag = arg;
                    argument.ImageIndex = 3;
                    argument.SelectedImageIndex = 3;
                    functionNode.Nodes.Add(argument);

                }
                TreeNode Called = new TreeNode("CalledFunctions");

                foreach (ICFunction calledFunction in function.CalledFunctions)
                {

                    Called.Nodes.Add(getcalledFunctionNode(calledFunction));
                }

                TreeNode LocalVariables = new TreeNode("LocalVariables");
                foreach (ICVariable variable in function.LocalVariables)
                {
                    TreeNode variableNode1 = new TreeNode(variable.Name);
                    variableNode1.Tag = variable;
                    variableNode1.ImageIndex = 5;
                    variableNode1.SelectedImageIndex = 5;
                    LocalVariables.Nodes.Add(variableNode1);
                }

                functionNode.Nodes.Add(LocalVariables);
                functionNode.Nodes.Add(Called);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
            return functionNode;
        }
示例#9
0
        TreeNode getcalledFunctionNode(ICFunction function)
        {
            TreeNode functionNode1 = new TreeNode(function.Name);
            try
            {

                functionNode1.Tag = function;
                functionNode1.ImageIndex = 6;
                functionNode1.SelectedImageIndex = 6;
                TreeNode returnNode1 = new TreeNode(function.ReturnValue.Name);
                returnNode1.Tag = function.ReturnValue;
                returnNode1.ImageIndex = 2;
                returnNode1.SelectedImageIndex = 2;
                functionNode1.Nodes.Add(returnNode1);
                foreach (ICVariable arg in function.Parameters)
                {
                    if (null != arg)
                    {
                        if (arg.Type != null)
                        {
                            TreeNode argument1 = new TreeNode(arg.Type.Name + ":" + arg.Name);
                            argument1.Tag = arg;
                            argument1.ImageIndex = 3;
                            argument1.SelectedImageIndex = 3;
                            functionNode1.Nodes.Add(argument1);
                        }
                    }

                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
            return functionNode1;
        }
示例#10
0
 public void SetComplexFunctions(string functionString, NodeLabelCallback FunctionCallback, string seperator)
 {
     string[] ss = functionString.Split(new string[] { seperator }, StringSplitOptions.None);
     ICFunction[] cft = new ICFunction[ss.Length];
     for (int i = 0; i < ss.Length; i++)
     {
         cft[i] = BaseFunction.CreateNode(ss[i], FunctionCallback);
     }
     ComplexFunctions = cft;
 }
示例#11
0
 public static void SetCallbackFunction(ICFunction function, NodeLabelCallback callback)
 {
     if (function is OutsourcedFunction)
         (function as OutsourcedFunction).Callback = callback;
     foreach (ICFunction child in function.Children)
         SetCallbackFunction(child, callback);
 }
示例#12
0
        public static ICFunction CreateNode(string label, NodeLabelCallback callBack)
        {
            label = removeWhitespace(label);
            ICFunction ret;

            // if it has an '=' then it's a variable.
            // Rearrange X = Y into Var(X,Y) format.
            if (label.Contains("="))
            {
                string[] pars = label.Split(new char[] { '=' });
                label = "Var(" + pars[0] + "," + pars[1] + ")";
            }

            // Split on first '('
            string[] split = label.Split(new char[] { '(' }, 2);
            ret = GetFunctionFromLabel(split[0]);
            // If null, then it's either a constant or node.
            if (split.Length < 2 || ret == null)
            {
                ret = ConstantFunction.CreateConstantFunction(label, split[0]);
                if (ret != null)
                {
                    return(AddNodeToList(ret));
                }
                ret = OutsourcedFunction.CreateOutsourcedFunction(split[0], callBack);
                if (ret != null)
                {
                    return(AddNodeToList(ret));
                }
            }
            // Now need to find children represented by remainder of split: split[1]
            // eg "4,5,Sub(3,4))"
            List <ICFunction> children = new List <ICFunction>();
            string            child    = "";
            int relevance = 0;

            foreach (char c in split[1])
            {
                if (c == '(')
                {
                    relevance++;
                }
                if (c == ')')
                {
                    relevance--;
                }
                child += c;
                if (relevance == 0)
                {
                    if (c == ')')
                    {
                        child = child.TrimEnd(new char[] { ')' });
                        if (child.Length > 0)
                        {
                            ICFunction icf = CreateNode(child, callBack);
                            children.Add(icf);
                        }
                        child = "";
                    }
                    if (c == ',')
                    {
                        child = child.TrimEnd(new char[] { ',' });
                        if (child.Length > 0)
                        {
                            ICFunction icf = CreateNode(child, callBack);
                            children.Add(icf);
                        }
                        child = "";
                    }
                }
            }
            child = child.TrimEnd(new char[] { ',', ')' });
            if (child.Length > 0)
            {
                ICFunction icff = CreateNode(child, callBack);
                children.Add(icff);
            }
            ret.Children = children;

            return(AddNodeToList(ret));
        }