当前位置: 首页>>代码示例>>C#>>正文


C# StringWriter.WriteLineNoTabs方法代码示例

本文整理汇总了C#中System.IO.StringWriter.WriteLineNoTabs方法的典型用法代码示例。如果您正苦于以下问题:C# StringWriter.WriteLineNoTabs方法的具体用法?C# StringWriter.WriteLineNoTabs怎么用?C# StringWriter.WriteLineNoTabs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StringWriter的用法示例。


在下文中一共展示了StringWriter.WriteLineNoTabs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoGenerate

        public static void DoGenerate()
        {
            var edsl_base = @"..\..\..\..\Libptx.Edsl\Libptx.Edsl\";
            var dir_sregs = edsl_base + @"Expressions\Sregs\";
            Func<String, String> dir2ns = dir => dir.Replace(@"..\..\..\..\Libptx.Edsl\", String.Empty).Replace(@"\", ".").Slice(0, -1);

            foreach (var t in Sregs.All)
            {
                var buf = new StringBuilder();
                var w = new StringWriter(buf).Indented();
                w.WriteLine("using Libptx.Edsl.Common.Types.Scalar;");
                w.WriteLine("using Libptx.Edsl.Common.Types.Vector;");
                w.WriteLineNoTabs(String.Empty);
                w.WriteLine("namespace {0}", dir2ns(dir_sregs));
                w.WriteLine("{");
                w.Indent++;
                w.WriteLine("public class {0} : {1}, sreg", t.Name, t.FullName);
                w.WriteLine("{");
                w.Indent++;

                var xid = t.Name == "tid" || t.Name == "ntid" || t.Name == "ctaid" || t.Name == "nctaid";
                if (xid)
                {
                    var post_20 = Context.Current.Version >= SoftwareIsa.PTX_20;
                    if (post_20)
                    {
                        w.EmitTypeSpec(t.Name, new Type { Name = TypeName.U16, Mod = TypeMod.V4 }, Space.Other);
                        w.EmitTypeSpec(t.Name, new Type { Name = TypeName.U32, Mod = TypeMod.V4 }, Space.Other);
                    }
                    else
                    {
                        w.EmitTypeSpec(t.Name, new Type { Name = TypeName.U16, Mod = TypeMod.V4 }, Space.Other);
                    }
                }
                else
                {
                    var type = t.Attr<SregAttribute>().Type;
                    w.EmitTypeSpec(t.Name, type, Space.Other);
                }

                // todo. also emit same stuff as gets emitted for non-reg vars of appropriate type
                // e.g. .x, .y, .z accessors for grid-related special registers

                w.Indent--;
                w.WriteLine("}");
                w.Indent--;
                w.WriteLine("}");

                var fname = dir_sregs + t.Name + ".cs";
                File.WriteAllText(fname, buf.ToString());
            }
        }
开发者ID:xeno-by,项目名称:libptx,代码行数:52,代码来源:SregGenerator.cs

示例2: DoGenerate

        public static void DoGenerate()
        {
            foreach (var op in Ptxops.All)
            {
                var dir = @"..\..\..\..\" + op.Namespace.Replace(".", @"\") + @"\";
                var file = dir + op.Name + ".cs";
                var text = File.ReadAllText(file);
                Action<String> use = ns =>
                {
                    if (!text.Contains("using " + ns + ";"))
                    {
                        var liof = text.LastIndexOf("using") + 1;
                        var next = text.IndexOf(Environment.NewLine, liof);
                        var ins = next == -1 ? 0 : (next + Environment.NewLine.Length);
                        text = text.Insert(ins, "using " + ns + ";" + Environment.NewLine);
                    }
                };

                var buf = new StringBuilder();
                var w = new StringWriter(buf).Indented();
                w.Indent += 2;
                w.WriteLineNoTabs(String.Empty);

                w.WriteLineNoTabs(String.Empty);
                var names = op.Signatures().SelectMany(s =>
                {
                    var bal = 0;
                    var eof = s.TakeWhile(c =>
                    {
                        if (c == '{') bal++;
                        if (c == '}') bal--;
                        if (bal == 0 && c == ' ') return false;
                        return true;
                    }).Count();

                    var arg_list = s.Slice(eof + 1).Trim();
                    arg_list = arg_list.Extract("^(?<name>.*?);?$");
                    var parsed_args = arg_list.Split(",".MkArray(), StringSplitOptions.RemoveEmptyEntries).Select(arg =>
                    {
                        arg = arg.Trim().Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "");
                        var parsed = arg.Trim().Parse(@"^(?<prefix>[!-])?(?<name>[\w\d]+)(\|(?<othername>[\w\d]+))?(\.(?<suffix>[\w\d]+))?$");
                        return parsed["name"];
                    }).ToReadOnly();

                    return parsed_args;
                }).Distinct().ToReadOnly();
                if (names.IsEmpty()) continue;

                names.ForEach(name =>
                {
                    use("Libptx.Expressions");
                    var decl = String.Format("public Expression {0} {{ get; set; }}", name);
                    if (text.Contains(decl))
                    {
                        var iof_decl = text.IndexOf(decl);
                        iof_decl -= "        ".Length;
                        iof_decl -= Environment.NewLine.Length * 2;
                        var iof_brace = text.IndexOf("}", iof_decl);
                        text = text.Remove(iof_decl, iof_brace - iof_decl + 1);
                    }

                    w.WriteLine(decl);
                });

                w.WriteLineNoTabs(String.Empty);
                use("Libcuda.Versions");
                w.WriteLine("protected override void custom_validate_ops(SoftwareIsa target_swisa, HardwareIsa target_hwisa)");
                w.WriteLine("{");
                w.Indent++;
                names.ForEach(name =>
                {
                    var props = op.GetProperties(BF.PublicInstance).Where(p => p.PropertyType == typeof(Type)).Select(p => p.Name).ToHashSet();

                    var prop = "N/A" as String;
                    if (props.Contains(name + "type")) prop = name + "type";
                    if (props.Contains("type")) prop = "type";

                    use("XenoGears.Assertions");
                    w.WriteLine("agree({0}, {1}).AssertTrue();", name, prop);
                });
                w.Indent--;
                w.Write("}");

                var iof = text.IndicesOf(c => c == '}').ThirdLastOrDefault(-1);
                if (iof == -1) continue;
                text = text.Insert(iof + 1, buf.ToString());
                File.WriteAllText(file, text);
            }
        }
开发者ID:xeno-by,项目名称:libptx,代码行数:89,代码来源:PtxopGenerator.cs

示例3: DoGenerate

        public static void DoGenerate()
        {
            var edsl_base = @"..\..\..\..\Libptx.Edsl\Libptx.Edsl\";
            var dir_types = edsl_base + @"Common\Types\";
            Func<String, String> dir2ns = dir =>
            {
                var rel = dir.Replace(@"..\..\..\..\Libptx.Edsl\", String.Empty);
                rel = (rel + @"\").Unfold(s => s.Slice(0, -1), s => s.EndsWith(@"\")).Last();
                return rel.Replace(@"\", ".").Slice(0, -1);
            };

            Types.Opaque.ForEach(t =>
            {
                var dir_opaques = dir_types + @"Opaque\";

                var buf = new StringBuilder();
                var w = new StringWriter(buf).Indented();
                w.WriteLine("using {0};", typeof(Expression).Namespace);
                w.WriteLineNoTabs(String.Empty);
                w.WriteLine("namespace {0}", dir2ns(dir_opaques));
                w.WriteLine("{");
                w.Indent++;
                w.WriteLine("public partial class {0} : typed_expr", t);
                w.WriteLine("{");
                w.Indent++;
                w.WriteLine("public {0}(Expression expr)", t);
                w.Indent++;
                w.WriteLine(": base(expr)");
                w.Indent--;
                w.WriteLine("{");
                w.Indent++;
                w.Indent--;
                w.WriteLine("}");
                w.Indent--;
                w.WriteLine("}");
                w.Indent--;
                w.WriteLine("}");

                var fname = dir_opaques + t + ".cs";
                if (!Directory.Exists(dir_opaques)) Directory.CreateDirectory(dir_opaques);
                File.WriteAllText(fname, buf.ToString());
            });

            Types.Other.ForEach(t =>
            {
                var dir_opaques = dir_types + @"Other\";

                var buf = new StringBuilder();
                var w = new StringWriter(buf).Indented();
                w.WriteLine("using {0};", typeof(Expression).Namespace);
                w.WriteLineNoTabs(String.Empty);
                w.WriteLine("namespace {0}", dir2ns(dir_opaques));
                w.WriteLine("{");
                w.Indent++;
                w.WriteLine("public partial class {0} : typed_expr", t);
                w.WriteLine("{");
                w.Indent++;
                w.WriteLine("public {0}(Expression expr)", t);
                w.Indent++;
                w.WriteLine(": base(expr)");
                w.Indent--;
                w.WriteLine("{");
                w.Indent++;
                w.Indent--;
                w.WriteLine("}");
                w.Indent--;
                w.WriteLine("}");
                w.Indent--;
                w.WriteLine("}");

                var fname = dir_opaques + t + ".cs";
                if (!Directory.Exists(dir_opaques)) Directory.CreateDirectory(dir_opaques);
                File.WriteAllText(fname, buf.ToString());
            });

            var scalars = Combinatorics.CartesianProduct(Types.Scalar, new []{ null, "reg" }, new []{null, "relaxed"}).ToReadOnly();
            scalars.Zip((t, mod1, mod2) =>
            {
                if (mod1 == null && mod2 == "relaxed") return;
                var mod = mod1 == null && mod2 == null ? null :
                    mod1 == "reg" && mod2 == null ? "reg" :
                    mod1 == "reg" && mod2 == "relaxed" ? "relaxed_reg" :
                    ((Func<String>)(() => { throw AssertionHelper.Fail(); }))();
                var name = t.Name.Signature();
                if (mod != null) name = mod + "_" + name;
                var dir = dir_types + @"Scalar\";

                var buf = new StringBuilder();
                var w = new StringWriter(buf).Indented();
                w.WriteLine("using {0};", typeof(Expression).Namespace);
                w.WriteLineNoTabs(String.Empty);
                w.WriteLine("namespace {0}", dir2ns(dir));
                w.WriteLine("{");
                w.Indent++;
                w.WriteLine("public partial class {0} : typed_expr", name);
                w.WriteLine("{");
                w.Indent++;
                w.WriteLine("public {0}(Expression expr)", name);
                w.Indent++;
                w.WriteLine(": base(expr)");
//.........这里部分代码省略.........
开发者ID:xeno-by,项目名称:libptx,代码行数:101,代码来源:TypeGenerator.cs

示例4: DoGenerate

        public static void DoGenerate()
        {
            var edsl_base = @"..\..\..\..\Libptx.Edsl\Libptx.Edsl\";
            var dir_vector = edsl_base + @"Expressions\Immediate\";
            var dir_vectors = edsl_base + @"Expressions\Immediate\Vectors\";
            Func<String, String> dir2ns = dir =>
            {
                var rel = dir.Replace(@"..\..\..\..\Libptx.Edsl\", String.Empty);
                rel = (rel + @"\").Unfold(s => s.Slice(0, -1), s => s.EndsWith(@"\")).Last();
                return rel.Replace(@"\", ".").Slice(0, -1);
            };

            var shortcuts = new Dictionary<int, List<String>>();
            new []{1, 2, 4}.ForEach(i => shortcuts.Add(i, new List<String>()));

            Types.Vector.ForEach(t =>
            {
                t.is_vec().AssertTrue();
                var name = String.Format("v{0}_{1}", t.vec_rank(), t.vec_el().Name.Signature());

                var buf_vec = new StringBuilder();
                var w_vec = new StringWriter(buf_vec).Indented();
                w_vec.WriteLine("using {0};", typeof(AssertionHelper).Namespace);
                w_vec.WriteLine("using {0};", typeof(Libptx.Edsl.Expressions.Slots.var).Namespace);
                w_vec.WriteLine("using Libptx.Edsl.Common.Types.Scalar;");
                w_vec.WriteLineNoTabs(String.Empty);
                w_vec.WriteLine("namespace {0}", dir2ns(dir_vectors));
                w_vec.WriteLine("{");
                w_vec.Indent++;
                w_vec.WriteLine("public class {0} : vector", name);
                w_vec.WriteLine("{");
                w_vec.Indent++;

                Func<int, String> arg_name = i => i == 1 ? "x" : i == 2 ? "y" : i == 3 ? "z" : i == 4 ? "w" : 
                    ((Func<String>)(() => { throw AssertionHelper.Fail(); }))();
                var args = 1.UpTo(t.vec_rank()).Select(i => String.Format("reg_{0} {1}", t.vec_el().Name.Signature(), arg_name(i))).StringJoin(", ");
                w_vec.WriteLine("public {0}({1})", name, args);

                var arg_names = 1.UpTo(t.vec_rank()).Select(arg_name).StringJoin(", ");
                shortcuts[t.vec_rank()].Add(String.Format("public static {0} v{1}({2}) {{ return new {0}({3}); }}", name, t.vec_rank(), args, arg_names));

                w_vec.WriteLine("{");
                w_vec.Indent++;
                w_vec.WriteLine("ElementType = {0};", t.vec_el().Name.Signature());
                1.UpTo(t.vec_rank()).ForEach(i => w_vec.WriteLine("Elements.Add({0}.AssertCast<var>());", arg_name(i)));
                w_vec.Indent--;
                w_vec.WriteLine("}");

                w_vec.WriteLineNoTabs(String.Empty);
                w_vec.EmitTypeSpec(name, t, Space.Reg, true);
                w_vec.Indent--;

                w_vec.WriteLine("}");
                w_vec.Indent--;
                w_vec.WriteLine("}");

                var fname_reg = dir_vectors + name + ".cs";
                if (!Directory.Exists(dir_vectors)) Directory.CreateDirectory(dir_vectors);
                File.WriteAllText(fname_reg, buf_vec.ToString());
            });

            var buf = new StringBuilder();
            var w = new StringWriter(buf).Indented();
            w.WriteLine("using {0};", typeof(Vector).Namespace);
            w.WriteLine("using Libptx.Edsl.Common.Types.Scalar;");
            w.WriteLine("using {0};", dir2ns(dir_vectors));
            w.WriteLineNoTabs(String.Empty);
            w.WriteLine("namespace {0}", dir2ns(dir_vector));
            w.WriteLine("{");
            w.Indent++;
            w.WriteLine("public class vector : Vector");
            w.WriteLine("{");
            w.Indent++;

            var write_shortcuts = shortcuts.Keys.Select<int, Action>(i => () => shortcuts[i].ForEach(w.WriteLine));
            var write_empty_lines = Seq.Nats.Select<int, Action>(_ => () => w.WriteLineNoTabs(String.Empty));
            write_shortcuts.Intersperse(write_empty_lines).SkipLast(1).RunEach();

            w.Indent--;
            w.WriteLine("}");
            w.Indent--;
            w.WriteLine("}");

            var fname = dir_vector + "vector.cs";
            if (!Directory.Exists(dir_vector)) Directory.CreateDirectory(dir_vector);
            File.WriteAllText(fname, buf.ToString());
        }
开发者ID:xeno-by,项目名称:libptx,代码行数:87,代码来源:VectorGenerator.cs


注:本文中的System.IO.StringWriter.WriteLineNoTabs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。