Skip to content

Commit

Permalink
Do not use specific values for object, dynamic or string. Instead use…
Browse files Browse the repository at this point in the history
… CSInst or CSValue accordingly
  • Loading branch information
jeremyfa committed Mar 2, 2024
1 parent 33c7b36 commit 8a573b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
17 changes: 0 additions & 17 deletions src/cscompiler/ast/CSType.hx
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ enum CSType {
**/
CSFunction(args: Array<CSArg>, ret: CSType);

/**
C# `object` type
**/
CSObject;

/**
C# `dynamic` type. See https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/reference-types#the-dynamic-type to see how it
is different from `object` type. (the gist of it: `dynamic` is similar to
Haxe's `Dynamic` type while `object` is more like Haxe's `Any` type).
**/
CSDynamic;

/**
A C# string type
**/
CSString;

/**
A C# value type (primitives like `int`, `bool`... or `struct` types) type. Optionally nullable (`int?` etc...)
**/
Expand Down
30 changes: 18 additions & 12 deletions src/cscompiler/components/CSCompiler_Type.hx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,22 @@ class CSCompiler_Type extends CSCompiler_Base {
);
}
case TInst(clsRef, params): {
CSInst(
compileClassType(clsRef.get()),
compileTypeParams(params)
);
final cls = clsRef.get();
if (cls.hasMeta(':struct')) {
// When using @:struct meta, we are
// dealing with a C# `struct` value type
CSValue(
compileClassType(cls),
compileTypeParams(params),
false
);
}
else {
CSInst(
compileClassType(cls),
compileTypeParams(params)
);
}
}
case TType(_, _): {
compile(Context.follow(type), pos);
Expand All @@ -61,11 +73,11 @@ class CSCompiler_Type extends CSCompiler_Base {
}
case TAnonymous(anonRef): {
// For now, we simply use `object` type. Might change later
CSObject;
CSInst('object', []);
}
case TDynamic(maybeType): {
// TODO, returning `dynamic` type for now here
CSDynamic;
CSInst('dynamic', []);
}
case TLazy(callback): {
compile(callback(), pos);
Expand Down Expand Up @@ -132,12 +144,6 @@ class CSCompiler_Type extends CSCompiler_Base {
type;
case CSFunction(args, ret):
type;
case CSObject:
type;
case CSDynamic:
type;
case CSString:
type;
case CSValue(typePath, params, _):
// Value types need to be explicitly nullable,
// whereas other types are already implicitly
Expand Down

0 comments on commit 8a573b8

Please sign in to comment.