Skip to content

Commit 938aee8

Browse files
committed
Added c++ code generation for function nodes.
1 parent f97fe47 commit 938aee8

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CodeGenerator/CppCodeGenerator.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public string GenerateCode(IEnumerable<ClassNode> classes, ILogger logger)
4848
sb.AppendLine(
4949
string.Join(
5050
"\n\n",
51-
OrderByInheritance(classes).Select(c =>
51+
OrderByInheritance(classes.Where(c => c.Nodes.All(n => !(n is FunctionNode)))).Select(c =>
5252
{
5353
var csb = new StringBuilder();
5454
csb.Append($"class {c.Name}");
@@ -74,7 +74,7 @@ public string GenerateCode(IEnumerable<ClassNode> classes, ILogger logger)
7474
csb.AppendLine(
7575
string.Join(
7676
"\n",
77-
YieldMemberDefinitions(c.Nodes.Skip(skipFirstMember ? 1 : 0), logger)
77+
YieldMemberDefinitions(c.Nodes.Skip(skipFirstMember ? 1 : 0).Where(n => !(n is FunctionNode)), logger)
7878
.Select(m => MemberDefinitionToString(m))
7979
.Select(s => "\t" + s)
8080
)
@@ -92,6 +92,18 @@ public string GenerateCode(IEnumerable<ClassNode> classes, ILogger logger)
9292
);
9393
}
9494

95+
var functions = classes.SelectMany(c2 => c2.Nodes).OfType<FunctionNode>().Where(f => f.BelongsToClass == c);
96+
if (functions.Any())
97+
{
98+
csb.AppendLine();
99+
csb.AppendLine(
100+
string.Join(
101+
"\n",
102+
functions.Select(f => $"\t{f.Signature} {{ }}")
103+
)
104+
);
105+
}
106+
95107
csb.Append($"}}; //Size: 0x{c.MemorySize:X04}");
96108
return csb.ToString();
97109
})

Nodes/FunctionNode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class FunctionNode : BaseNode
1313
private IntPtr address = IntPtr.Zero;
1414
private readonly List<string> instructions = new List<string>();
1515

16-
private string signature = "void function()";
16+
public string Signature { get; set; } = "void function()";
1717

1818
public ClassNode BelongsToClass { get; set; }
1919

@@ -64,7 +64,7 @@ public override int Draw(ViewInfo view, int x, int y)
6464
{
6565
y += view.Font.Height;
6666
x = AddText(view, tx, y, Program.Settings.TypeColor, HotSpot.NoneId, "Signature:") + view.Font.Width;
67-
x = AddText(view, x, y, Program.Settings.ValueColor, 0, signature);
67+
x = AddText(view, x, y, Program.Settings.ValueColor, 0, Signature);
6868

6969
y += view.Font.Height;
7070
x = AddText(view, tx, y, Program.Settings.TextColor, HotSpot.NoneId, "Belongs to: ");
@@ -103,7 +103,7 @@ public override void Update(HotSpot spot)
103103

104104
if (spot.Id == 0) // Signature
105105
{
106-
signature = spot.Text;
106+
Signature = spot.Text;
107107
}
108108
else if (spot.Id == 1)
109109
{

0 commit comments

Comments
 (0)