Skip to content

Commit e6ac5e2

Browse files
committed
Tolerate missing abstract methods
1 parent 37ededc commit e6ac5e2

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Source/buildbindingccpp.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ func buildDynamicCPPMethodDeclaration(method ComponentDefinitionMethod, NameSpac
609609
}
610610

611611
func writeDynamicCPPMethod(component ComponentDefinition, method ComponentDefinitionMethod, w LanguageWriter, ClassIdentifier string, ClassName string,
612-
implementationLines []string, isGlobal bool, includeComments bool, checkErrorSafely bool, useCPPTypes bool, ExplicitLinking bool) error {
612+
implementationLines []string, isGlobal bool, includeComments bool, checkErrorSafely bool, useCPPTypes bool, ExplicitLinking bool, isAbstract bool) error {
613613
NameSpace := component.NameSpace
614614

615615
CMethodName := ""
@@ -868,6 +868,10 @@ func writeDynamicCPPMethod(component ComponentDefinition, method ComponentDefini
868868

869869
w.Writeln(" {")
870870
w.Writelns(" ", definitionCodeLines)
871+
if isAbstract {
872+
w.Writeln(" if (!%s)", CMethodName)
873+
w.Writeln(" throw E%sException(%s_ERROR_NOTIMPLEMENTED, \"Method '%s' not found\");", NameSpace, strings.ToUpper(NameSpace), method.MethodName)
874+
}
871875
if requiresInitCall {
872876
w.Writeln(" %s%s(%s)%s;", checkErrorCodeBegin, CMethodName, initCallParameters, checkErrorCodeEnd)
873877
}
@@ -903,8 +907,12 @@ func writeLoadingOfClassFunctionTable(component ComponentDefinition, stubfile La
903907

904908
for k := 0; k < len(class.Methods); k++ {
905909
method := class.Methods[k]
910+
readMethod := "readMethodInto"
911+
if (class.IsAbstract()) {
912+
readMethod = "readAbstractMethodInto"
913+
}
906914
CMethodName := strings.ToLower(fmt.Sprintf("%s_%s_%s", NameSpace, class.ClassName, method.MethodName));
907-
stubfile.Writeln(" %s::readMethodInto(pLookupFunction, \"%s\", (void**)&(%s->m_%s_%s));", WrapperName, CMethodName, sTableName, class.ClassName, method.MethodName);
915+
stubfile.Writeln(" %s::%s(pLookupFunction, \"%s\", (void**)&(%s->m_%s_%s));", WrapperName, readMethod, CMethodName, sTableName, class.ClassName, method.MethodName);
908916
}
909917
}
910918

@@ -1413,6 +1421,13 @@ func buildCppHeader(component ComponentDefinition, w LanguageWriter, NameSpace s
14131421
w.Writeln(" }")
14141422
w.Writeln("")
14151423

1424+
w.Writeln(" static void readAbstractMethodInto(%sSymbolLookupType pLookupMethod, std::string sFunctionName, void** pfnTarget) {", NameSpace )
1425+
w.Writeln(" %sResult eLookupError = (*pLookupMethod)(sFunctionName.c_str(), pfnTarget);", NameSpace);
1426+
w.Writeln(" if (eLookupError != %s_SUCCESS)", strings.ToUpper(NameSpace))
1427+
w.Writeln(" *pfnTarget = 0;")
1428+
w.Writeln(" }")
1429+
w.Writeln("")
1430+
14161431

14171432
for i := 0; i < len(component.Classes); i++ {
14181433
class := component.Classes[i]
@@ -1510,7 +1525,7 @@ func buildCppHeader(component ComponentDefinition, w LanguageWriter, NameSpace s
15101525
checkErrorSafely = true
15111526
}
15121527

1513-
err = writeDynamicCPPMethod(component, method, w, ClassIdentifier, "Wrapper", implementationLines, true, true, checkErrorSafely, useCPPTypes, ExplicitLinking)
1528+
err = writeDynamicCPPMethod(component, method, w, ClassIdentifier, "Wrapper", implementationLines, true, true, checkErrorSafely, useCPPTypes, ExplicitLinking, false)
15141529
if err != nil {
15151530
return err
15161531
}
@@ -1599,7 +1614,7 @@ func buildCppHeader(component ComponentDefinition, w LanguageWriter, NameSpace s
15991614
checkErrorSafely = true
16001615
}
16011616

1602-
err := writeDynamicCPPMethod(component, method, w, ClassIdentifier, class.ClassName, make([]string,0), false, true, checkErrorSafely, useCPPTypes, ExplicitLinking)
1617+
err := writeDynamicCPPMethod(component, method, w, ClassIdentifier, class.ClassName, make([]string,0), false, true, checkErrorSafely, useCPPTypes, ExplicitLinking, class.IsAbstract())
16031618
if err != nil {
16041619
return err
16051620
}

0 commit comments

Comments
 (0)