Skip to content

Commit 37ea99e

Browse files
committed
Apply formatter
1 parent d2ae689 commit 37ea99e

32 files changed

+862
-1075
lines changed

src/cscompiler/CSCompiler.hx

Lines changed: 57 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package cscompiler;
22

3-
#if (macro || cs_runtime)
4-
3+
#if(macro || cs_runtime)
54
import sys.io.File;
65

76
import haxe.io.Path;
87
import haxe.macro.Expr;
98
import haxe.macro.Type;
109

1110
// ---
12-
1311
import reflaxe.BaseCompiler;
1412
import reflaxe.GenericCompiler;
1513
import reflaxe.data.ClassVarData;
@@ -27,7 +25,6 @@ using reflaxe.helpers.OperatorHelper;
2725
using reflaxe.helpers.TypeHelper;
2826

2927
// ---
30-
3128
import cscompiler.ast.CSTypePath;
3229
import cscompiler.ast.CSExpr;
3330
import cscompiler.ast.CSArg;
@@ -49,40 +46,40 @@ class CSCompiler extends reflaxe.GenericCompiler<CSTopLevel, CSTopLevel, CSState
4946
The namespace used for top-level module types.
5047
**/
5148
public static final DEFAULT_ROOT_NAMESPACE = "haxe.root";
52-
49+
5350
/**
5451
Handles implementation of `compileClassImpl`.
5552
**/
5653
public var classComp(default, null): CSCompiler_Class;
57-
54+
5855
/**
5956
Handles implementation of `compileEnumImpl`.
6057
**/
6158
public var enumComp(default, null): CSCompiler_Enum;
62-
59+
6360
/**
6461
Handles implementation of `compileExprImpl`.
6562
**/
6663
public var exprComp(default, null): CSCompiler_Expr;
67-
64+
6865
/**
6966
Handles implementation of `compileType`, `compileModuleType`, and `compileClassName`.
7067
**/
7168
public var typeComp(default, null): CSCompiler_Type;
72-
69+
7370
/**
7471
Keep the inverted mapping of `nameToHashTable` to handle potential collisions
7572
**/
76-
public var hashToNameTable(default, null): Map<Int,String> = new Map();
77-
73+
public var hashToNameTable(default, null): Map<Int, String> = new Map();
74+
7875
/**
7976
Constructor.
8077
**/
8178
public function new() {
8279
super();
8380
createComponents();
8481
}
85-
82+
8683
/**
8784
Constructs all the components of the compiler.
8885
@@ -91,45 +88,45 @@ class CSCompiler extends reflaxe.GenericCompiler<CSTopLevel, CSTopLevel, CSState
9188
inline function createComponents() {
9289
// Bypass Haxe null-safety not allowing `this` usage.
9390
@:nullSafety(Off) var self = this;
94-
91+
9592
classComp = new CSCompiler_Class(self);
9693
enumComp = new CSCompiler_Enum(self);
9794
exprComp = new CSCompiler_Expr(self);
9895
typeComp = new CSCompiler_Type(self);
9996
}
100-
97+
10198
// ---
102-
99+
103100
/**
104101
The file name used for main function code.
105102
106103
TODO: Was this the name used in the original Haxe/C# target?
107104
**/
108105
static final BootFilename = "HaxeBoot.cs";
109-
106+
110107
/**
111108
Called at the start of compilation.
112109
**/
113110
public override function onCompileStart() {
114111
setupMainFunction();
115112
setupCsProj();
116113
}
117-
114+
118115
/**
119116
If -main exists, generate a Main function in C#.
120117
**/
121118
function setupMainFunction() {
122119
final mainExpr = getMainExpr();
123120
if(mainExpr != null) {
124121
final csExpr = compileExpressionOrError(mainExpr);
125-
122+
126123
// TODO: Convert `csExpr` to `String` using printer
127124
final csCode = "";
128-
125+
129126
appendToExtraFile(BootFilename, haxeBootContent(csCode));
130127
}
131128
}
132-
129+
133130
/**
134131
Returns the content generated for the `HaxeBoot.cs`.
135132
@@ -147,7 +144,7 @@ namespace Haxe {
147144
}
148145
');
149146
}
150-
147+
151148
/**
152149
Adds a .csproj file to the output directory.
153150
@@ -159,17 +156,17 @@ namespace Haxe {
159156
Otherwise, a default .csproj is generated.
160157
**/
161158
function setupCsProj() {
162-
if (D_NoCsproj.isDefined()) {
159+
if(D_NoCsproj.isDefined()) {
163160
return;
164161
}
165-
if (!D_Csproj.isDefined()) {
162+
if(!D_Csproj.isDefined()) {
166163
appendToExtraFile("build.csproj", csProjDefaultContent());
167164
return;
168165
}
169166
final path = new Path(Context.resolvePath(D_Csproj.getValue()));
170167
appendToExtraFile('${path.file}.${path.ext}', File.getContent(path.toString()));
171168
}
172-
169+
173170
/**
174171
Returns the default content of the .csproj file.
175172
**/
@@ -188,13 +185,13 @@ namespace Haxe {
188185
</Project>
189186
');
190187
}
191-
188+
192189
/**
193190
Called at the end of compilation.
194191
**/
195192
public override function onCompileEnd() {
196193
}
197-
194+
198195
/**
199196
Generate output.
200197
@@ -204,33 +201,33 @@ namespace Haxe {
204201
// TODO: Print all classes and enums using these vars from `GenericCompiler`:
205202
// var classes: Array<CSClass>
206203
// var enums: Array<CSEnum>
207-
204+
208205
return {
209206
hasNext: () -> false,
210207
next: () -> {
211208
return new DataAndFileInfo(StringOrBytes.fromString(""), @:nullSafety(Off) null, null, null);
212209
}
213210
};
214211
}
215-
212+
216213
// ---
217-
214+
218215
/**
219216
Generate the C# output given the Haxe class information.
220217
**/
221218
public function compileClassImpl(classType: ClassType, varFields: Array<ClassVarData>, funcFields: Array<ClassFuncData>): Null<CSTopLevel> {
222219
return classComp.compile(classType, varFields, funcFields);
223220
}
224-
221+
225222
/**
226223
Generate the C# output given the Haxe enum information.
227224
**/
228225
public function compileEnumImpl(enumType: EnumType, options: Array<EnumOptionData>): Null<CSTopLevel> {
229226
return enumComp.compile(enumType, options);
230227
}
231-
228+
232229
// ---
233-
230+
234231
/**
235232
Generates the C# type from `haxe.macro.Type`.
236233
@@ -243,112 +240,107 @@ namespace Haxe {
243240
}
244241
return result;
245242
}
246-
243+
247244
/**
248245
Generate C# output for `ModuleType` used in an expression
249246
(i.e. for cast or static access).
250247
**/
251248
public function compileModuleType(m: ModuleType): CSTypePath {
252249
return typeComp.compileModuleType(m);
253250
}
254-
251+
255252
/**
256253
Get the name of the `ClassType` as it should appear in
257254
the C# output.
258255
**/
259256
public function compileClassName(classType: ClassType): String {
260257
return typeComp.compileClassName(classType);
261258
}
262-
259+
263260
// ---
264-
261+
265262
/**
266263
Generate the C# output for a function argument.
267264
268265
Note: it's possible for an argument to be optional but not have an `expr`.
269266
**/
270-
public function compileFunctionArgument(t: Type, name: String, pos: Position, optional: Bool, expr: Null<TypedExpr> = null):CSArg {
267+
public function compileFunctionArgument(t: Type, name: String, pos: Position, optional: Bool, expr: Null<TypedExpr> = null): CSArg {
271268
return {
272269
name: compileVarName(name),
273270
type: compileType(t, pos),
274271
opt: optional,
275272
value: expr != null ? compileToCSExpr(expr) : null
276273
};
277274
}
278-
275+
279276
public function compileClassVarExpr(expr: TypedExpr): Null<CSExpr> {
280277
return compileToCSExpr(expr);
281278
}
282-
279+
283280
public function compileClassFuncExpr(expr: TypedExpr): Null<CSStatement> {
284281
return compileExpression(expr);
285282
}
286-
283+
287284
/**
288285
Compile an expression and ensure it is an actual C# expression (not a statement)
289286
**/
290287
public function compileToCSExpr(expr: TypedExpr): Null<CSExpr> {
291288
return exprComp.compileToCSExpr(expr);
292289
}
293-
290+
294291
/**
295292
Generate the C# output given the Haxe typed expression (`TypedExpr`).
296293
**/
297294
public function compileExpressionImpl(expr: TypedExpr, topLevel: Bool): Null<CSStatement> {
298295
return exprComp.compile(expr, topLevel);
299296
}
300-
297+
301298
/**
302299
Wrap a block of code with the given name space
303300
**/
304-
public function wrapNameSpace(nameSpace: String, s: String):String {
301+
public function wrapNameSpace(nameSpace: String, s: String): String {
305302
return "namespace " + nameSpace + " {\n" + StringTools.rtrim(s.tab()) + "\n}\n";
306303
}
307-
304+
308305
/**
309306
Remove blank white space at the end of each line,
310307
and trim empty lines.
311308
**/
312-
public function cleanWhiteSpaces(s: String):String {
313-
309+
public function cleanWhiteSpaces(s: String): String {
314310
// Temporary workaround.
315-
311+
316312
// TODO: edit reflaxe SyntaxHelper.tab() so that it
317313
// doesn't add spaces/tabs to empty lines when indenting
318314
// a block, and make this method not needed anymore
319-
315+
320316
final lines = s.split("\n");
321-
for(i in 0...lines.length) {
317+
for (i in 0...lines.length) {
322318
lines[i] = StringTools.rtrim(lines[i]);
323319
}
324320
return lines.join("\n");
325321
}
326-
322+
327323
/**
328324
Get a hash code for the given name. If the name is new,
329325
add an entry to `hashToNameTable` so that it can be used
330326
for field lookup in generated code.
331327
**/
332328
public function nameToHash(name: String): Int {
333-
334-
var h:Int = 0;
335-
for (i in 0...name.length) {
336-
h = 223 * h + name.charCodeAt(i);
337-
}
338-
h %= 0x1FFFFF7B;
339-
340-
while (hashToNameTable.exists(h) && hashToNameTable.get(h) != name) {
329+
var h: Int = 0;
330+
for (i in 0...name.length) {
331+
h = 223 * h + name.charCodeAt(i);
332+
}
333+
h %= 0x1FFFFF7B;
334+
335+
while(hashToNameTable.exists(h) && hashToNameTable.get(h) != name) {
341336
h++;
342337
}
343-
344-
if (!hashToNameTable.exists(h)) {
338+
339+
if(!hashToNameTable.exists(h)) {
345340
hashToNameTable.set(h, name);
346341
}
347-
342+
348343
return h;
349-
350344
}
351-
352345
}
353-
354-
#end
346+
#end

0 commit comments

Comments
 (0)