コード例 #1
0
        public static void WriteToPath(string basePath)
        {
            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            using var stream = File.CreateText(Path.Combine(basePath, "MapDeclarationParser.Generated.cs"));
            using var output = new IndentedWriter(stream);

            var includes = new[]
            {
                "System.CodeDom.Compiler",
                "System.Linq",
                "Tiledriver.Core.FormatModels.Common",
                "Tiledriver.Core.FormatModels.MapInfo.Reading.AbstractSyntaxTree",
            };

            output
            .Line("#nullable enable")
            .WriteHeader("Tiledriver.Core.FormatModels.MapInfo.Reading", includes)
            .Line($"[GeneratedCode(\"{CurrentLibraryInfo.Name}\", \"{CurrentLibraryInfo.Version}\")]")
            .Line($"public static partial class MapDeclarationParser")
            .OpenParen();

            WriteParser(output, MapInfoDefinitions.Blocks.Single(b => b.ClassName == "DefaultMap"));
            output.Line();
            WriteParser(output, MapInfoDefinitions.Blocks.Single(b => b.ClassName == "AddDefaultMap"));
            output.Line();
            WriteMapParser(output, MapInfoDefinitions.Blocks.Single(b => b.ClassName == "Map"));
            output.Line();
            WriteDefaultMapUpdater(output, MapInfoDefinitions.Blocks.Single(b => b.ClassName == "DefaultMap"));

            output.CloseParen();
        }
コード例 #2
0
 /// <summary>
 /// Writes the constructor code to the specified output.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="indentation">The current indentation.</param>
 /// <param name="fields">The list of fields in the user type.</param>
 /// <param name="constructorName">The constructor name.</param>
 public void WriteCode(IndentedWriter output, int indentation, UserTypeField[] fields, string constructorName)
 {
     if (Static)
     {
         // Do nothing. We are initializing static variables in declaration statement because of the performance problems with generics.
     }
     else
     {
         output.WriteLine();
         output.WriteLine(indentation, "public {0}({1})", constructorName, Arguments);
         if (!string.IsNullOrEmpty(BaseClassInitialization))
         {
             output.WriteLine(indentation + 1, ": {0}", BaseClassInitialization);
         }
         output.WriteLine(indentation++, "{{");
         if (ContainsFieldDefinitions)
         {
             foreach (var field in fields)
             {
                 if (!field.CacheResult && !field.UseUserMember)
                 {
                     continue;
                 }
                 if (!field.Static)
                 {
                     field.WriteConstructorCode(output, indentation);
                 }
             }
         }
         output.WriteLine(--indentation, "}}");
     }
 }
コード例 #3
0
        public static void WriteTo(StreamWriter stream)
        {
            using (var output = new IndentedWriter(stream))
            {
                output.Line(
                    $@"// Copyright (c) {DateTime.Today.Year}, David Aramant
// Distributed under the 3-clause BSD license.  For full terms see the file LICENSE. 

using System.CodeDom.Compiler;
using UdmfParsing.Udmf.Parsing.SuperpowerVersion.AbstractSyntaxTree;

namespace UdmfParsing.Udmf.Parsing.SuperpowerVersion").OpenParen()
                .Line($"[GeneratedCode(\"{CurrentLibraryInfo.Name}\", \"{CurrentLibraryInfo.Version}\")]")
                .Line("public static partial class UdmfSemanticAnalyzer").OpenParen();

                WriteGlobalFieldParsing(output);

                output.Line();

                WriteBlockParsing(output);

                output.Line();

                foreach (var block in UdmfDefinitions.Blocks.Where(b => b.IsSubBlock))
                {
                    WriteBlockParser(block, output);
                }

                output.CloseParen();
                output.CloseParen();
            }
        }
コード例 #4
0
        private void Array_BuildPrettyString(IndentedWriter writer)
        {
            writer.Write("[");
            writer.Indent++;

            var keys = Keys.AssertCast <int>();

            if (keys.IsNotEmpty())
            {
                keys.ForEach((key, i) =>
                {
                    (key == i).AssertTrue();
                    // todo. omg what's with these dynamic invocations?!
                    if (((IEnumerable)this[key].Keys).Cast <Object>().Count() > 0)
                    {
                        writer.WriteLine();
                    }
                    this[key].BuildPrettyString(writer);
                    if (i < this.Count() - 1)
                    {
                        writer.Write(",");
                    }
                });

                writer.WriteLine();
            }

            writer.Indent--;
            writer.Write("]");
        }
コード例 #5
0
        public static void WriteToPath(string basePath)
        {
            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            using var stream = File.CreateText(Path.Combine(basePath, "UdmfSemanticAnalyzer.Generated.cs"));
            using var output = new IndentedWriter(stream);

            var includes = new[]
            {
                "System.CodeDom.Compiler",
                "System.Collections.Generic",
                "System.Collections.Immutable",
                "Tiledriver.Core.FormatModels.Common",
                "Tiledriver.Core.FormatModels.Common.Reading",
                "Tiledriver.Core.FormatModels.Common.Reading.AbstractSyntaxTree",
            };

            output
            .WriteHeader("Tiledriver.Core.FormatModels.Udmf.Reading", includes)
            .Line($"[GeneratedCode(\"{CurrentLibraryInfo.Name}\", \"{CurrentLibraryInfo.Version}\")]")
            .Line($"public static partial class UdmfSemanticAnalyzer")
            .OpenParen();

            foreach (var block in UdmfDefinitions.Blocks.Where(b => b.Serialization == SerializationType.Normal))
            {
                CreateBlockReader(output, block);
            }

            CreateGlobalBlockReader(output, UdmfDefinitions.Blocks.Single(b => b.Serialization == SerializationType.TopLevel));

            output.CloseParen();
        }
コード例 #6
0
        public static void WriteToPath(string basePath)
        {
            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            using var stream = File.CreateText(Path.Combine(basePath, "UdmfWriter.Generated.cs"));
            using var output = new IndentedWriter(stream);

            output
            .WriteHeader("Tiledriver.Core.FormatModels.Udmf.Writing",
                         new[]
            {
                "System.CodeDom.Compiler",
                "System.IO",
                "Tiledriver.Core.FormatModels.Common"
            })
            .Line($"[GeneratedCode(\"{CurrentLibraryInfo.Name}\", \"{CurrentLibraryInfo.Version}\")]")
            .Line($"public static partial class UdmfWriter")
            .OpenParen();

            foreach (var block in UdmfDefinitions.Blocks.Where(b => b.Serialization != SerializationType.Custom))
            {
                CreateBlockWriter(output, block);
            }

            output.CloseParen();
        }
コード例 #7
0
        public static ParserState <Result> ForStart(ParserNode root, ISourceTextReader reader, bool enableLog)
        {
            IndentedWriter w;

            if (enableLog)
            {
                w = new IndentedWriter("  ");
                w.Push().WriteLine("Start @{0} {1}", reader.GetPosition(), root).Push();
            }
            else
            {
                w = null;
            }

            if (root.Parent != null)
            {
                throw new ArgumentException();
            }

            return(new LinearParserState(
                       w,
                       root,
                       null,
                       new ParserStep.EnterNode(null, root, reader.Location),
                       StatefullStackNode.ForRoot(),
                       null,
                       reader
                       ));
        }
コード例 #8
0
        static void WriteRecord(string basePath, Block block)
        {
            using var blockStream =
                      File.CreateText(Path.Combine(basePath, block.ClassName + ".Generated.cs"));
            using var output = new IndentedWriter(blockStream);

            var containsTexture    = block.Properties.Any(p => p is TextureProperty);
            var containsCollection = block.Properties.Any(p => p is CollectionProperty);

            List <string> includes = new() { "System.CodeDom.Compiler" };

            if (containsTexture)
            {
                includes.Add("Tiledriver.Core.FormatModels.Common");
            }
            if (containsCollection)
            {
                includes.Add("System.Collections.Immutable");
            }

            output
            .WriteHeader("Tiledriver.Core.FormatModels.Uwmf", includes)
            .Line($"[GeneratedCode(\"{CurrentLibraryInfo.Name}\", \"{CurrentLibraryInfo.Version}\")]")
            .Line($"public sealed partial record {block.ClassName}(")
            .IncreaseIndent()
            .JoinLines(",", block.OrderedProperties.Select(GetPropertyDefinition))
            .DecreaseIndent()
            .Line(");");
        }
コード例 #9
0
        static void WriteBuilder(string basePath, Block block)
        {
            using var blockStream =
                      File.CreateText(Path.Combine(basePath, block.ClassName + "Builder.Generated.cs"));
            using var output = new IndentedWriter(blockStream);

            var           containsTexture   = block.Properties.Any(p => p is TextureProperty);
            var           containsNullables = block.Properties.Any(p => !p.HasDefault);
            List <string> includes          = new() { "System.CodeDom.Compiler", "System" };

            if (containsTexture)
            {
                includes.Add("Tiledriver.Core.FormatModels.Common");
            }

            output
            .WriteHeader("Tiledriver.Core.FormatModels.Udmf", includes, enableNullables: containsNullables)
            .Line($"[GeneratedCode(\"{CurrentLibraryInfo.Name}\", \"{CurrentLibraryInfo.Version}\")]")
            .Line($"public sealed partial class {block.ClassName}Builder")
            .OpenParen()
            .JoinLines("", block.OrderedProperties.Select(GetBuilderPropertyDefinition))
            .Line()
            .Line($"public {block.ClassName} Build() =>")
            .IncreaseIndent()
            .Line("new(")
            .IncreaseIndent()
            .JoinLines(",", block.OrderedProperties.Select(GetBuilderPropertyAssignment))
            .DecreaseIndent()
            .Line(");")
            .DecreaseIndent()
            .CloseParen();
        }
コード例 #10
0
        private static void WriteBlockParsing(IndentedWriter output)
        {
            output.
            Line("static partial void ProcessBlock(MapData map, Block block)").
            OpenParen().
            Line("switch (block.Name.ToLower())").
            OpenParen();

            foreach (var block in UdmfDefinitions.Blocks.Single(b => b.CodeName.ToPascalCase() == "MapData").SubBlocks
                     .Where(b => b.IsRequired))
            {
                output.
                Line($"case \"{block.FormatName.ToLowerInvariant()}\":").
                IncreaseIndent().
                Line($"map.{block.PropertyName}.Add(Process{block.FormatName.ToPascalCase()}(block));").
                Line("break;").
                DecreaseIndent();
            }

            output.
            Line("default:").
            IncreaseIndent().
            Line($"map.UnknownBlocks.Add(ProcessUnknownBlock(block));").
            Line("break;").
            DecreaseIndent().
            CloseParen().
            CloseParen();
        }
コード例 #11
0
 /// <summary>
 /// Writes the field code to the specified output.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="indentation">The current indentation.</param>
 /// <param name="generationFlags">The user type generation flags.</param>
 public virtual void WriteFieldCode(IndentedWriter output, int indentation, UserTypeGenerationFlags generationFlags)
 {
     if (generationFlags.HasFlag(UserTypeGenerationFlags.GenerateFieldTypeInfoComment) && !string.IsNullOrEmpty(FieldTypeInfoComment))
     {
         output.WriteLine(indentation, FieldTypeInfoComment);
     }
     if (!string.IsNullOrEmpty(ConstantValue))
     {
         output.WriteLine(indentation, "public static {0} {1} = ({0}){2};", FieldType, FieldName, GetConstantValue());
     }
     else if (Static && !UseUserMember)
     {
         output.WriteLine(indentation, "{3} static {0} {1} = {2};", FieldType, FieldName, ConstructorText, Access);
     }
     else if (UseUserMember && CacheResult)
     {
         output.WriteLine(indentation, "{3}{4} {0}UserMember<{1}> {2};", Static ? "static " : "", FieldType, FieldName, Access, OverrideWithNew ? " new" : "");
     }
     else if (CacheResult)
     {
         output.WriteLine(indentation, "{3}{4} {0}{1} {2};", Static ? "static " : "", FieldType, FieldName, Access, OverrideWithNew ? " new" : "");
     }
     if (generationFlags.HasFlag(UserTypeGenerationFlags.GenerateFieldTypeInfoComment))
     {
         output.WriteLine();
     }
 }
コード例 #12
0
        private static void WriteProperties(Block block, IndentedWriter sb)
        {
            foreach (var property in block.Fields.Where(_ => _.IsRequired))
            {
                sb.Line($"private bool {property.FieldName}HasBeenSet = false;").
                Line($"private {property.PropertyType} {property.FieldName};").
                Line($"public {property.PropertyType} {property.PropertyName}").
                OpenParen().
                Line($"get {{ return {property.FieldName}; }}").
                Line($"set").
                OpenParen().
                Line($"{property.FieldName}HasBeenSet = true;").
                Line($"{property.FieldName} = value;").
                CloseParen().
                CloseParen();
            }

            foreach (var field in block.Fields.Where(_ => !_.IsRequired))
            {
                sb.Line($"public {field.PropertyType} {field.PropertyName} {{ get; set; }} = {field.DefaultValue};");
            }

            foreach (var subBlock in block.SubBlocks)
            {
                sb.Line(
                    $"public {subBlock.PropertyType} {subBlock.PropertyName} {{ get; }} = new {subBlock.PropertyType}();");
            }
        }
コード例 #13
0
        public void BasicTest()
        {
            using var sw = new StringWriter();
            using var iw = new IndentedWriter(sw)
                  {
                      IndentString = "#", NewLine = "\n"
                  };

            Assert.Equal("\n", iw.NewLine);
            Assert.Equal(sw.Encoding, iw.Encoding);

            iw.WriteLine("line1");
            iw.Write("line");
            iw.IncreaseIndent();
            iw.WriteLine("2");
            iw.Write("line");
            iw.Write('3');
            iw.WriteLine();
            iw.IncreaseIndent(2);
            iw.WriteLine("line4");
            iw.DecreaseIndent();
            iw.WriteLine("line5");
            iw.DecreaseIndent(6);
            iw.WriteLine("line6");

            Assert.Equal("line1\nline2\n#line3\n###line4\n##line5\nline6\n", sw.ToString());
        }
コード例 #14
0
        private static void WriteFieldSwitch(IndentedWriter output, Block block, string variable)
        {
            output.
            Line("switch (assignment.Name.ToLower())").
            OpenParen();


            foreach (var field in block.Fields)
            {
                output.
                Line($"case \"{field.FormatName.ToLowerInvariant()}\":").
                IncreaseIndent().
                Line($"{variable}.{field.PropertyName} = Read{field.PropertyType.ToPascalCase()}Value(assignment, \"{block.CodeName}.{field.PropertyName}\");").
                Line("break;").
                DecreaseIndent();
            }

            output.
            Line("default:").
            IncreaseIndent().
            Line($"{variable}.UnknownProperties.Add(new UnknownProperty(assignment.Name, assignment.ValueAsString()));").
            Line("break;").
            DecreaseIndent().
            CloseParen();
        }
コード例 #15
0
ファイル: Json.Object.cs プロジェクト: avaranovich/xenogears
        private void Object_BuildPrettyString(IndentedWriter writer)
        {
            writer.Write("{");
            writer.Indent++;

            var keys = Keys.AssertCast <String>();

            if (keys.IsNotEmpty())
            {
                keys.ForEach((key, i) =>
                {
                    writer.WriteLine();
                    writer.Write("\"{0}\" : ", key);
                    if (((IEnumerable)this[key].Keys).Cast <Object>().Count() > 0)
                    {
                        writer.WriteLine();
                    }
                    this[key].BuildPrettyString(writer);
                    if (i < this.Count() - 1)
                    {
                        writer.Write(",");
                    }
                });

                writer.WriteLine();
            }

            writer.Indent--;
            writer.Write("}");
        }
コード例 #16
0
 internal Result(bool allTextParsed, bool treeReconstructed, IndentedWriter log, params IParsingTreeNode[] trees)
 {
     _log = log;
     this.AllTextParsed = allTextParsed;
     this.Successed     = allTextParsed || treeReconstructed;
     this.Tree          = trees.Length == 1 ? trees.First() : null;
     this.Trees         = trees.Length == 1 ? null : trees;
 }
コード例 #17
0
		public void setWriter(Writer writer, String indentString, int maxColumns)
		{
			_writer = new IndentedWriter(writer, maxColumns);
			if (indentString != null)
			{
				_writer.setIndentString(indentString);
			}
		}
コード例 #18
0
ファイル: CSharpBinder.cs プロジェクト: chrisculy/epoxy
 private static void WriteFileHeader(IndentedWriter writer)
 {
     writer.WriteLine("// WARNING: This file is generated by Epoxy. Do not edit this file manually.");
     writer.WriteLine("// -------------------------------------------------------------------------");
     writer.WriteLine();
     writer.WriteLine("using System.Runtime.InteropServices;");
     writer.WriteLine();
 }
コード例 #19
0
ファイル: CSharpBinder.cs プロジェクト: chrisculy/epoxy
 private void WriteVariableNativeBindings(Variable variable, IndentedWriter writer)
 {
     writer.WriteLine($"[DllImport(\"{Configuration.DllFileName}\")]");
     writer.WriteLine($"private static extern {ToCsReturnType(variable)} {ToNativeVariableGet(variable)}();");
     writer.WriteLine($"[DllImport(\"{Configuration.DllFileName}\")]");
     writer.WriteLine($"private static extern void {ToNativeVariableSet(variable)}({ToCsParameter(variable)});");
     writer.WriteLine();
 }
コード例 #20
0
        /// <summary>
        /// Writes the property code to the specified output.
        /// </summary>
        /// <param name="output">The output.</param>
        /// <param name="indentation">The current indentation.</param>
        /// <param name="generationFlags">The user type generation flags.</param>
        /// <param name="firstField">if set to <c>true</c> this is the first field in the user type.</param>
        public virtual void WritePropertyCode(IndentedWriter output, int indentation, UserTypeGenerationFlags generationFlags, ref bool firstField)
        {
            if (string.IsNullOrEmpty(ConstantValue))
            {
                if (generationFlags.HasFlag(UserTypeGenerationFlags.SingleLineProperty))
                {
                    if (firstField)
                    {
                        output.WriteLine();
                        firstField = false;
                    }

                    if (!UseUserMember && !CacheResult && generationFlags.HasFlag(UserTypeGenerationFlags.GenerateFieldTypeInfoComment) && !string.IsNullOrEmpty(FieldTypeInfoComment))
                    {
                        output.WriteLine(indentation, FieldTypeInfoComment);
                    }
                    if (UseUserMember && CacheResult)
                    {
                        output.WriteLine(indentation, "public {0}{1} {2} {{ get {{ return {3}.Value; }} }}", Static ? "static " : "", FieldType, PropertyName, FieldName);
                    }
                    else if (CacheResult)
                    {
                        output.WriteLine(indentation, "public {0}{1} {2} {{ get {{ return {3}; }} }}", Static ? "static " : "", FieldType, PropertyName, FieldName);
                    }
                    else
                    {
                        output.WriteLine(indentation, "public {0}{1} {2} {{ get {{ return {3}; }} }}", Static ? "static " : "", FieldType, PropertyName, ConstructorText);
                    }
                }
                else
                {
                    output.WriteLine();
                    if (!UseUserMember && !CacheResult && generationFlags.HasFlag(UserTypeGenerationFlags.GenerateFieldTypeInfoComment) && !string.IsNullOrEmpty(FieldTypeInfoComment))
                    {
                        output.WriteLine(indentation, FieldTypeInfoComment);
                    }
                    output.WriteLine(indentation, "public {0}{1} {2}", Static ? "static " : "", FieldType, PropertyName);
                    output.WriteLine(indentation++, "{{");
                    output.WriteLine(indentation, "get");
                    output.WriteLine(indentation++, "{{");
                    if (UseUserMember && CacheResult)
                    {
                        output.WriteLine(indentation, "return {0}.Value;", FieldName);
                    }
                    else if (CacheResult)
                    {
                        output.WriteLine(indentation, "return {0};", FieldName);
                    }
                    else
                    {
                        output.WriteLine(indentation, "return {0};", ConstructorText);
                    }
                    output.WriteLine(--indentation, "}}");
                    output.WriteLine(--indentation, "}}");
                }
            }
        }
コード例 #21
0
 public string ToString(JsonStringifyOption config, string newline)
 {
     using var sw = new StringWriter();
     using var iw = new IndentedWriter(sw)
           {
               NewLine = newline
           };
     Stringify(config, iw);
     return(sw.ToString());
 }
コード例 #22
0
ファイル: TemplateUserType.cs プロジェクト: leculver/WinDbgCs
 /// <summary>
 /// Writes the class comment on the specified output.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="indentation">The current indentation.</param>
 protected override void WriteClassComment(IndentedWriter output, int indentation)
 {
     base.WriteClassComment(output, indentation);
     output.WriteLine(indentation, "// ---------------------------------------------------");
     output.WriteLine(indentation, "// Specializations of this class");
     foreach (var type in SpecializedTypes)
     {
         output.WriteLine(indentation, "//   {0}", type.Symbol.Name);
     }
 }
コード例 #23
0
        static void WriteRecord(string basePath, Block block)
        {
            using var blockStream =
                      File.CreateText(Path.Combine(basePath, block.ClassName + ".Generated.cs"));
            using var output = new IndentedWriter(blockStream);

            var  containsCollection = block.Properties.Any(p => p is CollectionProperty);
            bool includeConverter   = block.ClassName == "TileTemplate";

            var includes = new List <string> {
                "System.CodeDom.Compiler"
            };

            if (containsCollection)
            {
                includes.Add("System.Collections.Immutable");
            }

            if (includeConverter)
            {
                includes.Add("Tiledriver.Core.FormatModels.Uwmf");
            }

            output
            .WriteHeader("Tiledriver.Core.FormatModels.Xlat", includes)
            .Line($"[GeneratedCode(\"{CurrentLibraryInfo.Name}\", \"{CurrentLibraryInfo.Version}\")]")
            .Line($"public sealed partial record {block.ClassName}(")
            .IncreaseIndent()
            .JoinLines(",", block.OrderedProperties.Select(GetPropertyDefinition))
            .DecreaseIndent();

            if (includeConverter)
            {
                output
                .Line(")")
                .OpenParen()
                .Line("public Tile ToTile() =>")
                .IncreaseIndent()
                .Line("new Tile(")
                .IncreaseIndent()
                .JoinLines(",",
                           block
                           .OrderedProperties
                           .Where(p => p.PropertyName != "OldNum")
                           .Select(p => $"{p.PropertyName}: {p.PropertyName}"))
                .DecreaseIndent()
                .Line(");")
                .DecreaseIndent()
                .CloseParen();
            }
            else
            {
                output.Line(");");
            }
        }
コード例 #24
0
        private LinearParserState(IndentedWriter w, ParserNode currNode, ParserNode prevNode, ParserStep lastStep, StatefullStackNode stack, bool?lastTerminalFailed, ISourceTextReader reader, ISourceTextReaderHolder holder = null)
            : base(w, currNode, prevNode, lastTerminalFailed, reader, holder)
        {
            this.LastStep = lastStep;
            this.Stack    = stack;

            if (_log != null)
            {
                _log.WriteLine(this.Stack.ToString());
            }
        }
コード例 #25
0
ファイル: EnumUserType.cs プロジェクト: dasatomic/WinDbgCs
        /// <summary>
        /// Writes the code for this user type to the specified output.
        /// </summary>
        /// <param name="output">The output.</param>
        /// <param name="error">The error text writer.</param>
        /// <param name="factory">The user type factory.</param>
        /// <param name="generationFlags">The user type generation flags.</param>
        /// <param name="indentation">The current indentation.</param>
        public override void WriteCode(IndentedWriter output, TextWriter error, UserTypeFactory factory, UserTypeGenerationFlags generationFlags, int indentation = 0)
        {
            // Check if we need to write namespace
            string nameSpace     = (DeclaredInType as NamespaceUserType)?.FullClassName ?? Namespace;
            string enumBasicType = GetEnumBasicType(Symbol);

            if ((DeclaredInType == null || (!generationFlags.HasFlag(UserTypeGenerationFlags.SingleFileExport) && DeclaredInType is NamespaceUserType)) && !string.IsNullOrEmpty(nameSpace))
            {
                output.WriteLine(indentation, "namespace {0}", nameSpace);
                output.WriteLine(indentation++, "{{");
            }

            // Write beginning of the enumeration
            if (generationFlags.HasFlag(UserTypeGenerationFlags.GenerateFieldTypeInfoComment))
            {
                output.WriteLine(indentation, "// {0} (original name: {1})", ClassName, Symbol.Name);
            }

            if (AreValuesFlags())
            {
                output.WriteLine(indentation, @"[System.Flags]");
            }
            if (Symbol.Size != 0)
            {
                output.WriteLine(indentation, @"public enum {0} : {1}", ClassName, enumBasicType);
            }
            else
            {
                output.WriteLine(indentation, @"public enum {0}", ClassName);
            }
            output.WriteLine(indentation++, @"{{");

            // Write values
            foreach (var enumValue in Symbol.EnumValues)
            {
                string value = enumValue.Item2;

                if (!FitsBasicType(enumBasicType, ref value))
                {
                    output.WriteLine(indentation, "{0} = ({1}){2},", enumValue.Item1, enumBasicType, value);
                }
                else
                {
                    output.WriteLine(indentation, "{0} = {1},", enumValue.Item1, value);
                }
            }

            // Enumeration end
            output.WriteLine(--indentation, @"}}");
            if ((DeclaredInType == null || (!generationFlags.HasFlag(UserTypeGenerationFlags.SingleFileExport) && DeclaredInType is NamespaceUserType)) && !string.IsNullOrEmpty(nameSpace))
            {
                output.WriteLine(--indentation, "}}");
            }
        }
コード例 #26
0
 internal override void Stringify(JsonStringifyOption config, IndentedWriter iw)
 {
     if (IsFloat)
     {
         iw.Write(ValueFloat);
     }
     else
     {
         iw.Write(ValueInt);
     }
 }
コード例 #27
0
ファイル: CSharpBinder.cs プロジェクト: chrisculy/epoxy
        private void WriteCsFunction(Function function, IndentedWriter writer)
        {
            string returnType = ToCsReturnType(function.Return);
            string qualifiers = function.IsStatic || !function.IsClassMember ? "static " : "";

            writer.WriteLine($"public {qualifiers}{returnType} {ToPascalCase(function.Name)}{ToCsParameterString(function.Parameters)}");
            using (Scope functionScope = writer.IndentBlock())
            {
                writer.WriteLine($@"{(returnType == "void" ? "" : "return ")}{ToNativeFunction(function)}({(string.Join(", ", function.Parameters.Select(parameter => parameter.Name)))});");
            }
            writer.WriteLine();
        }
コード例 #28
0
 private static void WriteParser(IndentedWriter output, IBlock block)
 {
     output
     .Line($"private static partial {block.ClassName} Parse{block.ClassName}(ILookup<Identifier, VariableAssignment> assignmentLookup)")
     .IncreaseIndent()
     .Line($"=> new {block.ClassName}(")
     .IncreaseIndent()
     .JoinLines(",", block.OrderedProperties.Select(GetPropertyReader))
     .DecreaseIndent()
     .Line(");")
     .DecreaseIndent();
 }
コード例 #29
0
        internal ParserState(IndentedWriter log, ParserNode curr, ParserNode prev, bool?lastTerminalFailed, ISourceTextReader reader, ISourceTextReaderHolder holder = null)
        {
            this.CurrNode            = curr;
            this.PrevNode            = prev;
            this.ResultReconstructed = false;

            _log = log;

            this.LastTerminalFailed = lastTerminalFailed;

            _reader       = reader;
            _readerHolder = holder;
        }
コード例 #30
0
        private static void WriteGlobalFieldParsing(IndentedWriter output)
        {
            output.
            Line("static partial void ProcessGlobalAssignment(MapData map, Assignment assignment)").
            OpenParen();

            var block = UdmfDefinitions.Blocks.Single(b => b.CodeName.ToPascalCase() == "MapData");

            WriteFieldSwitch(output, block, "map");

            output.
            CloseParen();
        }
コード例 #31
0
        /// <summary>
        /// Writes the code for this user type to the specified output.
        /// </summary>
        /// <param name="output">The output.</param>
        /// <param name="error">The error text writer.</param>
        /// <param name="factory">The user type factory.</param>
        /// <param name="generationFlags">The user type generation flags.</param>
        /// <param name="indentation">The current indentation.</param>
        public override void WriteCode(IndentedWriter output, TextWriter error, UserTypeFactory factory, UserTypeGenerationFlags generationFlags, int indentation = 0)
        {
            // Check if we need to write namespace
            string nameSpace = (DeclaredInType as NamespaceUserType)?.FullClassName ?? Namespace;

            if ((DeclaredInType == null || (!generationFlags.HasFlag(UserTypeGenerationFlags.SingleFileExport) && DeclaredInType is NamespaceUserType)) && !string.IsNullOrEmpty(nameSpace))
            {
                output.WriteLine(indentation, "namespace {0}", nameSpace);
                output.WriteLine(indentation++, "{{");
            }

            // Write beginning of the enumeration
            if (generationFlags.HasFlag(UserTypeGenerationFlags.GenerateFieldTypeInfoComment))
                output.WriteLine(indentation, "// {0} (original name: {1})", ClassName, Symbol.Name);

            if (AreValuesFlags())
                output.WriteLine(indentation, @"[System.Flags]");
            if (Symbol.Size != 0)
                output.WriteLine(indentation, @"public enum {0} : {1}", ClassName, GetEnumBasicType(Symbol));
            else
                output.WriteLine(indentation, @"public enum {0}", ClassName);
            output.WriteLine(indentation++, @"{{");

            // Write values
            foreach (var enumValue in Symbol.GetEnumValues())
            {
                output.WriteLine(indentation, "{0} = {1},", enumValue.Item1, enumValue.Item2);
            }

            // Enumeration end
            output.WriteLine(--indentation, @"}}");
            if ((DeclaredInType == null || (!generationFlags.HasFlag(UserTypeGenerationFlags.SingleFileExport) && DeclaredInType is NamespaceUserType)) && !string.IsNullOrEmpty(nameSpace))
            {
                output.WriteLine(--indentation, "}}");
            }
        }
コード例 #32
0
 /// <summary>
 /// Writes the constructor code to the specified output.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="indentation">The current indentation.</param>
 public override void WriteConstructorCode(IndentedWriter output, int indentation)
 {
     output.WriteLine(indentation, "{0}();", FieldName);
 }
コード例 #33
0
 /// <summary>
 /// Writes the class comment on the specified output.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="indentation">The current indentation.</param>
 protected override void WriteClassComment(IndentedWriter output, int indentation)
 {
     base.WriteClassComment(output, indentation);
     output.WriteLine(indentation, "// ---------------------------------------------------");
     output.WriteLine(indentation, "// Specializations of this class");
     foreach (var type in SpecializedTypes)
         output.WriteLine(indentation, "//   {0}", type.Symbol.Name);
 }
コード例 #34
0
 /// <summary>
 /// Writes the property code.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="indentation">The indentation.</param>
 /// <param name="options">The options.</param>
 /// <param name="firstField">if set to <c>true</c> [first field].</param>
 public override void WritePropertyCode(IndentedWriter output, int indentation, UserTypeGenerationFlags options, ref bool firstField)
 {
     // Do nothing
 }
コード例 #35
0
        /// <summary>
        /// Writes the code for this user type to the specified output.
        /// </summary>
        /// <param name="output">The output.</param>
        /// <param name="error">The error text writer.</param>
        /// <param name="factory">The user type factory.</param>
        /// <param name="generationFlags">The user type generation flags.</param>
        /// <param name="indentation">The current indentation.</param>
        public override void WriteCode(IndentedWriter output, TextWriter error, UserTypeFactory factory, UserTypeGenerationFlags generationFlags, int indentation = 0)
        {
            // Declared In Type with namespace
            if (DeclaredInType != null)
            {
                foreach (string innerClass in namespaces)
                {
                    output.WriteLine(indentation, "public static partial class {0}", innerClass);
                    output.WriteLine(indentation++, @"{{");
                }
            }
            else
            {
                output.WriteLine(indentation, "namespace {0}", Namespace);
                output.WriteLine(indentation++, @"{{");
            }

            // Inner types
            foreach (var innerType in InnerTypes)
            {
                output.WriteLine();
                innerType.WriteCode(output, error, factory, generationFlags, indentation);
            }

            // Declared In Type with namespace
            if (DeclaredInType != null)
                foreach (string innerClass in namespaces)
                    output.WriteLine(--indentation, "}}");
            else
                output.WriteLine(--indentation, "}}");
        }
コード例 #36
0
 /// <summary>
 /// Writes the field code.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="indentation">The indentation.</param>
 /// <param name="options">The options.</param>
 public override void WriteFieldCode(IndentedWriter output, int indentation, UserTypeGenerationFlags options)
 {
     output.WriteLine(indentation, "{0} {1}();", FieldType, FieldName);
 }