-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin work on C# AST, increment to v0.2
- Loading branch information
1 parent
be746fc
commit 9c17288
Showing
16 changed files
with
366 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cscompiler.ast; | ||
|
||
#if (macro || cs_runtime) | ||
|
||
/** | ||
Represents a class in C#. | ||
TODO. | ||
**/ | ||
class CSClass { | ||
public var name(default, null): String; | ||
|
||
var superClass: Null<CSClass>; | ||
var superClassTypeParams: Null<Array<CSType>>; | ||
|
||
public function new(name: String) { | ||
this.name = name; | ||
} | ||
|
||
public function setSuperClass(superClass: CSClass, typeParams: Array<CSType>) { | ||
this.superClass = superClass; | ||
superClassTypeParams = typeParams; | ||
} | ||
} | ||
|
||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cscompiler.ast; | ||
|
||
#if (macro || cs_runtime) | ||
|
||
/** | ||
Represents a constant expression. | ||
TODO: Give each case a better description. | ||
**/ | ||
enum CSConstant { | ||
CSInt(i: Int, suffix: String); | ||
|
||
/** | ||
TODO: | ||
Should there be a `CSDouble`? | ||
Or some better way to handle differen suffixes? | ||
**/ | ||
CSFloat(s: String, suffix: String); | ||
|
||
CSString(s: String); | ||
CSBool(b: Bool); | ||
|
||
CSNull; | ||
CSThis; | ||
CSSuper; | ||
} | ||
|
||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cscompiler.ast; | ||
|
||
#if (macro || cs_runtime) | ||
|
||
/** | ||
Represents an enum in C#. | ||
TODO. | ||
**/ | ||
class CSEnum { | ||
public var name(default, null): String; | ||
|
||
public function new(name: String) { | ||
this.name = name; | ||
} | ||
} | ||
|
||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package cscompiler.ast; | ||
|
||
#if (macro || cs_runtime) | ||
|
||
import haxe.macro.Expr; | ||
import haxe.macro.Type; | ||
|
||
/** | ||
Represents a C# expression. | ||
**/ | ||
class CSExpr { | ||
public var def(default, null): CSExprDef; | ||
public var haxeExpr(default, null): Null<TypedExpr>; | ||
|
||
public function new(def: CSExprDef, haxeExpr: Null<TypedExpr> = null) { | ||
this.def = def; | ||
this.haxeExpr = haxeExpr; | ||
} | ||
} | ||
|
||
/** | ||
TODO: Give each case a better description. | ||
**/ | ||
enum CSExprDef { | ||
/** | ||
A constant. | ||
**/ | ||
CSConst(constant: CSConstant); | ||
|
||
/** | ||
Reference to a local variable `varData`. | ||
**/ | ||
CSLocalVar(varData: CSVar); | ||
|
||
/** | ||
Array access `baseExpr[indexExpr]`. | ||
**/ | ||
CSArray(baseExpr: CSExpr, indexExpr: CSExpr); | ||
|
||
/** | ||
Binary operator `leftExpr op rightExpr`. | ||
**/ | ||
CSBinop(op: Binop, leftExpr: CSExpr, rightExpr: CSExpr); | ||
|
||
/** | ||
Field access on `e` of name `fieldName`. | ||
TODO: | ||
Replace `fieldName: String` with a custom `FieldAccess` type (`fieldAccess: CSFieldAccess`)? | ||
**/ | ||
CSField(e: CSExpr, fieldName: String); | ||
|
||
/** | ||
Reference to a module type `m`. | ||
TODO: | ||
This is assuming static-access is only possible from a class in C#? | ||
Maybe this should be replaced with a `CSStaticVar(varData: CSVar, cls: CSClass)`. | ||
**/ | ||
CSClassExpr(cls: CSClass); | ||
|
||
/** | ||
Parentheses `(e)`. | ||
**/ | ||
CSParenthesis(e: CSExpr); | ||
|
||
/** | ||
An array declaration `{ expressions }`. | ||
**/ | ||
CSArrayDecl(expressions: Array<CSExpr>); | ||
|
||
/** | ||
A call `baseExpr<typeParams>(arguments)`. | ||
**/ | ||
CSCall(baseExpr: CSExpr, typeParams: Array<CSType>, arguments: Array<CSExpr>); | ||
|
||
/** | ||
A constructor call `new cls<typeParams>(arguments)`. | ||
**/ | ||
CSNew(cls: CSClass, typeParams: Array<CSType>, arguments: Array<CSExpr>); | ||
|
||
/** | ||
An unary operator `op` on `baseExpr`. | ||
TODO: | ||
Is postfix necessary? | ||
**/ | ||
CSUnop(op: Unop, postFix: Bool, baseExpr: CSExpr); | ||
|
||
/** | ||
A function declaration. | ||
**/ | ||
CSFunctionExpr(tfunc: CSFunction); | ||
|
||
/** | ||
An unknown identifier. | ||
**/ | ||
CSIdent(s: String); | ||
} | ||
|
||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cscompiler.ast; | ||
|
||
#if (macro || cs_runtime) | ||
|
||
/** | ||
Represents a function in C#. | ||
TODO. | ||
**/ | ||
class CSFunction { | ||
} | ||
|
||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cscompiler.ast; | ||
|
||
#if (macro || cs_runtime) | ||
|
||
import haxe.macro.Type; | ||
|
||
/** | ||
Represents a C# statement. | ||
**/ | ||
class CSStatement { | ||
public var def(default, null): CSStatementDef; | ||
public var haxeExpr(default, null): Null<TypedExpr>; | ||
|
||
public function new(def: CSStatementDef, haxeExpr: Null<TypedExpr> = null) { | ||
this.def = def; | ||
this.haxeExpr = haxeExpr; | ||
} | ||
} | ||
|
||
enum CSStatementDef { | ||
CSExprStatement(expression: CSExpr); | ||
|
||
CSBlock(statements: Array<CSStatement>); | ||
|
||
/** | ||
TODO: else if | ||
**/ | ||
CSIf(condition: CSExpr, ifContent: Array<CSStatement>, elseContent: Null<Array<CSStatement>>); | ||
|
||
CSWhile(condition: CSExpr, content: Array<CSStatement>, normalWhile: Bool); | ||
|
||
/** | ||
A variable declaration `var varData` or `var varData = expr`. | ||
**/ | ||
CSVar(varData: CSVar, expr: Null<CSExpr>); | ||
} | ||
|
||
#end |
Oops, something went wrong.