Esempio n. 1
0
        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 void GenerateTest(
            BookModel book,
            string expected)
        {
            // Arrange
            var generator = new HeaderGenerator(new StringHelper());

            // Act
            var actual = generator.Generate(book);

            // Assert
            actual.Should().BeEquivalentTo(expected);
        }
Esempio n. 3
0
        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);
            }
        }