public static IR1Top RCompilationUnit(this IR1Top r1Top, IGCompilationUnit gCompilationUnit, IW1Top w1Top) { r1Top.Ct?.ThrowIfCancellationRequested(); r1Top.Sb.RenderCompilationUnitStringBuilder(gCompilationUnit, r1Top.Indent, r1Top.Eol, r1Top.Ct); if (gCompilationUnit.GUsingGroups.Any()) { r1Top.RUsingGroup(gCompilationUnit.GUsingGroups); } if (gCompilationUnit.GUsings.Any()) { foreach (var kvp in gCompilationUnit.GUsings) { r1Top.RUsing(kvp.Value); } } if (gCompilationUnit.GNamespaces.Any()) { foreach (var kvp in gCompilationUnit.GNamespaces) { r1Top.RNamespace(kvp.Value); } } w1Top.WCompilationUnit(gCompilationUnit, r1Top.Sb); return(r1Top); }
public static IW1Top WCompilationUnit(this IW1Top w1Top, IGCompilationUnit gCompilationUnit, StringBuilder sB, CancellationToken?ct = default) { var pathToDir = Path.Combine(w1Top.BasePath, gCompilationUnit.GRelativePath); var pathToFile = Path.Combine(w1Top.BasePath, gCompilationUnit.GRelativePath, gCompilationUnit.GName + gCompilationUnit.GFileSuffix); var transformDictionary = gCompilationUnit.GPatternReplacement.GDictionary; IW1Top iW1Top; try { iW1Top = w1Top.WFile(pathToDir, pathToFile, transformDictionary, sB, ct); } catch (Exception e) { Console.WriteLine(e); // ToDo: better exception handling throw; } sB.Clear(); return(iW1Top); }
public static IGCompilationUnit TClassMakeBase(this IGCompilationUnit gCompilationUnit, IGClass gClass) { string name = gClass.GName + "Base"; List <IGMethod> gMethods = new List <IGMethod>(); foreach (var kvp in gClass.GMethods) { var oldGMethod = kvp.Value; string newgAccessModifier; newgAccessModifier = oldGMethod.GDeclaration.GVisibility == "public" ? "virtual" : ""; gMethods.Add(new GMethod(new GMethodDeclaration(gName: oldGMethod.GDeclaration.GName, gType: oldGMethod.GDeclaration.GType, gAccessModifier: newgAccessModifier, isStatic: oldGMethod.GDeclaration.IsStatic, gArguments: oldGMethod.GDeclaration.GArguments ) , oldGMethod.GBody)); } return(gCompilationUnit); }
public static void MStateMachineConstructor( IGCompilationUnit gCompilationUnit = default, IGNamespace gNamespace = default, IGClass gClass = default, IGMethod gConstructor = default, IList <string> initialDiGraphList = default) { #region UsingGroup var gUsingGroup = MUsingGroupForStatelessStateMachine(); gCompilationUnit.GUsingGroups.Add(gUsingGroup.Philote, gUsingGroup); #endregion #region Delegates var gDelegates = new Dictionary <IPhilote <IGDelegate>, IGDelegate>(); var UnhandledTriggerDelegateArguments = new Dictionary <IPhilote <IGArgument>, IGArgument>(); foreach (var o in new List <IGArgument>() { new GArgument("state", "State"), new GArgument("trigger", "Trigger"), }) { UnhandledTriggerDelegateArguments.Add(o.Philote, o); } foreach (var o in new List <IGDelegate>() { new GDelegate(new GDelegateDeclaration("UnHandledTriggerDelegate", gType: "void", gVisibility: "public", gArguments: UnhandledTriggerDelegateArguments)), new GDelegate(new GDelegateDeclaration(gName: "EntryExitDelegate", gType: "void", gVisibility: "public")), new GDelegate(new GDelegateDeclaration(gName: "GuardClauseDelegate", gType: "void", gVisibility: "public")), }) { gDelegates.Add(o.Philote, o); } gNamespace.AddDelegate(gDelegates); #endregion #region StateMachine GPropertyGroup and its properties var gPropertyGroup = new GPropertyGroup(gName: "StateMachine Properties"); // StateMachine Property var gProperty = new GProperty(gName: "StateMachine", gType: "StateMachine<State,Trigger>", gAccessors: "{get;}"); gPropertyGroup.GPropertys.Add(gProperty.Philote, gProperty); // StateConfigurations property //gProperty = new GProperty(gName: "StateConfigurations", gType: "List<StateConfiguration>", gAccessors: "{get;}"); //gPropertyGroup.GPropertys.Add(gProperty.Philote, gProperty); // Add the PropertyGroup to the gClass gClass.GPropertyGroups.Add(gPropertyGroup.Philote, gPropertyGroup); #endregion // Add initialization statements for the properties in the the StateMachine Properties Property Group to the constructor body gConstructor.GBody.GStatements.AddRange(new List <string>() { "StateMachine = new StateMachine<State, Trigger>(State.WaitingForInitialization);", "//StateConfigurations = stateConfigurations;", "ConfigureStateMachine();", }); //// StateConfiguration Class for the provided namespace //// Define the properties for the StateConfiguration class //// ToDo: Move this type into ATAP.Utilities.StateMachine //var gPropertys = new Dictionary<IPhilote<IGProperty>, GIProperty>(); //gProperty = new GProperty("State", "State", gAccessors: "{get;}", gVisibility: "public"); //gPropertys.Add(gProperty.Philote, gProperty); //gProperty = new GProperty("Trigger", "Trigger", gAccessors: "{get;}", gVisibility: "public"); //gPropertys.Add(gProperty.Philote, gProperty); //gProperty = new GProperty("NextState", "State", gAccessors: "{get;}", gVisibility: "public"); //gPropertys.Add(gProperty.Philote, gProperty); //var stateConfigurationClass = new GClass(gName: "StateConfiguration", gPropertys: gPropertys); //var gMethodArguments = new Dictionary<IPhilote<IGArgument>, IGArgument>(); //foreach (var o in new List<IGArgument>() { // new GArgument("state", "State"), new GArgument("trigger", "Trigger"), new GArgument("nextState", "State"), //}) { // gMethodArguments.Add(o.Philote, o); //} //gConstructor = new GMethod( // new GMethodDeclaration(gName: "StateConfiguration", isConstructor: true, gType: "IDisposable", // gVisibility: "public", gAccessModifier: "", // gArguments: gMethodArguments), // gBody: // new GBody(new List<string>() {"State=state;", "Trigger=trigger;", "NextState=nextState;",}), // new GComment(new List<string>() { // "/// <summary>", "/// builds one state instance", "/// </summary>", "/// <returns></returns>", // })); //stateConfigurationClass.GMethods.Add(gConstructor.Philote, gConstructor); //gNamespace.GClasss.Add(stateConfigurationClass.Philote, stateConfigurationClass); }
public static StringBuilder RenderCompilationUnitStringBuilder(this StringBuilder sb, IGCompilationUnit gCompilationUnit, StringBuilder indent, string eol, CancellationToken?ct = default) { ct?.ThrowIfCancellationRequested(); return(sb.Append($"{indent}{GCompilationUnit.Header}{eol}")); }