Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 2688cb8

Browse files
Refactor vtable handling
1 parent 474b420 commit 2688cb8

File tree

5 files changed

+169
-422
lines changed

5 files changed

+169
-422
lines changed

Dynamo/Dynamo.CSLang/CSClass.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Dynamo.CSLang {
1010
public class CSClass : ICodeElementSet, ICSTopLevelDeclaration {
1111
public CSClass (CSVisibility vis, CSIdentifier name, IEnumerable<CSMethod> methods = null,
12-
bool isStatic = false, bool isSealed = false)
12+
bool isStatic = false, bool isSealed = false, bool isUnsafe = false)
1313
{
1414
Visibility = vis;
1515
IsStatic = isStatic;
@@ -32,8 +32,9 @@ public CSClass (CSVisibility vis, CSIdentifier name, IEnumerable<CSMethod> metho
3232
}
3333

3434
public CSClass (CSVisibility vis, string name,
35-
IEnumerable<CSMethod> members = null, bool isStatic = false, bool isSealed = false)
36-
: this (vis, new CSIdentifier (name), members, isStatic, isSealed)
35+
IEnumerable<CSMethod> members = null, bool isStatic = false, bool isSealed = false,
36+
bool isUnsafe = false)
37+
: this (vis, new CSIdentifier (name), members, isStatic, isSealed, isUnsafe: false)
3738
{
3839
}
3940

@@ -42,6 +43,7 @@ public CSClass (CSVisibility vis, string name,
4243
public CSVisibility Visibility { get; private set; }
4344
public bool IsStatic { get; private set; }
4445
public bool IsSealed { get; private set; }
46+
public bool IsUnsafe { get; private set; }
4547
public CSIdentifier Name { get; private set; }
4648
public CSInheritance Inheritance { get; private set; }
4749
public List<CSDelegateTypeDecl> Delegates { get; private set; }
@@ -114,6 +116,8 @@ public IEnumerable<ICodeElement> Elements {
114116
decl.Add (new SimpleElement ("static ", true));
115117
if (IsSealed)
116118
decl.Add (new SimpleElement ("sealed ", true));
119+
if (IsUnsafe)
120+
decl.Add (new SimpleElement ("unsafe ", true));
117121
decl.Add (new CSIdentifier (EntityLabel + " "));
118122
decl.Add (Name);
119123
decl.Add (GenericParams);
@@ -169,14 +173,15 @@ public CSClasses And (CSClass use)
169173

170174
public class CSStruct : CSClass {
171175
public CSStruct (CSVisibility vis, CSIdentifier name, IEnumerable<CSMethod> methods = null,
172-
bool isStatic = false, bool isSealed = false)
173-
: base (vis, name, methods, isStatic, isSealed)
176+
bool isStatic = false, bool isSealed = false, bool isUnsafe = false)
177+
: base (vis, name, methods, isStatic, isSealed, isUnsafe)
174178
{
175179
}
176180

177181
public CSStruct (CSVisibility vis, string name,
178-
IEnumerable<CSMethod> members = null, bool isStatic = false, bool isSealed = false)
179-
: this (vis, new CSIdentifier (name), members, isStatic, isSealed)
182+
IEnumerable<CSMethod> members = null, bool isStatic = false, bool isSealed = false,
183+
bool isUnsafe = false)
184+
: this (vis, new CSIdentifier (name), members, isStatic, isSealed, isUnsafe)
180185
{
181186
}
182187

Dynamo/Dynamo.CSLang/CSMethod.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public CSMethod (CSVisibility vis, CSMethodKind kind, CSType type, CSIdentifier
5252

5353
lc.And (name).And (GenericParameters).And (new SimpleElement ("(")).And (parms).And (new SimpleElement (")")).And (GenericConstraints);
5454
if (body == null) {
55-
if (!(kind == CSMethodKind.StaticExtern || kind == CSMethodKind.Interface))
55+
if (!(kind == CSMethodKind.StaticExtern || kind == CSMethodKind.StaticExternUnsafe || kind == CSMethodKind.Interface))
5656
throw new ArgumentException ("Method body is only optional when method kind kind is either StaticExtern or Interface",
5757
nameof (body));
5858
lc.Add (new SimpleElement (";"));
@@ -153,6 +153,8 @@ public static string MethodKindToString (CSMethodKind kind)
153153
return "unsafe";
154154
case CSMethodKind.StaticUnsafe:
155155
return "static unsafe";
156+
case CSMethodKind.StaticExternUnsafe:
157+
return "static extern unsafe";
156158
default:
157159
throw new ArgumentOutOfRangeException (nameof (kind));
158160
}

Dynamo/Dynamo.CSLang/Enums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public enum CSMethodKind {
2323
Interface,
2424
Unsafe,
2525
StaticUnsafe,
26+
StaticExternUnsafe,
2627
}
2728

2829
public enum CSBinaryOperator {

0 commit comments

Comments
 (0)