/// <summary> /// Visita un objecte 'UnitDeclaration'. /// </summary> /// <param name="decl">L'objecte a visitar.</param> /// public override void Visit(UnitDeclaration decl) { if (decl.Namespace != null) { decl.Namespace.AcceptVisitor(this); } }
public void Write(Stream stream, UnitDeclaration decl) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (decl == null) { throw new ArgumentNullException(nameof(decl)); } XmlWriterSettings settings = new XmlWriterSettings(); settings.CloseOutput = false; settings.Encoding = Encoding.UTF8; settings.Indent = true; settings.IndentChars = " "; XmlWriter wr = XmlWriter.Create(stream, settings); try { IVisitor visitor = new XmlVisitor(wr); decl.AcceptVisitor(visitor); } finally { wr.Close(); } }
private void GenerateContextCode(UnitDeclaration unitDeclaration) { if (!String.IsNullOrEmpty(options.ContextCodeFileName)) { using (StreamWriter writer = File.CreateText(options.ContextCodeFileName)) { string code = CodeGenerator.Generate(unitDeclaration); StringBuilder sb = new StringBuilder(); sb .AppendLine("// -----------------------------------------------------------------------") .AppendLine("// Generated by FsmCompiler v1.1") .AppendLine("// Finite state machine compiler tool") .AppendLine("// Copyright 2015-2020 Rafael Serrano ([email protected])") .AppendLine("//") .AppendLine("// Warning. Don't touch. Changes will be overwritten!") .AppendLine("//") .AppendLine("// -----------------------------------------------------------------------") .AppendLine() .AppendLine() .AppendFormat("#include \"{0}\"", options.StateHeaderFileName).AppendLine() .AppendFormat("#include \"{0}\"", options.ContextHeaderFileName).AppendLine() .AppendLine() .AppendLine() .Append(code); writer.Write(sb.ToString()); } } }
private void GenerateContextHeader(UnitDeclaration unitDeclaration) { if (!String.IsNullOrEmpty(options.ContextHeaderFileName)) { using (StreamWriter writer = File.CreateText(options.ContextHeaderFileName)) { string header = HeaderGenerator.Generate(unitDeclaration); string guardString = Path.GetFileName(options.ContextHeaderFileName).ToUpper().Replace(".", "_"); StringBuilder sb = new StringBuilder(); sb .AppendLine("// -----------------------------------------------------------------------") .AppendLine("// Generated by FsmCompiler v1.1") .AppendLine("// Finite state machine compiler tool") .AppendLine("// Copyright 2015-2020 Rafael Serrano ([email protected])") .AppendLine("//") .AppendLine("// Warning. Don't touch. Changes will be overwritten!") .AppendLine("//") .AppendLine("// -----------------------------------------------------------------------") .AppendLine() .AppendFormat("#ifndef __{0}", guardString).AppendLine() .AppendFormat("#define __{0}", guardString).AppendLine() .AppendLine() .AppendLine() .AppendFormat("#include \"{0}\"", options.ConfigHeaderFileName).AppendLine() .AppendLine() .AppendLine() .AppendLine(header) .AppendLine() .AppendFormat("#endif // __{0}", guardString).AppendLine(); writer.Write(sb.ToString()); } } }
public override void Generate(Machine machine) { if (String.IsNullOrEmpty(options.OutputType) || (options.OutputType == "ContextHeader")) { ContextUnitGenerator generator = new ContextUnitGenerator(options); UnitDeclaration contextUnit = generator.Generate(machine); GenerateContextHeader(contextUnit); } if (String.IsNullOrEmpty(options.OutputType) || (options.OutputType == "ContextCode")) { ContextUnitGenerator generator = new ContextUnitGenerator(options); UnitDeclaration contextUnit = generator.Generate(machine); GenerateContextCode(contextUnit); } if (String.IsNullOrEmpty(options.OutputType) || (options.OutputType == "StateHeader")) { StateUnitGenerator generator = new StateUnitGenerator(options); UnitDeclaration stateUnit = generator.Generate(machine, StateUnitGenerator.Variant.Header); GenerateStateHeader(stateUnit); } if (String.IsNullOrEmpty(options.OutputType) || (options.OutputType == "StateCode")) { StateUnitGenerator generator = new StateUnitGenerator(options); UnitDeclaration stateUnit = generator.Generate(machine, StateUnitGenerator.Variant.Code); GenerateStateCode(stateUnit); } }
/// <summary> /// Genera el codi font. /// </summary> /// <param name="unitDecl">Objecte 'UnitDeclaration'.</param> /// <returns>El codi generat.</returns> /// public static string Generate(UnitDeclaration unitDecl) { if (unitDecl == null) { throw new ArgumentNullException(nameof(unitDecl)); } var cb = new CodeBuilder(); var visitor = new GeneratorVisitor(cb); visitor.Visit(unitDecl); return(cb.ToString()); }
public SLangUnitDefinition(Context ctx, UnitDeclaration ir) : this(ctx, ir.Name) { foreach (var declaration in ir.Declarations) { switch (declaration) { case RoutineDeclaration routine: RegisterRoutine(new SLangRoutineDefinition(this, routine)); break; default: throw new NotImplementedException("only routines declarations are supported within units"); } } }
public override void Generate(Machine machine) { UnitDeclaration unit = MachineUnitGenerator.Generate(machine, options); if (String.IsNullOrEmpty(options.OutputType) || (options.OutputType == "MachineHeader")) { string header = HeaderGenerator.Generate(unit); GenerateMachineHeader(header); } if (String.IsNullOrEmpty(options.OutputType) || (options.OutputType == "MachineCode")) { string code = CodeGenerator.Generate(unit); GenerateMachineCode(code); } }
public override void Visit(UnitDeclaration decl) { StartElement("unitDeclaration"); base.Visit(decl); EndElement(); }