public CGenerator(GeneratorParameters generatorParameters) { CGeneratorOptions options = new CGeneratorOptions(); generatorParameters.Populate(options); this.options = options; }
public static UnitDeclaration Generate(Machine machine, CGeneratorOptions options) { MachineUnitGenerator.options = options; NamespaceMemberList memberList = new NamespaceMemberList(); // Crea el tipus enumerador pels valors del estat. // List <string> stateList = new List <string>(); foreach (var state in machine.States) { stateList.Add(String.Format("State_{0}", state.Name)); } EnumerationDeclaration stateType = new EnumerationDeclaration("State", AccessSpecifier.Public, stateList); memberList.Add(stateType); // Crea la variabe 'state' // VariableDeclaration stateVariable = new VariableDeclaration(); stateVariable.Access = AccessSpecifier.Private; stateVariable.Name = String.Format("{0}_state", machine.Name); stateVariable.ValueType = TypeIdentifier.FromName("State"); memberList.Add(stateVariable); // Crea les funcions de transicio [machine]_[state]_[transition]() // foreach (var state in machine.States) { foreach (var transitionName in state.GetTransitionNames()) { memberList.Add(MakeStateTransitionFunction(machine, state, transitionName)); } } // Crea la funcio [machine]_Start() // memberList.Add(MakeStartFunction(machine)); // Crea les funcions de despatch de les transicions [machine]_[transition]() // foreach (var transitionName in machine.GetTransitionNames()) { memberList.Add(MakeMachineTransitionFunction(machine, transitionName)); } return(new UnitDeclaration(new NamespaceDeclaration { Name = "", Members = memberList }));; }