11package cscompiler ;
22
33#if(macro || cs_runtime)
4- import sys .io .File ;
4+ import cscompiler .ast .CSTypePath ;
5+ import cscompiler .ast .CSExpr ;
6+ import cscompiler .ast .CSArg ;
7+ import cscompiler .ast .CSTopLevel ;
8+ import cscompiler .ast .CSClass ;
9+ import cscompiler .ast .CSEnum ;
10+ import cscompiler .ast .CSStatement ;
11+ import cscompiler .ast .CSType ;
12+ import cscompiler .components .* ;
13+ import cscompiler .config .Define ;
514
615import haxe .io .Path ;
716import haxe .macro .Expr ;
817import haxe .macro .Type ;
918
10- // ---
19+ import sys .io .File ;
20+
1121import reflaxe .BaseCompiler ;
1222import reflaxe .GenericCompiler ;
1323import reflaxe .data .ClassVarData ;
@@ -17,25 +27,15 @@ import reflaxe.helpers.Context;
1727import reflaxe .output .DataAndFileInfo ;
1828import reflaxe .output .StringOrBytes ;
1929
20- using reflaxe . helpers . SyntaxHelper ;
30+ // ---
2131using reflaxe .helpers .ModuleTypeHelper ;
2232using reflaxe .helpers .NameMetaHelper ;
2333using reflaxe .helpers .NullableMetaAccessHelper ;
34+ using reflaxe .helpers .NullHelper ;
2435using reflaxe .helpers .OperatorHelper ;
36+ using reflaxe .helpers .SyntaxHelper ;
2537using reflaxe .helpers .TypeHelper ;
2638
27- // ---
28- import cscompiler .ast .CSTypePath ;
29- import cscompiler .ast .CSExpr ;
30- import cscompiler .ast .CSArg ;
31- import cscompiler .ast .CSTopLevel ;
32- import cscompiler .ast .CSClass ;
33- import cscompiler .ast .CSEnum ;
34- import cscompiler .ast .CSStatement ;
35- import cscompiler .ast .CSType ;
36- import cscompiler .components .* ;
37- import cscompiler .config .Define ;
38-
3939/**
4040 The class that manages the generation of the C# code.
4141
@@ -134,15 +134,17 @@ class CSCompiler extends reflaxe.GenericCompiler<CSTopLevel, CSTopLevel, CSState
134134 Store `args` to use with `Sys.args()` later.
135135 **/
136136 function haxeBootContent (csCode : String ) {
137- return StringTools .trim ('
137+ return StringTools .trim (
138+ '
138139namespace Haxe {
139140 class HaxeBoot {
140141 static void Main(string[] args) {
141142 ${csCode };
142143 }
143144 }
144145}
145- ' );
146+ '
147+ );
146148 }
147149
148150 /**
@@ -171,7 +173,8 @@ namespace Haxe {
171173 Returns the default content of the .csproj file.
172174 **/
173175 function csProjDefaultContent () {
174- return StringTools .trim ('
176+ return StringTools .trim (
177+ '
175178<Project Sdk="Microsoft.NET.Sdk">
176179
177180<PropertyGroup>
@@ -183,7 +186,8 @@ namespace Haxe {
183186</PropertyGroup>
184187
185188</Project>
186- ' );
189+ '
190+ );
187191 }
188192
189193 /**
@@ -198,31 +202,24 @@ namespace Haxe {
198202 TODO.
199203 **/
200204 public function generateOutputIterator (): Iterator <DataAndFileInfo <StringOrBytes >> {
201- // TODO: Print all classes and enums using these vars from `GenericCompiler`:
202- // var classes: Array<CSClass>
203- // var enums: Array<CSEnum>
204-
205- return {
206- hasNext : () -> false ,
207- next : () -> {
208- return new DataAndFileInfo (StringOrBytes .fromString (" " ), @:nullSafety (Off ) null , null , null );
209- }
210- };
205+ return new CSOutputIterator (this );
211206 }
212207
213208 // ---
214209
215210 /**
216211 Generate the C# output given the Haxe class information.
217212 **/
218- public function compileClassImpl (classType : ClassType , varFields : Array <ClassVarData >, funcFields : Array <ClassFuncData >): Null <CSTopLevel > {
213+ public function compileClassImpl (classType : ClassType , varFields : Array <ClassVarData >,
214+ funcFields : Array <ClassFuncData >): Null <CSTopLevel > {
219215 return classComp .compile (classType , varFields , funcFields );
220216 }
221217
222218 /**
223219 Generate the C# output given the Haxe enum information.
224220 **/
225- public function compileEnumImpl (enumType : EnumType , options : Array <EnumOptionData >): Null <CSTopLevel > {
221+ public function compileEnumImpl (enumType : EnumType ,
222+ options : Array <EnumOptionData >): Null <CSTopLevel > {
226223 return enumComp .compile (enumType , options );
227224 }
228225
@@ -257,14 +254,23 @@ namespace Haxe {
257254 return typeComp .compileClassName (classType );
258255 }
259256
257+ /**
258+ Get the name of the `EnumType` as it should appear in
259+ the C# output.
260+ **/
261+ public function compileEnumName (enumType : EnumType ): String {
262+ return typeComp .compileEnumName (enumType );
263+ }
264+
260265 // ---
261266
262267 /**
263268 Generate the C# output for a function argument.
264269
265270 Note: it's possible for an argument to be optional but not have an `expr`.
266271 **/
267- public function compileFunctionArgument (t : Type , name : String , pos : Position , optional : Bool , expr : Null <TypedExpr > = null ): CSArg {
272+ public function compileFunctionArgument (t : Type , name : String , pos : Position , optional : Bool ,
273+ expr : Null <TypedExpr > = null ): CSArg {
268274 return {
269275 name : compileVarName (name ),
270276 type : compileType (t , pos ),
@@ -314,7 +320,7 @@ namespace Haxe {
314320 // a block, and make this method not needed anymore
315321
316322 final lines = s .split (" \n " );
317- for (i in 0 ... lines .length ) {
323+ for (i in 0 ... lines .length ) {
318324 lines [i ] = StringTools .rtrim (lines [i ]);
319325 }
320326 return lines .join (" \n " );
@@ -327,8 +333,8 @@ namespace Haxe {
327333 **/
328334 public function nameToHash (name : String ): Int {
329335 var h : Int = 0 ;
330- for (i in 0 ... name .length ) {
331- h = 223 * h + name .charCodeAt (i );
336+ for (i in 0 ... name .length ) {
337+ h = 223 * h + name .charCodeAt (i ). trustMe () ;
332338 }
333339 h % = 0x1FFFFF7B ;
334340
0 commit comments