Skip to content

Commit

Permalink
Format func ptr sigs
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Oct 19, 2017
1 parent e63d02e commit 6ae40d6
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,25 @@ public void Write(TypeSig type, IList<CorType> typeGenArgs = null, IList<CorType
break;

case ElementType.FnPtr:
OutputWrite("fnptr", TypeColor.Keyword);
var sig = ((FnPtrSig)type).MethodSig;
Write(sig.RetType, typeGenArgs, methGenArgs);
WriteSpace();
OutputWrite("(", TypeColor.Punctuation);
for (int i = 0; i < sig.Params.Count; i++) {
if (i > 0)
WriteCommaSpace();
Write(sig.Params[i], typeGenArgs, methGenArgs);
}
if (sig.ParamsAfterSentinel != null) {
if (sig.Params.Count > 0)
WriteCommaSpace();
OutputWrite("...", TypeColor.Punctuation);
for (int i = 0; i < sig.ParamsAfterSentinel.Count; i++) {
WriteCommaSpace();
Write(sig.ParamsAfterSentinel[i], typeGenArgs, methGenArgs);
}
}
OutputWrite(")", TypeColor.Punctuation);
break;

case ElementType.CModReqd:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct CSharpTypeFormatter {
const string GENERICS_CLOSE_PAREN = ">";
const string TUPLE_OPEN_PAREN = "(";
const string TUPLE_CLOSE_PAREN = ")";
const string METHOD_OPEN_PAREN = "(";
const string METHOD_CLOSE_PAREN = ")";
const string HEX_PREFIX = "0x";
const string COMMENT_BEGIN = "/*";
const string COMMENT_END = "*/";
Expand Down Expand Up @@ -256,8 +258,27 @@ public void Format(DmdType type, DbgDotNetValue value) {
break;

case DmdTypeSignatureKind.FunctionPointer:
//TODO:
OutputWrite("fnptr", BoxedTextColor.Keyword);
var sig = type.GetFunctionPointerMethodSignature();
Format(sig.ReturnType, null);
WriteSpace();
OutputWrite(METHOD_OPEN_PAREN, BoxedTextColor.Punctuation);
var types = sig.GetParameterTypes();
for (int i = 0; i < types.Count; i++) {
if (i > 0)
WriteCommaSpace();
Format(types[i], null);
}
types = sig.GetVarArgsParameterTypes();
if (types.Count > 0) {
if (sig.GetParameterTypes().Count > 0)
WriteCommaSpace();
OutputWrite("...", BoxedTextColor.Punctuation);
for (int i = 0; i < types.Count; i++) {
WriteCommaSpace();
Format(types[i], null);
}
}
OutputWrite(METHOD_CLOSE_PAREN, BoxedTextColor.Punctuation);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct VisualBasicTypeFormatter {
const string GENERICS_OF_KEYWORD = "Of";
const string TUPLE_OPEN_PAREN = "(";
const string TUPLE_CLOSE_PAREN = ")";
const string METHOD_OPEN_PAREN = "(";
const string METHOD_CLOSE_PAREN = ")";
const string HEX_PREFIX = "&H";
const string COMMENT_BEGIN = "/*";
const string COMMENT_END = "*/";
Expand Down Expand Up @@ -269,8 +271,27 @@ public void Format(DmdType type, DbgDotNetValue value) {
break;

case DmdTypeSignatureKind.FunctionPointer:
//TODO:
OutputWrite("fnptr", BoxedTextColor.Keyword);
var sig = type.GetFunctionPointerMethodSignature();
Format(sig.ReturnType, null);
WriteSpace();
OutputWrite(METHOD_OPEN_PAREN, BoxedTextColor.Punctuation);
var types = sig.GetParameterTypes();
for (int i = 0; i < types.Count; i++) {
if (i > 0)
WriteCommaSpace();
Format(types[i], null);
}
types = sig.GetVarArgsParameterTypes();
if (types.Count > 0) {
if (sig.GetParameterTypes().Count > 0)
WriteCommaSpace();
OutputWrite("...", BoxedTextColor.Punctuation);
for (int i = 0; i < types.Count; i++) {
WriteCommaSpace();
Format(types[i], null);
}
}
OutputWrite(METHOD_CLOSE_PAREN, BoxedTextColor.Punctuation);
break;

default:
Expand Down
20 changes: 19 additions & 1 deletion dnSpy/dnSpy.Decompiler/CSharp/CSharpFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,25 @@ void Write(TypeSig type, IList<TypeSig> typeGenArgs, IList<TypeSig> methGenArgs)
break;

case ElementType.FnPtr:
OutputWrite("fnptr", BoxedTextColor.Keyword);
var sig = ((FnPtrSig)type).MethodSig;
Write(sig.RetType, typeGenArgs, methGenArgs);
WriteSpace();
OutputWrite(MethodParenOpen, BoxedTextColor.Punctuation);
for (int i = 0; i < sig.Params.Count; i++) {
if (i > 0)
WriteCommaSpace();
Write(sig.Params[i], typeGenArgs, methGenArgs);
}
if (sig.ParamsAfterSentinel != null) {
if (sig.Params.Count > 0)
WriteCommaSpace();
OutputWrite("...", BoxedTextColor.Punctuation);
for (int i = 0; i < sig.ParamsAfterSentinel.Count; i++) {
WriteCommaSpace();
Write(sig.ParamsAfterSentinel[i], typeGenArgs, methGenArgs);
}
}
OutputWrite(MethodParenClose, BoxedTextColor.Punctuation);
break;

case ElementType.CModReqd:
Expand Down
20 changes: 19 additions & 1 deletion dnSpy/dnSpy.Decompiler/VisualBasic/VisualBasicFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,25 @@ void Write(TypeSig type, IList<TypeSig> typeGenArgs, IList<TypeSig> methGenArgs)
break;

case ElementType.FnPtr:
OutputWrite("fnptr", BoxedTextColor.Keyword);
var sig = ((FnPtrSig)type).MethodSig;
Write(sig.RetType, typeGenArgs, methGenArgs);
WriteSpace();
OutputWrite(MethodParenOpen, BoxedTextColor.Punctuation);
for (int i = 0; i < sig.Params.Count; i++) {
if (i > 0)
WriteCommaSpace();
Write(sig.Params[i], typeGenArgs, methGenArgs);
}
if (sig.ParamsAfterSentinel != null) {
if (sig.Params.Count > 0)
WriteCommaSpace();
OutputWrite("...", BoxedTextColor.Punctuation);
for (int i = 0; i < sig.ParamsAfterSentinel.Count; i++) {
WriteCommaSpace();
Write(sig.ParamsAfterSentinel[i], typeGenArgs, methGenArgs);
}
}
OutputWrite(MethodParenClose, BoxedTextColor.Punctuation);
break;

case ElementType.CModReqd:
Expand Down

0 comments on commit 6ae40d6

Please sign in to comment.