Skip to content

Commit

Permalink
fix for references to unwrap types template arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
hrissan committed Jun 5, 2024
1 parent b56954d commit dc707b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
22 changes: 22 additions & 0 deletions internal/tlcodegen/type_rw_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,28 @@ outer:
return result
}

func (trw *TypeRWWrapper) replaceUnwrapHalfResolvedName(topHalfResolved HalfResolvedArgument, name string) string {
if name == "" {
return ""
}
for i, arg := range trw.origTL[0].TemplateArguments {
if arg.FieldName == name {
return topHalfResolved.Args[i].Name
}
}
return ""
}

// same code as in func (w *TypeRWWrapper) transformNatArgsToChild, replaceUnwrapArgs
func (trw *TypeRWWrapper) replaceUnwrapHalfResolved(topHalfResolved HalfResolvedArgument, halfResolved HalfResolvedArgument) HalfResolvedArgument {
var result HalfResolvedArgument
result.Name = trw.replaceUnwrapHalfResolvedName(topHalfResolved, halfResolved.Name)
for _, arg := range halfResolved.Args {
result.Args = append(result.Args, trw.replaceUnwrapHalfResolved(topHalfResolved, arg))
}
return result
}

func (trw *TypeRWStruct) typeResettingCode(bytesVersion bool, directImports *DirectImports, ins *InternalNamespace, val string, ref bool) string {
if trw.isUnwrapType() {
return trw.Fields[0].t.TypeResettingCode(bytesVersion, directImports, ins, val, ref)
Expand Down
7 changes: 4 additions & 3 deletions internal/tlcodegen/type_rw_struct_cpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ func (trw *TypeRWStruct) CPPFillRecursiveChildren(visitedNodes map[*TypeRWWrappe
}

func (trw *TypeRWStruct) cppTypeStringInNamespace(bytesVersion bool, hppInc *DirectIncludesCPP) string {
if trw.isUnwrapType() { // TODO - when replacing typedefs, we must make name resolution
if trw.isUnwrapType() {
return trw.Fields[0].t.CPPTypeStringInNamespace(bytesVersion, hppInc)
}
_, _, args := trw.wr.cppTypeStringInNamespace(bytesVersion, hppInc, false, HalfResolvedArgument{})
return trw.wr.cppNamespaceQualifier() + trw.wr.cppLocalName + args
}

func (trw *TypeRWStruct) cppTypeStringInNamespaceHalfResolved(bytesVersion bool, hppInc *DirectIncludesCPP, halfResolved HalfResolvedArgument) string {
if trw.isUnwrapType() { // TODO - when replacing typedefs, we must make name resolution
return trw.Fields[0].t.CPPTypeStringInNamespaceHalfResolved(bytesVersion, hppInc, halfResolved) // trw.Fields[0].resolvedType
if trw.isUnwrapType() {
halfResolvedUnwrapped := trw.wr.replaceUnwrapHalfResolved(halfResolved, trw.Fields[0].halfResolved)
return trw.Fields[0].t.CPPTypeStringInNamespaceHalfResolved(bytesVersion, hppInc, halfResolvedUnwrapped)
}
_, _, args := trw.wr.cppTypeStringInNamespace(bytesVersion, hppInc, true, halfResolved)
return trw.wr.cppNamespaceQualifier() + trw.wr.cppLocalName + args
Expand Down

0 comments on commit dc707b1

Please sign in to comment.