From a0add98b30c8e489c36703c7c376fc8c58d7c69f Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sun, 2 Oct 2016 02:33:41 +0300 Subject: [PATCH] ocl: eliminate build warning Templates are replaced by macro --- .../core/src/opencl/runtime/generator/common.py | 40 ++++++++++++---------- .../generator/template/opencl_clamdblas.hpp.in | 2 +- .../generator/template/opencl_clamdfft.hpp.in | 2 +- .../runtime/generator/template/opencl_core.hpp.in | 2 +- .../generator/template/opencl_core_wrappers.hpp.in | 2 +- .../runtime/generator/template/opencl_gl.hpp.in | 2 +- .../generator/template/opencl_gl_wrappers.hpp.in | 2 +- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/modules/core/src/opencl/runtime/generator/common.py b/modules/core/src/opencl/runtime/generator/common.py index 5f81e8e..d9064fa 100644 --- a/modules/core/src/opencl/runtime/generator/common.py +++ b/modules/core/src/opencl/runtime/generator/common.py @@ -136,16 +136,30 @@ def generateFilterNames(fns): print '%s%s' % ('' if fn.has_key('enabled') else '//', fn['name']) print '#total %d' % len(fns) +callback_check = re.compile(r'([^\(]*\(.*)(\* *)(\).*\(.*\))') + +def getTypeWithParam(t, p): + if callback_check.match(t): + return callback_check.sub(r'\1 *' + p + r'\3', t) + return t + ' ' + p + @outputToString def generateStructDefinitions(fns, lprefix='opencl_fn', enumprefix='OPENCL_FN'): print '// generated by %s' % os.path.basename(sys.argv[0]) first = True for fn in fns: commentStr = '' if fn.has_key('enabled') else '//' - print commentStr + ('%s%s (%s *%s)(%s) =\n%s %s%d<%s_%s, %s%s>::switch_fn;' % \ + decl_args = [] + for (i, t) in enumerate(fn['params']): + decl_args.append(getTypeWithParam(t, 'p%d' % (i+1))) + decl_args_str = '(' + (', '.join(decl_args)) + ')' + print '%s%s%d(%s_%s, %s, %s)' % \ + (commentStr, lprefix, len(fn['params']), enumprefix, fn['name'], \ + ' '.join(fn['ret']), decl_args_str) + print commentStr + ('%s%s (%s *%s)(%s) =\n%s %s_%s_switch_fn;' % \ ((' '.join(fn['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''), ' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \ - commentStr, lprefix, len(fn['params']), enumprefix, fn['name'], ' '.join(fn['ret']), ('' if len(fn['params']) == 0 else ', ' + ', '.join(fn['params'])))) + commentStr, enumprefix, fn['name'])) print commentStr + ('static const struct DynamicFnEntry %s_definition = { "%s", (void**)&%s};' % (fn['name'], fn['name'], fn['name'])) print first = False @@ -200,22 +214,12 @@ def generateFnDeclaration(fns): def generateTemplates(sz, lprefix, switch_name, calling_convention=''): print '// generated by %s' % os.path.basename(sys.argv[0]) for sz in range(sz): - template_params = ['int ID', 'typename _R'] - types = [] - types_with_params = [] - params = [] - for i in range(1, sz + 1): - template_params.append('typename _T%d' % i) - types.append('_T%d' % i) - types_with_params.append('_T%d p%d' % (i, i)) - params.append('p%d' % i) - print 'template <%s>' % ', '.join(template_params) - print 'struct %s%d' % (lprefix, sz) - print '{' - print ' typedef _R (%s *FN)(%s);' % (calling_convention, ', '.join(types)) - print ' static _R %s switch_fn(%s)' % (calling_convention, ', '.join(types_with_params)) - print ' { return ((FN)%s(ID))(%s); }' % (switch_name, ', '.join(params)) - print '};' + template_params = ['ID', '_R', 'decl_args'] + params = ['p%d' % (i + 1) for i in range(0, sz)] + print '#define %s%d(%s) \\' % (lprefix, sz, ', '.join(template_params)) + print ' typedef _R (%s *ID##FN)decl_args; \\' % (calling_convention) + print ' static _R %s ID##_switch_fn decl_args \\' % (calling_convention) + print ' { return ((ID##FN)%s(ID))(%s); } \\' % (switch_name, ', '.join(params)) print '' @outputToString diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_clamdblas.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_clamdblas.hpp.in index 251c085..5b48f51 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_clamdblas.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_clamdblas.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP #error "Invalid usage" #endif diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_clamdfft.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_clamdfft.hpp.in index 8633580..4e8a563 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_clamdfft.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_clamdfft.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP #error "Invalid usage" #endif diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in index b6c8f05..db9eb80 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP #error "Invalid usage" #endif diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_core_wrappers.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_core_wrappers.hpp.in index 847e67f..1c2cb68 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_core_wrappers.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_core_wrappers.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP #error "Invalid usage" #endif diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in index 13a33c7..d9de9f6 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP #error "Invalid usage" #endif diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in index fc03179..c5b7554 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP #error "Invalid usage" #endif -- 2.7.4