Skip to content

Commit

Permalink
Improved interface method comment alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchiecarroll committed Sep 29, 2024
1 parent 0f7b523 commit a3fd6a2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 54 deletions.
6 changes: 3 additions & 3 deletions src/Tests/Behavioral/SortArrayType/SortArrayType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ private static nint dynamicFn1() {
// NodeR is an interface
[GoType("interface")]
public partial interface NodeR {
public nint Pos(); // Pos is a method
public nint End12(); // End12 is a method
public @string Name(nint offset); // Sub-name
public nint Pos(); // Pos is a method
public nint End12(); // End12 is a method
public @string Name(nint offset); // Sub-name
}

// Person is a type representing a person
Expand Down
6 changes: 3 additions & 3 deletions src/Tests/Behavioral/SortArrayType/SortArrayType.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func dynamicFn1() int {

// NodeR is an interface
type NodeR interface {
Pos() int // Pos is a method
End12() int // End12 is a method
Name(offset int) string // Sub-name
Pos() int // Pos is a method
End12() int // End12 is a method
Name(offset int) string // Sub-name
}

// Person is a type representing a person
Expand Down
48 changes: 0 additions & 48 deletions src/go2cs2/visitFuncDecl.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,51 +249,3 @@ func generateResultSignature(signature *types.Signature) string {

return result.String()
}

func getSourceParameterSignatureLen(signature *types.Signature) int {
parameters := signature.Params()

if parameters == nil {
return 0
}

if parameters.Len() == 1 {
return len(getTypeName(parameters.At(0).Type()))
}

result := 0

for i := 0; i < parameters.Len(); i++ {
if i > 0 {
result += 2
}

result += len(getTypeName(parameters.At(i).Type()))
}

return result
}

func getSourceResultSignatureLen(signature *types.Signature) int {
results := signature.Results()

if results == nil {
return 0
}

if results.Len() == 1 {
return len(getTypeName(results.At(0).Type()))
}

result := 2

for i := 0; i < results.Len(); i++ {
if i > 0 {
result += 2
}

result += len(getTypeName(results.At(i).Type()))
}

return result
}
50 changes: 50 additions & 0 deletions src/go2cs2/visitInterfaceType.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,53 @@ func (v *Visitor) visitInterfaceType(interfaceType *ast.InterfaceType, name stri
v.indentLevel--
v.writeOutputLn("}")
}

func getSourceParameterSignatureLen(signature *types.Signature) int {
parameters := signature.Params()

if parameters == nil {
return 0
}

result := 0

for i := 0; i < parameters.Len(); i++ {
param := parameters.At(i)

if i > 0 {
result += 2
}

result += len(getTypeName(param.Type()))

if param.Name() != "" {
result += 1 + len(param.Name())
}
}

return result
}

func getSourceResultSignatureLen(signature *types.Signature) int {
results := signature.Results()

if results == nil {
return 0
}

if results.Len() == 1 {
return len(getTypeName(results.At(0).Type()))
}

result := 2

for i := 0; i < results.Len(); i++ {
if i > 0 {
result += 2
}

result += len(getTypeName(results.At(i).Type()))
}

return result
}

0 comments on commit a3fd6a2

Please sign in to comment.