private static void AddThrowException(SMCSharpGenerator gen, string evName, StringBuilder buff) { var exceptionName = gen.StateMap.ExceptionName; buff.Append($" throw new {exceptionName}") .AppendLine($"(\"{evName}\", {ArgName}.CurrentStateName);"); }
private static void AddErrorFuncCall(SMCSharpGenerator gen, string evName, StringBuilder buff) { var errorFunctionName = gen.StateMap.ErrorFunctionName; buff.Append($" {ArgName}.{errorFunctionName}") .AppendLine($"(\"{evName}\", {ArgName}.CurrentState);"); }
private static SMCSharpGenerator MakeGeneratorWith(Builder.FSMRepresentationBuilder fsmbld) { var fsm = new SMCSharpGenerator(); fsm.FSMInit(fsmbld.StateMap, "fileName"); fsm.Initialize(); return(fsm); }
private void AddOpenEventDeclaration(SMCSharpGenerator gen, string evName, StringBuilder buff) { var stateMachineClass = gen.StateMap.Name; var methodName = this.CreateMethodName(evName); buff.AppendLine($" public virtual void {methodName}({stateMachineClass} {ArgName})") .AppendLine(" {"); }
protected static SMCSharpGenerator InitWithBuilder(FSMRepresentationBuilder fsmbld) { var retval = new SMCSharpGenerator(); retval.FSMInit(fsmbld.StateMap, "fileName"); retval.Initialize(); return(retval); }
public void Paramaters() { FSMGenerator fsm = new SMCSharpGenerator(); fsm.FSMInit(new MutableStateMap(), "TurnStyle"); fsm.Initialize(); Assert.AreEqual("TurnStyle", fsm.InputFileName); Assert.AreEqual("TurnStyle", fsm.FilePrefix); }
public void ConcreteStates() { FSMRepresentationBuilder fsmbld = InitBuilderState(); StateMap map = fsmbld.StateMap; FSMGenerator fsm = new SMCSharpGenerator(); fsm.FSMInit(map, "TurnStyle"); fsm.Initialize(); Assert.AreEqual(2, fsm.ConcreteStates.Count()); }
public static StringBuilder AddFromGenerators(SMCSharpGenerator gen, Func <IEnumerable <CSharpCodeGenerator> > generatorFactory, StringBuilder buff) { var generators = generatorFactory.Invoke(); foreach (var code in generators) { buff.Append(code.GenerateCode(gen)); } return(buff); }
public string GenerateCode(SMCSharpGenerator gen, StringBuilder buff) { if (gen.HasNamespace) { buff.AppendLine($"namespace {gen.Namespace}") .AppendLine("{"); } return buff.ToString(); }
private static void AddEventBody(SMCSharpGenerator gen, string evName, StringBuilder buff) { if (gen.StateMap.UsesExceptions) { AddThrowException(gen, evName, buff); } else { AddErrorFuncCall(gen, evName, buff); } }
public string GenerateCode(SMCSharpGenerator gen, StringBuilder buff) { if (gen.HasUsing) { foreach (var item in gen.Usings) { buff.AppendLine($"using {item};"); } buff.AppendLine(); } return(buff.ToString()); }
private void AddConcreteStates(SMCSharpGenerator gen, StringBuilder buff) { buff.AppendLine(" #region Static Properties For Each State") .AppendLine(); foreach (var cs in gen.ConcreteStates) { buff.Append($" public static State {CreateMethodName(cs)} ") .AppendLine($"{{ get; }} = new {ClassNameFor(cs)}();"); } buff.AppendLine() .AppendLine(" #endregion") .AppendLine(); }
public override string GenerateCode(SMCSharpGenerator gen) { var buff = new StringBuilder(); AddClassHeader(buff); AddOpeningClassDeclaration(buff); AddConcreteStates(gen, buff); AddPublicProperties(buff); AddEventMethods(gen, buff); AddClosingClassDeclaration(buff); return(buff.ToString()); }
public override string GenerateCode(SMCSharpGenerator gen) { this.gen = gen; var buff = new StringBuilder(); foreach (var cs in this.gen.ConcreteStates) { GenerateConcreteStateClass(cs, buff); } var length = Environment.NewLine.Length; buff.Remove(buff.Length - length - 1, length); return(buff.ToString()); }
public override string GenerateCode(SMCSharpGenerator gen) { var stateMap = gen.StateMap; var buff = new StringBuilder() .AppendLine("// <auto-generated />") .AppendLine("//-----------------------------------------------------------------------") .AppendLine($"// FSM: {stateMap.Name}") .AppendLine($"// Context: {stateMap.ContextName}") .AppendLine(GetErrorStrategy(stateMap, stateMap.UsesExceptions)) .AppendLine($"// Version: {stateMap.Version}") .AppendLine("//-----------------------------------------------------------------------") .AppendLine(); return(buff.ToString()); }
public override string GenerateCode(SMCSharpGenerator gen) { var stateMap = gen.StateMap; var buff = new StringBuilder(); AddClassHeader(buff); BeginClassDeclaration(buff, stateMap); AddFields(buff, stateMap); AddClassMembers(gen, buff); AddStateClasses(gen, buff); CloseClassDeclaration(buff); return(buff.ToString()); }
private void AddEventMethods(SMCSharpGenerator gen, StringBuilder buff) { buff.AppendLine(" #region Default Event Methods") .AppendLine(); var events = gen.StateMap.Events; foreach (var evName in events) { AddEventHeader(evName, buff); AddOpenEventDeclaration(gen, evName, buff); AddEventBody(gen, evName, buff); AddCloseEventDeclaration(buff); } buff.AppendLine(" #endregion"); }
public override string GenerateCode(SMCSharpGenerator gen) { return(new StringBuilder() .AppendLine(" #region Public Properties") .AppendLine() .AppendLine(" public string Version => version;") .AppendLine() .AppendLine(" public string CurrentStateName => this.currentState.Name;") .AppendLine() .AppendLine(" internal State CurrentState") .AppendLine(" {") .AppendLine(" get { return this.currentState; }") .AppendLine(" set { this.currentState = value; }") .AppendLine(" }") .AppendLine() .AppendLine(" #endregion") .AppendLine() .ToString()); }
public override string GenerateCode(SMCSharpGenerator gen) { var buff = new StringBuilder() .AppendLine(" #region Event Methods - forward to the current State") .AppendLine(); var events = gen.StateMap.Events; foreach (var evi in events) { var evName = CreateMethodName(evi); buff.Append($" public void {evName}() ") .AppendLine($"=> this.currentState.{evName}(this);") .AppendLine(); } buff.AppendLine(" #endregion") .AppendLine(); return(buff.ToString()); }
public override string GenerateCode(SMCSharpGenerator gen) { var buff = new StringBuilder() .AppendLine(" #region Constructors & Destructors") .AppendLine() .AppendLine($" public {gen.StateMap.Name}()") .AppendLine(" {"); var iName = CreateMethodName(gen.StateMap.InitialState); buff.AppendLine($" this.currentState = State.{iName};"); var initialHierarchy = new List <State>(); gen.GetStateHierarchy(initialHierarchy, gen.StateMap.InitialState); foreach (var newState in initialHierarchy) { var eactions = newState.EntryActions; if (eactions.Any()) { buff.AppendLine() .AppendLine($" // Entry functions for: {newState.Name}"); } foreach (var action in eactions) { buff.AppendLine($" {action}();"); } } buff.AppendLine(" }") .AppendLine() .AppendLine(" #endregion") .AppendLine(); return(buff.ToString()); }
public override string GenerateCode(SMCSharpGenerator gen) => GenerateCode(gen, new StringBuilder());
public abstract string GenerateCode(SMCSharpGenerator gen);
public static StringBuilder AddFromGenerators(SMCSharpGenerator gen, Func <IEnumerable <CSharpCodeGenerator> > generatorFactory) => AddFromGenerators(gen, generatorFactory, new StringBuilder());
private static void AddStateClasses(SMCSharpGenerator gen, StringBuilder buff) => AddFromGenerators(gen, CSharpCodeGeneratorBuilder.Instance.StateGenerators, buff);