Beispiel #1
0
        public void PureTranslateMakeDelegateNode(MakeDelegateNode node)
        {
            // Write assignment of return value
            string returnName = GetOrCreatePinName(node.OutputDataPins[0]);

            builder.Append($"{returnName} = ");

            // Static: Write class name / target, default to own class name
            // Instance: Write target, default to this

            if (node.IsFromStaticMethod)
            {
                builder.Append($"{node.MethodSpecifier.DeclaringType}.");
            }
            else
            {
                if (node.TargetPin.IncomingPin != null)
                {
                    string targetName = GetOrCreatePinName(node.TargetPin.IncomingPin);
                    builder.Append($"{targetName}.");
                }
                else
                {
                    // Default to thise
                    builder.Append("this.");
                }
            }

            // Write method name
            builder.AppendLine($"{node.MethodSpecifier.Name};");
        }
        public void TestDelegate()
        {
            // Create method
            Method delegateMethod = new Method("DelegateMethod")
            {
                Visibility = MemberVisibility.Public
            };

            List <TypeNode> returnTypeNodes = new List <TypeNode>()
            {
                new TypeNode(delegateMethod, TypeSpecifier.FromType <Func <int, string, float> >()),
            };

            for (int i = 0; i < returnTypeNodes.Count; i++)
            {
                delegateMethod.MainReturnNode.AddReturnType();
                GraphUtil.ConnectTypePins(returnTypeNodes[i].OutputTypePins[0], delegateMethod.MainReturnNode.InputTypePins[i]);
            }

            MethodSpecifier delegateMethodSpecifier = new MethodSpecifier("TestMethod",
                                                                          new MethodParameter[]
            {
                new MethodParameter("arg1", TypeSpecifier.FromType <int>(), MethodParameterPassType.Default),
                new MethodParameter("arg2", TypeSpecifier.FromType <string>(), MethodParameterPassType.Default)
            },
                                                                          new BaseType[] { TypeSpecifier.FromType <float>() },
                                                                          MethodModifiers.Static, MemberVisibility.Public,
                                                                          TypeSpecifier.FromType <double>(), Array.Empty <BaseType>());

            // Create nodes
            MakeDelegateNode makeDelegateNode = new MakeDelegateNode(delegateMethod, delegateMethodSpecifier);

            // Connect node execs
            GraphUtil.ConnectExecPins(delegateMethod.EntryNode.InitialExecutionPin, delegateMethod.ReturnNodes.First().ReturnPin);

            // Connect node data
            GraphUtil.ConnectDataPins(makeDelegateNode.OutputDataPins[0], delegateMethod.ReturnNodes.First().InputDataPins[0]);

            string translated = methodTranslator.Translate(delegateMethod, true);
        }
Beispiel #3
0
        public void TestDelegate()
        {
            List <TypeSpecifier> argumentTypes = new List <TypeSpecifier>()
            {
            };

            List <TypeSpecifier> returnTypes = new List <TypeSpecifier>()
            {
                typeof(Func <int, string, float>)
            };

            // Create method
            Method delegateMethod = new Method("DelegateMethod")
            {
                Modifiers = MethodModifiers.Public
            };

            delegateMethod.ArgumentTypes.AddRange(argumentTypes);
            delegateMethod.ReturnTypes.AddRange(returnTypes);

            MethodSpecifier delegateMethodSpecifier = new MethodSpecifier("TestMethod",
                                                                          new BaseType[] { typeof(int), typeof(string) },
                                                                          new BaseType[] { typeof(float) },
                                                                          MethodModifiers.Static,
                                                                          typeof(double),
                                                                          Array.Empty <BaseType>());

            // Create nodes
            MakeDelegateNode makeDelegateNode = new MakeDelegateNode(delegateMethod, delegateMethodSpecifier);

            // Connect node execs
            GraphUtil.ConnectExecPins(delegateMethod.EntryNode.InitialExecutionPin, delegateMethod.ReturnNode.ReturnPin);

            // Connect node data
            GraphUtil.ConnectDataPins(makeDelegateNode.OutputDataPins[0], delegateMethod.ReturnNode.InputDataPins[0]);

            string translated = methodTranslator.Translate(delegateMethod);
        }
Beispiel #4
0
        public void TestDelegate()
        {
            List <TypeSpecifier> argumentTypes = new List <TypeSpecifier>()
            {
            };

            List <TypeSpecifier> returnTypes = new List <TypeSpecifier>()
            {
                TypeSpecifier.FromType <Func <int, string, float> >(),
            };

            // Create method
            Method delegateMethod = new Method("DelegateMethod")
            {
                Modifiers = MethodModifiers.Public
            };

            delegateMethod.ArgumentTypes.AddRange(argumentTypes);
            delegateMethod.ReturnTypes.AddRange(returnTypes);

            MethodSpecifier delegateMethodSpecifier = new MethodSpecifier("TestMethod",
                                                                          new Named <BaseType>[] { new Named <BaseType>("arg1", TypeSpecifier.FromType <int>()), new Named <BaseType>("arg2", TypeSpecifier.FromType <string>()) },
                                                                          new BaseType[] { TypeSpecifier.FromType <float>() },
                                                                          MethodModifiers.Static,
                                                                          TypeSpecifier.FromType <double>(),
                                                                          Array.Empty <BaseType>());

            // Create nodes
            MakeDelegateNode makeDelegateNode = new MakeDelegateNode(delegateMethod, delegateMethodSpecifier);

            // Connect node execs
            GraphUtil.ConnectExecPins(delegateMethod.EntryNode.InitialExecutionPin, delegateMethod.ReturnNodes.First().ReturnPin);

            // Connect node data
            GraphUtil.ConnectDataPins(makeDelegateNode.OutputDataPins[0], delegateMethod.ReturnNodes.First().InputDataPins[0]);

            string translated = methodTranslator.Translate(delegateMethod);
        }