public void CreateStringLengthMethod()
        {
            List <TypeSpecifier> argumentTypes = new List <TypeSpecifier>()
            {
                typeof(string),
            };

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

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

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

            // Create nodes
            VariableGetterNode getLengthNode = new VariableGetterNode(stringLengthMethod, typeof(string), "Length", typeof(int));

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

            // Connect node data
            GraphUtil.ConnectDataPins(stringLengthMethod.EntryNode.OutputDataPins[0], getLengthNode.InputDataPins[0]);
            GraphUtil.ConnectDataPins(getLengthNode.OutputDataPins[0], stringLengthMethod.ReturnNode.InputDataPins[0]);
        }
Example #2
0
        public void CreateStringLengthMethod()
        {
            List <TypeSpecifier> returnTypes = new List <TypeSpecifier>()
            {
                TypeSpecifier.FromType <int>(),
            };

            // Create method
            stringLengthMethod = new Method("StringLength")
            {
                Class     = cls,
                Modifiers = MethodModifiers.Public
            };

            stringLengthMethod.ReturnTypes.AddRange(returnTypes);

            // Create nodes
            VariableGetterNode getStringNode = new VariableGetterNode(stringLengthMethod, cls.Type, new Variable("testVariable", TypeSpecifier.FromType <string>()));
            VariableGetterNode getLengthNode = new VariableGetterNode(stringLengthMethod, cls.Type, new Variable("Length", TypeSpecifier.FromType <int>()));

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

            // Connect node data
            GraphUtil.ConnectDataPins(getStringNode.ValuePin, getLengthNode.TargetPin);
            GraphUtil.ConnectDataPins(getLengthNode.ValuePin, stringLengthMethod.ReturnNodes.First().InputDataPins[0]);
        }
        public void CreateStringLengthMethod()
        {
            // Create method
            stringLengthMethod = new MethodGraph("StringLength")
            {
                Class     = cls,
                Modifiers = MethodModifiers.None
            };

            List <TypeNode> returnTypeNodes = new List <TypeNode>()
            {
                new TypeNode(stringLengthMethod, TypeSpecifier.FromType <int>()),
            };

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

            TypeSpecifier stringType = TypeSpecifier.FromType <string>();
            TypeSpecifier intType    = TypeSpecifier.FromType <int>();

            // Create nodes
            VariableGetterNode getStringNode = new VariableGetterNode(stringLengthMethod, new VariableSpecifier("testVariable", stringType, MemberVisibility.Public, MemberVisibility.Public, stringType, VariableModifiers.None));
            VariableGetterNode getLengthNode = new VariableGetterNode(stringLengthMethod, new VariableSpecifier("Length", intType, MemberVisibility.Public, MemberVisibility.Public, stringType, VariableModifiers.None));

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

            // Connect node data
            GraphUtil.ConnectDataPins(getStringNode.ValuePin, getLengthNode.TargetPin);
            GraphUtil.ConnectDataPins(getLengthNode.ValuePin, stringLengthMethod.ReturnNodes.First().InputDataPins[0]);
        }
        public void CreateStringLengthMethod()
        {
            List <TypeSpecifier> argumentTypes = new List <TypeSpecifier>()
            {
                TypeSpecifier.FromType <string>(),
            };

            // Create method
            stringLengthMethod = new Method("StringLength")
            {
                Visibility = MemberVisibility.Public
            };

            // Add arguments
            List <TypeNode> argTypeNodes = new List <TypeNode>()
            {
                new TypeNode(stringLengthMethod, TypeSpecifier.FromType <string>()),
            };

            for (int i = 0; i < argTypeNodes.Count; i++)
            {
                stringLengthMethod.EntryNode.AddArgument();
                GraphUtil.ConnectTypePins(argTypeNodes[i].OutputTypePins[0], stringLengthMethod.EntryNode.InputTypePins[i]);
            }

            // Add return types
            List <TypeNode> returnTypeNodes = new List <TypeNode>()
            {
                new TypeNode(stringLengthMethod, TypeSpecifier.FromType <int>()),
            };

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

            // Create nodes
            var getLengthNode = new VariableGetterNode(stringLengthMethod, new VariableSpecifier("Length", TypeSpecifier.FromType <int>(),
                                                                                                 MemberVisibility.Public, MemberVisibility.Public, TypeSpecifier.FromType <string>(), VariableModifiers.None));

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

            // Connect node data
            GraphUtil.ConnectDataPins(stringLengthMethod.EntryNode.OutputDataPins[0], getLengthNode.InputDataPins[0]);
            GraphUtil.ConnectDataPins(getLengthNode.OutputDataPins[0], stringLengthMethod.ReturnNodes.First().InputDataPins[0]);
        }
Example #5
0
        public void PureTranslateVariableGetterNode(VariableGetterNode node)
        {
            string valueName = GetOrCreatePinName(node.OutputDataPins[0]);

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

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

            builder.AppendLine($"{node.VariableName};");
        }