Skip to content

Commit

Permalink
TVar, TBlock, TFor, TIf, TWhile, TSwitch
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyfa committed Apr 14, 2024
1 parent 9b51c51 commit 5f56373
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 62 deletions.
8 changes: 4 additions & 4 deletions src/cscompiler/CSCompiler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ namespace Haxe {
name: compileVarName(name),
type: compileType(t, pos),
opt: optional,
value: expr != null ? compileCSExpr(expr) : null
value: expr != null ? compileToCSExpr(expr) : null
};
}

Expand All @@ -282,7 +282,7 @@ namespace Haxe {
// TODO: do we need to unwrap and optimize in that case?
//final exprs = ExprOptimizer.optimizeAndUnwrap(expr);

return compileCSExpr(expr);
return compileToCSExpr(expr);
}

public function compileClassFuncExpr(expr: TypedExpr): Null<CSStatement> {
Expand All @@ -292,8 +292,8 @@ namespace Haxe {
/**
Compile an expression and ensure it is an actual C# expression (not a statement)
**/
public function compileCSExpr(expr: TypedExpr): Null<CSExpr> {
return exprComp.compileCSExpr(expr);
public function compileToCSExpr(expr: TypedExpr): Null<CSExpr> {
return exprComp.compileToCSExpr(expr);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/cscompiler/ast/CSStatement.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ enum CSStatementDef {

CSWhile(condition: CSExpr, content: Array<CSStatement>, normalWhile: Bool);

/**
Used for TFor, although in practice it's not really happening as all
TFor are converted to while
**/
CSForeach(varData: CSVar, iterExpr: CSExpr, content: Array<CSStatement>);

/**
C# Switch
**/
CSSwitch(subject: CSExpr, cases:Array<{value: CSExpr, content: Null<Array<CSStatement>>}>, edef: Null<Array<CSStatement>>);

CSBreak;

CSContinue;

/**
A variable declaration `var varData` or `var varData = expr`.
**/
Expand Down
1 change: 1 addition & 0 deletions src/cscompiler/ast/CSVar.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cscompiler.ast;
/**
Represents a variable in C#.
**/
@:structInit
class CSVar {
/**
TODO:
Expand Down
Loading

0 comments on commit 5f56373

Please sign in to comment.