Skip to content

Commit a827947

Browse files
committed
Move rendering entirely to templates
1 parent e4e90ca commit a827947

635 files changed

Lines changed: 8614 additions & 10149 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
# Verify
3030
*.received.*
3131
*.received/
32-
**/Templates/*.cs
32+
**/Templates/**.cs

Docs/Generator.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Generator rules:
2+
- Generators should be able to run multiple times, but only output new structures. That is, any shared helpers, object declarations, etc. should be output only once.
3+
- Generator's output should be configurable by users. The FastData.Generator.Template package helps developing templatable generators using the T4 template engine.
4+
- Generators should provide placeholders that configures the output across all templates. For example, in C#, the user might want to generate a static class instead of an instance class. Instead of having them go through all templates and update them to accomodate the need, they simply set ClassType = Static.
5+
- Generators must be named <Lang>CodeGenerator as the naming scheme is assumed elsewhere.
6+
7+
## Supporting core features
8+
The FastData engine supports several core features that a generator developer can use. However, to support them, you must do the following:
9+
10+
- Trimming: You must use the InputKeyName/LookupKeyName abstraction, as the engine will switch the name if trimming is enabled
11+
- Early exits: You must render the early exit expression at the top of public API methods. TODO: Which expressions to support in compiler?
12+
- Case sensitivity support: You must provide an indirection for string comparison and switch between case-sensitive and case-insensitive matching depending on the value of Config.IgnoreCase.

Src/FastData.Benchmarks/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private static void DoStructure(Type type, int size)
5959
Random rng = new Random(42);
6060
string[] data = Enumerable.Range(0, size).Select(_ => TestHelper.GenerateRandomString(rng, rng.Next(5, 10))).ToArray();
6161

62-
CSharpCodeGenerator generator = CSharpCodeGenerator.Create(new CSharpCodeGeneratorConfig("fastdata"));
62+
CSharpCodeGenerator generator = new CSharpCodeGenerator(new CSharpCodeGeneratorConfig("fastdata"));
6363

6464
StringDataConfig config = new StringDataConfig();
6565
config.StructureTypeOverride = type;

Src/FastData.Cli/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ internal static async Task<int> Main(string[] args)
139139
genCfg.ClassVisibility = cv;
140140
genCfg.ClassType = ct;
141141

142-
CSharpCodeGenerator generator = CSharpCodeGenerator.Create(genCfg);
142+
CSharpCodeGenerator generator = new CSharpCodeGenerator(genCfg);
143143

144144
await GenerateAsync(inputFile, keyType, structureType, ignoreCase, generator, outputFile, token).ConfigureAwait(false);
145145
});
@@ -154,7 +154,7 @@ internal static async Task<int> Main(string[] args)
154154
string? cn = pr.GetValue(classNameOpt);
155155

156156
CPlusPlusCodeGeneratorConfig genCfg = new CPlusPlusCodeGeneratorConfig(cn);
157-
CPlusPlusCodeGenerator generator = CPlusPlusCodeGenerator.Create(genCfg);
157+
CPlusPlusCodeGenerator generator = new CPlusPlusCodeGenerator(genCfg);
158158

159159
await GenerateAsync(inputFile, keyType, structureType, ignoreCase, generator, outputFile, token).ConfigureAwait(false);
160160
});
@@ -169,7 +169,7 @@ internal static async Task<int> Main(string[] args)
169169
string? cn = pr.GetValue(classNameOpt);
170170

171171
RustCodeGeneratorConfig genCfg = new RustCodeGeneratorConfig(cn);
172-
RustCodeGenerator generator = RustCodeGenerator.Create(genCfg);
172+
RustCodeGenerator generator = new RustCodeGenerator(genCfg);
173173

174174
await GenerateAsync(inputFile, keyType, structureType, ignoreCase, generator, outputFile, token).ConfigureAwait(false);
175175
});

Src/FastData.Examples/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static class Program
88
private static void Main()
99
{
1010
StringDataConfig config = new StringDataConfig();
11-
CSharpCodeGenerator generator = CSharpCodeGenerator.Create(new CSharpCodeGeneratorConfig("Dogs"));
11+
CSharpCodeGenerator generator = new CSharpCodeGenerator(new CSharpCodeGeneratorConfig("Dogs"));
1212

1313
string source = FastDataGenerator.Generate(["Labrador", "German Shepherd", "Golden Retriever"], config, generator);
1414
Console.WriteLine(source);

Src/FastData.Generator.CPlusPlus.TestHarness/CPlusPlusBootstrap.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Genbox.FastData.Enums;
22
using Genbox.FastData.Generator.CPlusPlus.Internal;
33
using Genbox.FastData.Generator.CPlusPlus.Internal.Framework;
4-
using Genbox.FastData.Generator.Framework;
54
using Genbox.FastData.Generators.Abstracts;
65
using Genbox.FastData.InternalShared.Harness;
76
using Genbox.FastData.InternalShared.Harness.Enums;
@@ -18,7 +17,7 @@ public CPlusPlusBootstrap(HarnessType type) : base("CPlusPlus", ".cpp", type, "s
1817

1918
public TypeMap Map { get; }
2019

21-
public override ICodeGenerator Generator => CPlusPlusCodeGenerator.Create(new CPlusPlusCodeGeneratorConfig("fastdata"));
20+
public override ICodeGenerator Generator => new CPlusPlusCodeGenerator(new CPlusPlusCodeGeneratorConfig("fastdata"));
2221

2322
public override string Wrap(string code) =>
2423
$$"""

0 commit comments

Comments
 (0)