diff options
author | Jim Carroll <thecarrolls@jiminger.com> | 2012-10-21 17:30:10 -0400 |
---|---|---|
committer | Jim Carroll <thecarrolls@jiminger.com> | 2012-10-21 20:22:17 -0400 |
commit | 9829ef0b5aa1915cbff4ba7171bbbda5820a9988 (patch) | |
tree | ca49697d5878253c87e9d1ee8714627268706147 /tools/codegenerator/Helper.groovy | |
parent | 5d37556ad756afd2f4138cc414fac7a151b0887b (diff) |
[fix] fix the Helper for the codegenerator so that out conversions for api classes don't require the actual xml node. This is required to support returning api types from other modules.
Diffstat (limited to 'tools/codegenerator/Helper.groovy')
-rw-r--r-- | tools/codegenerator/Helper.groovy | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/tools/codegenerator/Helper.groovy b/tools/codegenerator/Helper.groovy index 7050d96ce4..ff619355ef 100644 --- a/tools/codegenerator/Helper.groovy +++ b/tools/codegenerator/Helper.groovy @@ -183,11 +183,15 @@ public class Helper // if (convertTemplate == null) convertTemplate = outTypemap[apiLType] // is the returns a pointer to a known class - Node classNode = null + String className = null if (convertTemplate == null && apiType.startsWith('p.')) { - classNode = findClassNodeByName(parents(method)[0], SwigTypeParser.getRootType(apiType),method) - if (classNode) convertTemplate = defaultOutTypeConversion + Node classNode = findClassNodeByName(parents(method)[0], SwigTypeParser.getRootType(apiType),method) + if (classNode) + { + className = findFullClassName(classNode) + convertTemplate = defaultOutTypeConversion + } } if (convertTemplate == null) @@ -198,10 +202,20 @@ public class Helper if (!convertTemplate) { + String knownApiType = isKnownApiType(apiType,method) + if (knownApiType) + { + convertTemplate = defaultOutTypeConversion + className = knownApiType + } + } + + if (!convertTemplate) + { if (recurse) return getOutConversion(SwigTypeParser.SwigType_ltype(apiType),apiName,method,overrideBindings,false) - else - throw new RuntimeException("WARNING: Cannot convert the return value of swig type ${apiType} for the call ${Helper.findFullClassName(method) + '::' + Helper.callingName(method)}") + else if (!isKnownApiType(apiType,method)) + throw new RuntimeException("WARNING: Cannot convert the return value of swig type ${apiType} for the call ${Helper.findFullClassName(method) + '::' + Helper.callingName(method)}") } boolean seqSetHere = false @@ -217,7 +231,7 @@ public class Helper 'method' : method, 'helper' : Helper.class, 'swigTypeParser' : SwigTypeParser.class, 'sequence' : seq ] - if (classNode) bindings['classnode'] = classNode + if (className) bindings['classname'] = className if (overrideBindings) bindings.putAll(overrideBindings) @@ -652,7 +666,7 @@ public class Helper */ public static boolean isKnownBaseType(String type, Node searchFrom) { - return hasFeatureSetting(type,searchFrom,'feature_knownbasetypes',{ it.split(',').find({ it == type }) != null }) + return hasFeatureSetting(type,searchFrom,'feature_knownbasetypes',{ it.split(',').find({ it.trim() == type }) != null }) } /** @@ -660,19 +674,38 @@ public class Helper * looking for a %feature("knownapitypes") declaration that the given 'type' is * known for 'searchFrom' Node. */ - public static boolean isKnownApiType(String type, Node searchFrom) + public static String isKnownApiType(String type, Node searchFrom) { String rootType = SwigTypeParser.getRootType(type) - return hasFeatureSetting(type,searchFrom,'feature_knownapitypes',{ it.split(',').find({ it == rootType }) != null }) + String namespace = findNamespace(searchFrom,'::',false) + return hasFeatureSetting(type,searchFrom,'feature_knownapitypes',{ it.split(',').find( + { + if (it.trim() == rootType) + return true + // we assume the 'type' is defined within namespace and + // so we can walk up the namespace appending the type until + // we find a match. + while (namespace != '') + { +// System.out.println('checking ' + (namespace + '::' + rootType)) + if ((namespace + '::' + rootType) == it.trim()) + return true + // truncate the last namespace + int chop = namespace.lastIndexOf('::') + namespace = (chop > 0) ? namespace.substring(0,chop) : '' + } + return false + }) != null }) } - private static boolean hasFeatureSetting(String type, Node searchFrom, String feature, Closure test) + private static String hasFeatureSetting(String type, Node searchFrom, String feature, Closure test) { if (!searchFrom) - return false + return null - if (searchFrom.attribute(feature) && test.call(searchFrom.attribute(feature))) - return true + Object attr = searchFrom.attribute(feature) + if (attr && test.call(attr)) + return attr.toString() return hasFeatureSetting(type,searchFrom.parent(),feature,test) } |