Skip to content

Commit 32837b0

Browse files
committed
Refactoring
1 parent 03bd610 commit 32837b0

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

Library/CppLang/Generator.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ public TFile[] Generate(SyntaxNode input)
176176

177177
static partial class Extensions
178178
{
179-
#region Utils
180-
181179
static public string GetName(this NamespaceDeclarationSyntax syntax)
182180
{
183181
return syntax.Name.ToString();
@@ -221,7 +219,5 @@ static public YType GetYType(this TypeSyntax typeSyntax)
221219

222220
throw new TException("Unsupported return type");
223221
}
224-
225-
#endregion
226222
}
227223
}

Library/CppLang/SourceCompiler.cs

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -68,71 +68,76 @@ internal protected override void Visit(StringBuilder builder, YMethod method)
6868
builder.Append(_typeMapper.ValueOf(method.Signature.Parameters));
6969
builder.Append(")");
7070

71-
Append(builder, method.Body);
71+
builder.AppendEx(method.Body);
7272
}
7373

74-
static void Append(StringBuilder builder, YStatement statement)
74+
internal protected override void FinalizeBuilder(StringBuilder builder)
7575
{
76-
if (statement is YBlock) {
77-
var block = (YBlock)statement;
76+
base.FinalizeBuilder(builder);
7877

79-
builder.Append("{");
78+
builder.Replace(IncludesMark, "");
8079

81-
foreach (var s in block.Statements) {
82-
Append(builder, s);
83-
}
80+
// only default constructor supported
81+
_constructor.Append("{}");
8482

85-
builder.Append("}");
86-
} else if (statement is YReturn) {
87-
var @return = (YReturn)statement;
83+
builder.Replace(ConstructorsMark, _constructor.ToString());
84+
}
85+
}
8886

89-
builder.Append("return ");
90-
Append(builder, @return.Value);
91-
builder.Append(";");
87+
public override UnitWalker CreateUnitWalker(YClass @class)
88+
{
89+
return new SourceWalker(@class);
90+
}
91+
}
9292

93-
} else if (statement is YAssign) {
94-
var assign = (YAssign)statement;
93+
public static partial class Extensions
94+
{
9595

96-
Append(builder, assign.Left);
97-
builder.Append("=");
98-
Append(builder, assign.Right);
99-
builder.Append(";");
100-
}
101-
}
96+
static public void AppendEx(this StringBuilder builder, YStatement statement)
97+
{
98+
if (statement is YBlock) {
99+
var block = (YBlock)statement;
102100

103-
static void Append(StringBuilder builder, YExpr expr)
104-
{
105-
if (expr is YConstExpr) {
106-
builder.Append("" + expr);
107-
} else if (expr is YThisExpr) {
108-
builder.Append("this");
109-
} else if (expr is YMemberAccessExpr) {
110-
var memberAccess = (YMemberAccessExpr)expr;
111-
112-
Append(builder, memberAccess.Expression);
113-
builder.Append("->"); // But what with "this."?
114-
builder.Append(memberAccess.Name);
115-
} else if (expr is YIdentifierExpr) {
116-
builder.Append(((YIdentifierExpr)expr).Name);
101+
builder.Append("{");
102+
103+
foreach (var s in block.Statements) {
104+
AppendEx(builder, s);
117105
}
118-
}
119106

120-
internal protected override void FinalizeBuilder(StringBuilder builder)
121-
{
122-
base.FinalizeBuilder(builder);
107+
builder.Append("}");
108+
} else if (statement is YReturn) {
109+
var @return = (YReturn)statement;
123110

124-
builder.Replace(IncludesMark, "");
111+
builder.Append("return ");
112+
AppendEx(builder, @return.Value);
113+
builder.Append(";");
125114

126-
// only default constructor supported
127-
_constructor.Append("{}");
115+
} else if (statement is YAssign) {
116+
var assign = (YAssign)statement;
128117

129-
builder.Replace(ConstructorsMark, _constructor.ToString());
118+
AppendEx(builder, assign.Left);
119+
builder.Append("=");
120+
AppendEx(builder, assign.Right);
121+
builder.Append(";");
130122
}
131123
}
132124

133-
public override UnitWalker CreateUnitWalker(YClass @class)
125+
static public void AppendEx(this StringBuilder builder, YExpr expr)
134126
{
135-
return new SourceWalker(@class);
127+
if (expr is YConstExpr) {
128+
builder.Append("" + expr);
129+
} else if (expr is YThisExpr) {
130+
builder.Append("this");
131+
} else if (expr is YMemberAccessExpr) {
132+
var memberAccess = (YMemberAccessExpr)expr;
133+
134+
AppendEx(builder, memberAccess.Expression);
135+
builder.Append("->"); // But what with "this."?
136+
builder.Append(memberAccess.Name);
137+
} else if (expr is YIdentifierExpr) {
138+
builder.Append(((YIdentifierExpr)expr).Name);
139+
}
136140
}
141+
137142
}
138143
}

0 commit comments

Comments
 (0)