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]); }
public void CreateIfElseMethod() { List <TypeSpecifier> argumentTypes = new List <TypeSpecifier>() { TypeSpecifier.FromType <int>(), TypeSpecifier.FromType <bool>(), }; List <TypeSpecifier> returnTypes = new List <TypeSpecifier>() { TypeSpecifier.FromType <int>(), }; // Create method ifElseMethod = new Method("IfElse") { Modifiers = MethodModifiers.Public }; ifElseMethod.ArgumentTypes.AddRange(argumentTypes); ifElseMethod.ReturnTypes.AddRange(returnTypes); // Create nodes IfElseNode ifElseNode = new IfElseNode(ifElseMethod); LiteralNode literalNode = LiteralNode.WithValue(ifElseMethod, 123); // Connect exec nodes GraphUtil.ConnectExecPins(ifElseMethod.EntryNode.InitialExecutionPin, ifElseNode.ExecutionPin); GraphUtil.ConnectExecPins(ifElseNode.TruePin, ifElseMethod.ReturnNodes.First().ReturnPin); GraphUtil.ConnectExecPins(ifElseNode.FalsePin, ifElseMethod.ReturnNodes.First().ReturnPin); // Connect node data GraphUtil.ConnectDataPins(ifElseMethod.EntryNode.OutputDataPins[1], ifElseNode.ConditionPin); GraphUtil.ConnectDataPins(ifElseMethod.EntryNode.OutputDataPins[0], ifElseMethod.ReturnNodes.First().InputDataPins[0]); GraphUtil.ConnectDataPins(literalNode.ValuePin, ifElseMethod.ReturnNodes.First().InputDataPins[0]); }
public void CreateIfElseMethod() { // Create method ifElseMethod = new Method("IfElse") { Visibility = MemberVisibility.Public }; // Add arguments List <TypeNode> argTypeNodes = new List <TypeNode>() { new TypeNode(ifElseMethod, TypeSpecifier.FromType <int>()), new TypeNode(ifElseMethod, TypeSpecifier.FromType <bool>()), }; for (int i = 0; i < argTypeNodes.Count; i++) { ifElseMethod.EntryNode.AddArgument(); GraphUtil.ConnectTypePins(argTypeNodes[i].OutputTypePins[0], ifElseMethod.EntryNode.InputTypePins[i]); } // Add return types List <TypeNode> returnTypeNodes = new List <TypeNode>() { new TypeNode(ifElseMethod, TypeSpecifier.FromType <int>()), }; for (int i = 0; i < returnTypeNodes.Count; i++) { ifElseMethod.MainReturnNode.AddReturnType(); GraphUtil.ConnectTypePins(returnTypeNodes[i].OutputTypePins[0], ifElseMethod.MainReturnNode.InputTypePins[i]); } // Create nodes IfElseNode ifElseNode = new IfElseNode(ifElseMethod); LiteralNode literalNode = LiteralNode.WithValue(ifElseMethod, 123); // Connect exec nodes GraphUtil.ConnectExecPins(ifElseMethod.EntryNode.InitialExecutionPin, ifElseNode.ExecutionPin); GraphUtil.ConnectExecPins(ifElseNode.TruePin, ifElseMethod.ReturnNodes.First().ReturnPin); GraphUtil.ConnectExecPins(ifElseNode.FalsePin, ifElseMethod.ReturnNodes.First().ReturnPin); // Connect node data GraphUtil.ConnectDataPins(ifElseMethod.EntryNode.OutputDataPins[1], ifElseNode.ConditionPin); GraphUtil.ConnectDataPins(ifElseMethod.EntryNode.OutputDataPins[0], ifElseMethod.ReturnNodes.First().InputDataPins[0]); GraphUtil.ConnectDataPins(literalNode.ValuePin, ifElseMethod.ReturnNodes.First().InputDataPins[0]); }
public void CreateForLoopMethod() { // Create method forLoopMethod = new Method("ForLoop") { Visibility = MemberVisibility.Public }; // Create nodes LiteralNode maxIndexLiteralNode = LiteralNode.WithValue(forLoopMethod, 10); ForLoopNode forLoopNode = new ForLoopNode(forLoopMethod); // Connect exec nodes GraphUtil.ConnectExecPins(forLoopMethod.EntryNode.InitialExecutionPin, forLoopNode.ExecutionPin); GraphUtil.ConnectExecPins(forLoopNode.CompletedPin, forLoopMethod.ReturnNodes.First().ReturnPin); // Connect node data GraphUtil.ConnectDataPins(maxIndexLiteralNode.ValuePin, forLoopNode.MaxIndexPin); }