示例#1
0
        public void CreateMainMethod()
        {
            mainMethod = new Method("Main")
            {
                Class     = cls,
                Modifiers = MethodModifiers.Static
            };

            MethodSpecifier stringLengthSpecifier = new MethodSpecifier("StringLength", new Named <BaseType> [0], new List <TypeSpecifier>()
            {
                TypeSpecifier.FromType <int>()
            }, MethodModifiers.Public, TypeSpecifier.FromType <string>(), Array.Empty <BaseType>());
            //MethodSpecifier writeConsoleSpecifier = typeof(Console).GetMethods().Single(m => m.Name == "WriteLine" && m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == typeof(string));
            TypeSpecifier   stringType            = TypeSpecifier.FromType <string>();
            MethodSpecifier writeConsoleSpecifier = new MethodSpecifier("WriteLine", new Named <BaseType>[] { new Named <BaseType>("argName", stringType) }, new BaseType[0], MethodModifiers.Public, TypeSpecifier.FromType(typeof(Console)), new BaseType[0]);

            // Create nodes
            LiteralNode        stringLiteralNode   = LiteralNode.WithValue(mainMethod, "Hello World");
            VariableSetterNode setStringNode       = new VariableSetterNode(mainMethod, cls.Type, new Variable("testVariable", TypeSpecifier.FromType <string>()));
            CallMethodNode     getStringLengthNode = new CallMethodNode(mainMethod, stringLengthSpecifier);
            CallMethodNode     writeConsoleNode    = new CallMethodNode(mainMethod, writeConsoleSpecifier);

            // Connect node execs
            GraphUtil.ConnectExecPins(mainMethod.EntryNode.InitialExecutionPin, setStringNode.InputExecPins[0]);
            GraphUtil.ConnectExecPins(setStringNode.OutputExecPins[0], getStringLengthNode.InputExecPins[0]);
            GraphUtil.ConnectExecPins(getStringLengthNode.OutputExecPins[0], writeConsoleNode.InputExecPins[0]);
            GraphUtil.ConnectExecPins(writeConsoleNode.OutputExecPins[0], mainMethod.ReturnNodes.First().InputExecPins[0]);

            // Connect node data
            GraphUtil.ConnectDataPins(stringLiteralNode.ValuePin, setStringNode.NewValuePin);
            GraphUtil.ConnectDataPins(getStringLengthNode.OutputDataPins[0], writeConsoleNode.ArgumentPins[0]);
        }
示例#2
0
        public void TranslateVariableSetterNode(VariableSetterNode node)
        {
            // Translate all the pure nodes this node depends on in
            // the correct order
            TranslateDependentPureNodes(node);

            string valueName = GetOrCreatePinName(node.InputDataPins[1].IncomingPin);

            // Add target name or this if not a local variable
            if (!node.IsLocalVariable)
            {
                if (node.InputDataPins[0].IncomingPin != null)
                {
                    string targetName = GetOrCreatePinName(node.InputDataPins[0].IncomingPin);
                    builder.Append($"{targetName}.");
                }
                else
                {
                    builder.Append("this.");
                }
            }

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

            // Set output pin of this node to the same value
            builder.AppendLine($"{GetOrCreatePinName(node.OutputDataPins[0])} = {valueName};");

            // Go to the next state
            WriteGotoOutputPin(node.OutputExecPins[0]);
        }
示例#3
0
        public void TranslateVariableSetterNode(VariableSetterNode node)
        {
            // Translate all the pure nodes this node depends on in
            // the correct order
            TranslateDependentPureNodes(node);

            string valueName = GetPinIncomingValue(node.NewValuePin);

            // Add target name if there is a target (null for local and static variables)
            if (node.IsStatic)
            {
                if (!(node.TargetType is null))
                {
                    builder.Append(node.TargetType.FullCodeName);
                }
                else
                {
                    builder.Append(node.Method.Class.Name);
                }
            }