Exemplo n.º 1
0
def apiFuncDeclareCode(apis, args):
  code = ''

  for api in apis:

    d = [] # defines
    e = [] # enums
    t = [] # function pointer typedefs
    m = [] # mangled names for REGAL_NAMESPACE support
    f = [] # gl names
    p = [] # plugin names for REGAL_PLUGIN_MODE support

    for enum in api.enums:
      if enum.name == 'defines':
        for enumerant in enum.enumerants:

          # Ignore enums that match category, a workaround
          # for EGL_VERSION_1_3 and EGL_VERSION_1_4

          if enumerant.name==enumerant.category:
            continue

          value = toLong(enumerant.value)
          if value==None:
            value = enumerant.value

          # Don't bother with decimal for 0-10
          if isinstance(value, long) and value>=10:
            e.append((enumerant.category, '#define %s %s /* %s */'%(enumerant.name,hexValue(value),value)))
          else:
            e.append((enumerant.category, '#define %s %s'%(enumerant.name,hexValue(value))))

    for function in api.functions:

      name   = function.name
      params = paramsDefaultCode(function.parameters, True)
      rType  = typeCode(function.ret.type)
      category  = getattr(function, 'category', None)
      version   = getattr(function, 'version', None)

      if category:
        category = category.replace('_DEPRECATED', '')
      elif version:
        category = version.replace('.', '_')
        category = 'GL_VERSION_' + category

      t.append((category,funcProtoCode(function, version, 'REGAL_CALL', True)))
      m.append((category,'#define %-35s r%-35s' % (name, name) ))
      f.append((category,'REGAL_DECL %sREGAL_CALL %s(%s);' % (rType, name, params) ))
      p.append((category,'REGAL_DECL %sREGAL_CALL plugin_%s(%s);' % (rType, name, params) ))

    def cmpEnum(a,b):
      if a[0]==b[0]:
        aValue = a[1].split(' ')[2]
        bValue = b[1].split(' ')[2]
        if aValue==bValue:
          return cmp(a[1].split(' ')[1], b[1].split(' ')[1])
        else:
          return cmp(aValue,bValue)
      return cmp(a[0],b[0])

    def enumIfDef(category):
      return '#ifndef REGAL_NO_ENUM_%s'%(upper(category).replace(' ','_'))

    def typedefIfDef(category):
      return '#ifndef REGAL_NO_TYPEDEF_%s'%(upper(category).replace(' ','_'))

    def namespaceIfDef(category):
      return '#ifndef REGAL_NO_NAMESPACE_%s'%(upper(category).replace(' ','_'))

    def pluginIfDef(category):
      return '#ifndef REGAL_NO_PLUGIN_%s'%(upper(category).replace(' ','_'))

    def declarationIfDef(category):
      return '#ifndef REGAL_NO_DECLARATION_%s'%(upper(category).replace(' ','_'))

    categories = set()

    if api.name=='egl':
      categories.add('EGL_VERSION_1_3')
      categories.add('EGL_VERSION_1_4')

    categories.update([ i[0] for i in e ])
    categories.update([ i[0] for i in t ])
    categories.update([ i[0] for i in m ])
    categories.update([ i[0] for i in p ])
    categories.update([ i[0] for i in f ])

    for i in categories:
      if len(i):
        cat = upper(i).replace(' ','_')

        d.append((i,'#if (defined(%s) || defined(REGAL_NO_ENUM) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_ENUM_%s)'%(cat,cat,cat)))
        d.append((i,'#define REGAL_NO_ENUM_%s'%(cat)))
        d.append((i,'#endif'))
        d.append((i,''))

        d.append((i,'#if (defined(%s) || defined(REGAL_NO_TYPEDEF) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_TYPEDEF_%s)'%(cat,cat,cat)))
        d.append((i,'#define REGAL_NO_TYPEDEF_%s'%(cat)))
        d.append((i,'#endif'))
        d.append((i,''))

        d.append((i,'#if (defined(%s) || !defined(REGAL_NAMESPACE) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_NAMESPACE_%s)'%(cat,cat,cat)))
        d.append((i,'#define REGAL_NO_NAMESPACE_%s'%(cat)))
        d.append((i,'#endif'))
        d.append((i,''))

        d.append((i,'#if (defined(%s) || !defined(REGAL_PLUGIN_MODE) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_PLUGIN_%s)'%(cat,cat,cat)))
        d.append((i,'#define REGAL_NO_PLUGIN_%s'%(cat)))
        d.append((i,'#endif'))
        d.append((i,''))

        d.append((i,'#if (defined(%s) || defined(REGAL_NO_DECLARATION) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_DECLARATION_%s)'%(cat,cat,cat)))
        d.append((i,'#define REGAL_NO_DECLARATION_%s'%(cat)))
        d.append((i,'#endif'))
        d.append((i,''))

        d.append((i,'#ifndef %s'%(i)))
        d.append((i,'#define %s 1'%(i)))
        d.append((i,'#endif'))
        d.append((i,''))

    e.sort(cmpEnum)
    e = alignDefineCategory(e)
    e = ifCategory(e,enumIfDef)
    e = spaceCategory(e)

    t.sort()
    t = ifCategory(t,typedefIfDef)
    t = spaceCategory(t)

    m.sort()
    m = ifCategory(m,namespaceIfDef)
    m = spaceCategory(m)

    f.sort()
    f = ifCategory(f,declarationIfDef)
    f = spaceCategory(f)

    p.sort()
    p = ifCategory(p,pluginIfDef)
    p = spaceCategory(p)

    d.extend(e)
    d.extend(t)
    d.extend(m)
    d.extend(f)
    d.extend(p)

    tmp = listToString(unfoldCategory(d,'/**\n ** %s\n **/',lambda x,y: cmp(x[0], y[0])))

    if api.name == 'wgl':
      tmp = wrapIf('REGAL_SYS_WGL_DECLARE_WGL',tmp)
    if api.name in cond:
      tmp = wrapIf(cond[api.name], tmp)

    code += '%s\n'%(tmp)

  return code
Exemplo n.º 2
0
def apiFuncDeclareCode(apis, args):
    code = ''

    for api in apis:

        d = []  # defines
        e = []  # enums
        t = []  # function pointer typedefs
        m = []  # mangled names for REGAL_NAMESPACE support
        f = []  # gl names
        p = []  # plugin names for REGAL_PLUGIN_MODE support

        for enum in api.enums:
            if enum.name == 'defines':
                for enumerant in enum.enumerants:

                    # Ignore enums that match category, a workaround
                    # for EGL_VERSION_1_3 and EGL_VERSION_1_4

                    if enumerant.name == enumerant.category:
                        continue

                    value = toLong(enumerant.value)
                    if value == None:
                        value = enumerant.value

                    # Don't bother with decimal for 0-10
                    if isinstance(value, long) and value >= 10:
                        e.append(
                            (enumerant.category, '#define %s %s /* %s */' %
                             (enumerant.name, hexValue(value), value)))
                    else:
                        e.append((enumerant.category, '#define %s %s' %
                                  (enumerant.name, hexValue(value))))

        for function in api.functions:

            name = function.name
            params = paramsDefaultCode(function.parameters, True)
            rType = typeCode(function.ret.type)
            category = getattr(function, 'category', None)
            version = getattr(function, 'version', None)

            if category:
                category = category.replace('_DEPRECATED', '')
            elif version:
                category = version.replace('.', '_')
                category = 'GL_VERSION_' + category

            t.append(
                (category, funcProtoCode(function, version, 'REGAL_CALL',
                                         True)))
            m.append((category, '#define %-35s r%-35s' % (name, name)))
            f.append(
                (category,
                 'REGAL_DECL %sREGAL_CALL %s(%s);' % (rType, name, params)))
            p.append((category, 'REGAL_DECL %sREGAL_CALL plugin_%s(%s);' %
                      (rType, name, params)))

        def cmpEnum(a, b):
            if a[0] == b[0]:
                aValue = a[1].split(' ')[2]
                bValue = b[1].split(' ')[2]
                if aValue == bValue:
                    return cmp(a[1].split(' ')[1], b[1].split(' ')[1])
                else:
                    return cmp(aValue, bValue)
            return cmp(a[0], b[0])

        def enumIfDef(category):
            return '#ifndef REGAL_NO_ENUM_%s' % (upper(category).replace(
                ' ', '_'))

        def typedefIfDef(category):
            return '#ifndef REGAL_NO_TYPEDEF_%s' % (upper(category).replace(
                ' ', '_'))

        def namespaceIfDef(category):
            return '#ifndef REGAL_NO_NAMESPACE_%s' % (upper(category).replace(
                ' ', '_'))

        def pluginIfDef(category):
            return '#ifndef REGAL_NO_PLUGIN_%s' % (upper(category).replace(
                ' ', '_'))

        def declarationIfDef(category):
            return '#ifndef REGAL_NO_DECLARATION_%s' % (
                upper(category).replace(' ', '_'))

        categories = set()

        if api.name == 'egl':
            categories.add('EGL_VERSION_1_3')
            categories.add('EGL_VERSION_1_4')

        categories.update([i[0] for i in e])
        categories.update([i[0] for i in t])
        categories.update([i[0] for i in m])
        categories.update([i[0] for i in p])
        categories.update([i[0] for i in f])

        for i in categories:
            if len(i):
                cat = upper(i).replace(' ', '_')

                d.append((
                    i,
                    '#if (defined(%s) || defined(REGAL_NO_ENUM) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_ENUM_%s)'
                    % (cat, cat, cat)))
                d.append((i, '#define REGAL_NO_ENUM_%s' % (cat)))
                d.append((i, '#endif'))
                d.append((i, ''))

                d.append((
                    i,
                    '#if (defined(%s) || defined(REGAL_NO_TYPEDEF) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_TYPEDEF_%s)'
                    % (cat, cat, cat)))
                d.append((i, '#define REGAL_NO_TYPEDEF_%s' % (cat)))
                d.append((i, '#endif'))
                d.append((i, ''))

                d.append((
                    i,
                    '#if (defined(%s) || !defined(REGAL_NAMESPACE) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_NAMESPACE_%s)'
                    % (cat, cat, cat)))
                d.append((i, '#define REGAL_NO_NAMESPACE_%s' % (cat)))
                d.append((i, '#endif'))
                d.append((i, ''))

                d.append((
                    i,
                    '#if (defined(%s) || !defined(REGAL_PLUGIN_MODE) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_PLUGIN_%s)'
                    % (cat, cat, cat)))
                d.append((i, '#define REGAL_NO_PLUGIN_%s' % (cat)))
                d.append((i, '#endif'))
                d.append((i, ''))

                d.append((
                    i,
                    '#if (defined(%s) || defined(REGAL_NO_DECLARATION) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_DECLARATION_%s)'
                    % (cat, cat, cat)))
                d.append((i, '#define REGAL_NO_DECLARATION_%s' % (cat)))
                d.append((i, '#endif'))
                d.append((i, ''))

                d.append((i, '#ifndef %s' % (i)))
                d.append((i, '#define %s 1' % (i)))
                d.append((i, '#endif'))
                d.append((i, ''))

        e.sort(cmpEnum)
        e = alignDefineCategory(e)
        e = ifCategory(e, enumIfDef)
        e = spaceCategory(e)

        t.sort()
        t = ifCategory(t, typedefIfDef)
        t = spaceCategory(t)

        m.sort()
        m = ifCategory(m, namespaceIfDef)
        m = spaceCategory(m)

        f.sort()
        f = ifCategory(f, declarationIfDef)
        f = spaceCategory(f)

        p.sort()
        p = ifCategory(p, pluginIfDef)
        p = spaceCategory(p)

        d.extend(e)
        d.extend(t)
        d.extend(m)
        d.extend(f)
        d.extend(p)

        tmp = listToString(
            unfoldCategory(d, '/**\n ** %s\n **/',
                           lambda x, y: cmp(x[0], y[0])))

        if api.name == 'wgl':
            tmp = wrapIf('REGAL_SYS_WGL_DECLARE_WGL', tmp)
        if api.name in cond:
            tmp = wrapIf(cond[api.name], tmp)

        code += '%s\n' % (tmp)

    return code
Exemplo n.º 3
0
def generateTokenSource(apis, args):

  code = []

  code.append('  const char * GLenumToString( GLenum e ) {')
  code.append('    switch( e ) {')

  for i in apis:
    if i.name != 'gl':
      continue
    e = {}
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerants:
        value = toLong(k.value)
        if value != None:
          if not value in e:
            e[value] = set()
          e[value].add(k.name)

    e = sorted([ (i,sorted(list(e[i]))) for i in e.iterkeys() ])
    e = [ i for i in e if i[0] < 0xfffffffff ]
    e = filterTokens(e)

    for i in e:
      value = i[0]
      if len(i[1]):
        name = i[1][0]
      else:
        name = i[2][0]

      if value==0:
        name = 'GL_ZERO'
      if value==1:
        name = 'GL_ONE'

      code.append('      case %s: return "%s";'%(hexValue(value,'0x%08x'),name))

  code.append('      default: break;')
  code.append('    }')
  code.append('  return "unknown_gl_enum";')
  code.append('  }')

  # GLerrorToString

  code.append('')
  code.append('  const char * GLerrorToString( GLenum e ) {')
  code.append('    switch( e ) {')
  for i in apis:
    if i.name != 'gl':
      continue
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerants:
        if getattr(k,'gluErrorString',None):
          code.append('      case %s: return "%s";'%(k.name,k.gluErrorString))
  code.append('      default: break;')
  code.append('    }')
  code.append('  return NULL;')
  code.append('  }')

  # GLX_VERSION

  code.append('')
  code.append('#if REGAL_SYS_GLX')
  code.append('  const char * GLXenumToString(int v) {')
  code.append('    switch( v ) {')

  for i in apis:
    if i.name != 'glx':
      continue
    e = {}
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerants:
        value = toLong(k.value)
        if value != None:
          if not value in e:
            e[value] = set()
          e[value].add(k.name)

    e = sorted([ (i,sorted(list(e[i]))) for i in e.iterkeys() ])
    e = [ i for i in e if i[0] < 0xfffffffff ]
    e = filterTokens(e)

    for i in e:
      value = i[0]
      if len(i[1]):
        name = i[1][0]
      else:
        name = i[2][0]

      code.append('      case %s: return "%s";'%(hexValue(value,'0x%08x'),name))

  code.append('      default: break;')
  code.append('    }')
  code.append('    return "unknown_glx_enum";')
  code.append('  }')
  code.append('#endif // REGAL_SYS_GLX')

  # EGL version

  code.append('')
  code.append('#if REGAL_SYS_EGL')
  code.append('  const char * EGLenumToString(int v) {')
  code.append('    switch( v ) {')

  for i in apis:
    if i.name != 'egl':
      continue
    e = {}
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerants:
        value = toLong(k.value)
        if value != None:
          if not value in e:
            e[value] = set()
          e[value].add(k.name)

    e = sorted([ (i,sorted(list(e[i]))) for i in e.iterkeys() ])
    e = [ i for i in e if i[0] < 0xfffffffff ]
    e = filterTokens(e)

    for i in e:
      value = i[0]
      if len(i[1]):
        name = i[1][0]
      else:
        name = i[2][0]

      if value==0:
        name = 'EGL_FALSE'
      if value==1:
        name = 'EGL_TRUE'

      code.append('      case %s: return "%s";'%(hexValue(value,'0x%08x'),name))

  code.append('      default: break;')
  code.append('    }')
  code.append('    return "unknown_egl_enum";')
  code.append('  }')
  code.append('#endif // REGAL_SYS_EGL')

  substitute = {}
  substitute['LICENSE']       = args.license
  substitute['AUTOGENERATED'] = args.generated
  substitute['COPYRIGHT']     = args.copyright
  substitute['CODE']          = '\n'.join(code)
  outputCode( '%s/RegalToken.cpp' % args.srcdir, tokenSourceTemplate.substitute(substitute))
Exemplo n.º 4
0
def generateTokenSource(apis, args):

  code = []

  code.append('  const char * GLenumToString( GLenum e ) {')
  code.append('    #if REGAL_ENUM_TO_STRING')
  code.append('    switch( e ) {')

  for i in apis:
    if i.name != 'gl':
      continue
    e = {}
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerantsByName:
        value = toLong(k.value)
        if value != None:
          if not value in e:
            e[value] = set()
          e[value].add(k.name)

    e = sorted([ (i,sorted(list(e[i]))) for i in e.iterkeys() ])
    e = [ i for i in e if i[0] < 0xfffffffff ]
    e = filterTokens(e)

    for i in e:
      value = i[0]
      if len(i[1]):
        name = i[1][0]
      else:
        name = i[2][0]

      if value==0:
        name = 'GL_ZERO'
      if value==1:
        name = 'GL_ONE'

      code.append('      case %s: return "%s";'%(hexValue(value,'0x%08x'),name))

  code.append('      default: break;')
  code.append('    }')
  code.append('    #endif // REGAL_ENUM_TO_STRING')
  code.append('    return "unknown_gl_enum";')
  code.append('  }')

  # NV_path_rendering related

  code.extend(groupToStringCodeGen(apis,'pathCoord',   'GLpathCoordToString',   'unknown'))  
  code.extend(groupToStringCodeGen(apis,'pathCommand', 'GLpathCommandToString', 'unknown', 'GLubyte', '0x%02x'))

  # GLerrorToString

  code.append('')
  code.append('  const char * GLerrorToString( GLenum e ) {')
  code.append('    #if REGAL_ENUM_TO_STRING')
  code.append('    switch( e ) {')
  for i in apis:
    if i.name != 'gl':
      continue
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerantsByName:
        if getattr(k,'gluErrorString',None):
          code.append('      case %s: return "%s";'%(k.name,k.gluErrorString))
  code.append('      default: break;')
  code.append('    }')
  code.append('    #endif // REGAL_ENUM_TO_STRING')
  code.append('    return NULL;')
  code.append('  }')

  # GLX_VERSION

  code.append('')
  code.append('#if REGAL_SYS_GLX')
  code.append('  const char * GLXenumToString(int v) {')
  code.append('    #if REGAL_ENUM_TO_STRING')
  code.append('    switch( v ) {')

  for i in apis:
    if i.name != 'glx':
      continue
    e = {}
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerants:
        value = toLong(k.value)
        if value != None:
          if not value in e:
            e[value] = set()
          e[value].add(k.name)

    e = sorted([ (i,sorted(list(e[i]))) for i in e.iterkeys() ])
    e = [ i for i in e if i[0] < 0xfffffffff ]
    e = filterTokens(e)

    for i in e:
      value = i[0]
      if len(i[1]):
        name = i[1][0]
      else:
        name = i[2][0]

      code.append('      case %s: return "%s";'%(hexValue(value,'0x%08x'),name))

  code.append('      default: break;')
  code.append('    }')
  code.append('    #endif // REGAL_ENUM_TO_STRING')
  code.append('    return "unknown_glx_enum";')
  code.append('  }')
  code.append('#endif // REGAL_SYS_GLX')

  # EGL version

  code.append('')
  code.append('#if REGAL_SYS_EGL')
  code.append('  const char * EGLenumToString(int v) {')
  code.append('    #if REGAL_ENUM_TO_STRING')
  code.append('    switch( v ) {')

  for i in apis:
    if i.name != 'egl':
      continue
    e = {}
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerantsByName:
        value = toLong(k.value)
        if value != None:
          if not value in e:
            e[value] = set()
          e[value].add(k.name)

    e = sorted([ (i,sorted(list(e[i]))) for i in e.iterkeys() ])
    e = [ i for i in e if i[0] < 0xfffffffff ]
    e = filterTokens(e)

    for i in e:
      value = i[0]
      if len(i[1]):
        name = i[1][0]
      else:
        name = i[2][0]

      if value==0:
        name = 'EGL_FALSE'
      if value==1:
        name = 'EGL_TRUE'

      code.append('      case %s: return "%s";'%(hexValue(value,'0x%08x'),name))

  code.append('      default: break;')
  code.append('    }')
  code.append('    #endif // REGAL_ENUM_TO_STRING')
  code.append('    return "unknown_egl_enum";')
  code.append('  }')
  code.append('#endif // REGAL_SYS_EGL')

  substitute = {}
  substitute['LICENSE']       = args.license
  substitute['AUTOGENERATED'] = args.generated
  substitute['COPYRIGHT']     = args.copyright
  substitute['CODE']          = '\n'.join(code)
  outputCode( '%s/RegalToken.cpp' % args.srcdir, tokenSourceTemplate.substitute(substitute))
Exemplo n.º 5
0
def generateTokenSource(apis, args):

    code = []

    code.append("  const char * GLenumToString( GLenum e ) {")
    code.append("    switch( e ) {")

    for i in apis:
        if i.name != "gl":
            continue
        e = {}
        for j in i.enums:
            if j.name != "defines":
                continue
            for k in j.enumerantsByName:
                value = toLong(k.value)
                if value != None:
                    if not value in e:
                        e[value] = set()
                    e[value].add(k.name)

        e = sorted([(i, sorted(list(e[i]))) for i in e.iterkeys()])
        e = [i for i in e if i[0] < 0xFFFFFFFFF]
        e = filterTokens(e)

        for i in e:
            value = i[0]
            if len(i[1]):
                name = i[1][0]
            else:
                name = i[2][0]

            if value == 0:
                name = "GL_ZERO"
            if value == 1:
                name = "GL_ONE"

            code.append('      case %s: return "%s";' % (hexValue(value, "0x%08x"), name))

    code.append("      default: break;")
    code.append("    }")
    code.append('  return "unknown_gl_enum";')
    code.append("  }")

    # GLerrorToString

    code.append("")
    code.append("  const char * GLerrorToString( GLenum e ) {")
    code.append("    switch( e ) {")
    for i in apis:
        if i.name != "gl":
            continue
        for j in i.enums:
            if j.name != "defines":
                continue
            for k in j.enumerantsByName:
                if getattr(k, "gluErrorString", None):
                    code.append('      case %s: return "%s";' % (k.name, k.gluErrorString))
    code.append("      default: break;")
    code.append("    }")
    code.append("  return NULL;")
    code.append("  }")

    # GLX_VERSION

    code.append("")
    code.append("#if REGAL_SYS_GLX")
    code.append("  const char * GLXenumToString(int v) {")
    code.append("    switch( v ) {")

    for i in apis:
        if i.name != "glx":
            continue
        e = {}
        for j in i.enums:
            if j.name != "defines":
                continue
            for k in j.enumerants:
                value = toLong(k.value)
                if value != None:
                    if not value in e:
                        e[value] = set()
                    e[value].add(k.name)

        e = sorted([(i, sorted(list(e[i]))) for i in e.iterkeys()])
        e = [i for i in e if i[0] < 0xFFFFFFFFF]
        e = filterTokens(e)

        for i in e:
            value = i[0]
            if len(i[1]):
                name = i[1][0]
            else:
                name = i[2][0]

            code.append('      case %s: return "%s";' % (hexValue(value, "0x%08x"), name))

    code.append("      default: break;")
    code.append("    }")
    code.append('    return "unknown_glx_enum";')
    code.append("  }")
    code.append("#endif // REGAL_SYS_GLX")

    # EGL version

    code.append("")
    code.append("#if REGAL_SYS_EGL")
    code.append("  const char * EGLenumToString(int v) {")
    code.append("    switch( v ) {")

    for i in apis:
        if i.name != "egl":
            continue
        e = {}
        for j in i.enums:
            if j.name != "defines":
                continue
            for k in j.enumerantsByName:
                value = toLong(k.value)
                if value != None:
                    if not value in e:
                        e[value] = set()
                    e[value].add(k.name)

        e = sorted([(i, sorted(list(e[i]))) for i in e.iterkeys()])
        e = [i for i in e if i[0] < 0xFFFFFFFFF]
        e = filterTokens(e)

        for i in e:
            value = i[0]
            if len(i[1]):
                name = i[1][0]
            else:
                name = i[2][0]

            if value == 0:
                name = "EGL_FALSE"
            if value == 1:
                name = "EGL_TRUE"

            code.append('      case %s: return "%s";' % (hexValue(value, "0x%08x"), name))

    code.append("      default: break;")
    code.append("    }")
    code.append('    return "unknown_egl_enum";')
    code.append("  }")
    code.append("#endif // REGAL_SYS_EGL")

    substitute = {}
    substitute["LICENSE"] = args.license
    substitute["AUTOGENERATED"] = args.generated
    substitute["COPYRIGHT"] = args.copyright
    substitute["CODE"] = "\n".join(code)
    outputCode("%s/RegalToken.cpp" % args.srcdir, tokenSourceTemplate.substitute(substitute))
Exemplo n.º 6
0
def generateTokenSource(apis, args):

  code = []

  code.append('  const char * GLenumToString( GLenum e ) {')
  code.append('    switch( e ) {')

  for i in apis:
    if i.name != 'gl':
      continue
    e = {}
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerants:
        value = toLong(k.value)
        if value != None:
          if not value in e:
            e[value] = set()
          e[value].add(k.name)

    e = sorted([ (i,sorted(list(e[i]))) for i in e.iterkeys() ])

    e = [ i for i in e if i[0] < 0xfffffffff ]

    # Filter out extension duplicates

    u = e
    for i in ['_ARB','_EXT','_NV','_ATI','_PGI','_OES','_IBM','_SUN','_SGI','_SGIX','_SGIS','_APPLE']:
      u = [ (j[0], [ k for k in j[1] if not k.endswith(i)  ]) for j in u ]

    # Filter out _BIT duplicates

    for i in ['_BIT','_BITS']:
      u = [ (j[0], [ k for k in j[1] if not k.endswith(i)  ]) for j in u ]

    u = [ (i[0], [ j for j in i[1] if not j.startswith('GL_KTX_') ]) for i in u  ]

    # Form tuple of value, filtered names, all names, per GLenum

    e = [ (e[i][0], u[i][1], e[i][1]) for i in xrange(len(e)) ]

    for i in e:
      value = i[0]
      if len(i[1]):
        name = i[1][0]
      else:
        name = i[2][0]

      if value==0:
        name = 'GL_ZERO'
      if value==1:
        name = 'GL_ONE'

      code.append('      case %s: return "%s";'%(hexValue(value,'0x%08x'),name))

  code.append('      default: break;')
  code.append('    }')
  code.append('  return "unknown_gl_enum";')
  code.append('  }')

  # GLerrorToString

  code.append('')
  code.append('  const char * GLerrorToString( GLenum e ) {')
  code.append('    switch( e ) {')
  for i in apis:
    if i.name != 'gl':
      continue
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerants:
        if getattr(k,'gluErrorString',None):
          code.append('      case %s: return "%s";'%(k.name,k.gluErrorString))
  code.append('      default: break;')
  code.append('    }')
  code.append('  return NULL;')
  code.append('  }')

  # GLX_VERSION

  code.append('')
  code.append('#if REGAL_SYS_GLX')
  code.append('  const char * GLXenumToString(int v) {')
  code.append('    switch( v ) {')

  for i in apis:
    if i.name != 'glx':
      continue
    e = {}
    for j in i.enums:
      if j.name != 'defines':
        continue
      for k in j.enumerants:
        value = toLong(k.value)
        if value != None:
          if not value in e:
            e[value] = set()
          e[value].add(k.name)

    e = sorted([ (i,sorted(list(e[i]))) for i in e.iterkeys() ])

    e = [ i for i in e if i[0] < 0xfffffffff ]

    # Filter out extension duplicates

    u = e
    for i in ['_ARB','_EXT','_NV','_ATI','_PGI','_OES','_IBM','_SUN','_SGI','_SGIX','_SGIS','_APPLE']:
      u = [ (j[0], [ k for k in j[1] if not k.endswith(i)  ]) for j in u ]

    # Filter out _BIT duplicates

    for i in ['_BIT','_BITS']:
      u = [ (j[0], [ k for k in j[1] if not k.endswith(i)  ]) for j in u ]

    u = [ (i[0], [ j for j in i[1] if not j.startswith('GL_KTX_') ]) for i in u  ]

    # Form tuple of value, filtered names, all names, per GLenum

    e = [ (e[i][0], u[i][1], e[i][1]) for i in xrange(len(e)) ]

    for i in e:
      value = i[0]
      if len(i[1]):
        name = i[1][0]
      else:
        name = i[2][0]

      code.append('      case %s: return "%s";'%(hexValue(value,'0x%08x'),name))

  code.append('      default: break;')
  code.append('    }')
  code.append('    return "unknown_glx_enum";')
  code.append('  }')
  code.append('#endif // REGAL_SYS_GLX')

  substitute = {}
  substitute['LICENSE']       = args.license
  substitute['AUTOGENERATED'] = args.generated
  substitute['COPYRIGHT']     = args.copyright
  substitute['CODE']          = '\n'.join(code)
  outputCode( '%s/RegalToken.cpp' % args.outdir, tokenSourceTemplate.substitute(substitute))
Exemplo n.º 7
0
def apiFuncDeclareCode(apis, args):
    code = ""

    for api in apis:

        d = []  # defines
        e = []  # enums
        t = []  # function pointer typedefs
        m = []  # mangled names for REGAL_NAMESPACE support
        f = []  # gl names
        p = []  # plugin names for REGAL_PLUGIN_MODE support

        for enum in api.enums:
            if enum.name == "defines":
                for enumerant in enum.enumerants:
                    value = toLong(enumerant.value)
                    if value == None:
                        value = enumerant.value

                    # Don't bother with decimal for 0-10
                    if isinstance(value, long) and value >= 10:
                        e.append(
                            (enumerant.category, "#define %s %s /* %s */" % (enumerant.name, hexValue(value), value))
                        )
                    else:
                        e.append((enumerant.category, "#define %s %s" % (enumerant.name, hexValue(value))))

        for function in api.functions:

            name = function.name
            params = paramsDefaultCode(function.parameters, True)
            rType = typeCode(function.ret.type)
            category = getattr(function, "category", None)
            version = getattr(function, "version", None)

            if category:
                category = category.replace("_DEPRECATED", "")
            elif version:
                category = version.replace(".", "_")
                category = "GL_VERSION_" + category

            t.append((category, funcProtoCode(function, version, "REGAL_CALL", True)))
            m.append((category, "#define %-35s r%-35s" % (name, name)))
            f.append((category, "REGAL_DECL %sREGAL_CALL %s(%s);" % (rType, name, params)))
            p.append((category, "REGAL_DECL %sREGAL_CALL plugin_%s(%s);" % (rType, name, params)))

        def cmpEnum(a, b):
            if a[0] == b[0]:
                aValue = a[1].split(" ")[2]
                bValue = b[1].split(" ")[2]
                if aValue == bValue:
                    return cmp(a[1].split(" ")[1], b[1].split(" ")[1])
                else:
                    return cmp(aValue, bValue)
            return cmp(a[0], b[0])

        def enumIfDef(category):
            return "#ifndef REGAL_NO_ENUM_%s" % (upper(category).replace(" ", "_"))

        def typedefIfDef(category):
            return "#ifndef REGAL_NO_TYPEDEF_%s" % (upper(category).replace(" ", "_"))

        def namespaceIfDef(category):
            return "#ifndef REGAL_NO_NAMESPACE_%s" % (upper(category).replace(" ", "_"))

        def pluginIfDef(category):
            return "#ifndef REGAL_NO_PLUGIN_%s" % (upper(category).replace(" ", "_"))

        def declarationIfDef(category):
            return "#ifndef REGAL_NO_DECLARATION_%s" % (upper(category).replace(" ", "_"))

        categories = set()
        categories.update([i[0] for i in e])
        categories.update([i[0] for i in t])
        categories.update([i[0] for i in m])
        categories.update([i[0] for i in p])
        categories.update([i[0] for i in f])

        for i in categories:
            if len(i):
                cat = upper(i).replace(" ", "_")

                d.append(
                    (
                        i,
                        "#if (defined(%s) || defined(REGAL_NO_ENUM) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_ENUM_%s)"
                        % (cat, cat, cat),
                    )
                )
                d.append((i, "#define REGAL_NO_ENUM_%s" % (cat)))
                d.append((i, "#endif"))
                d.append((i, ""))

                d.append(
                    (
                        i,
                        "#if (defined(%s) || defined(REGAL_NO_TYPEDEF) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_TYPEDEF_%s)"
                        % (cat, cat, cat),
                    )
                )
                d.append((i, "#define REGAL_NO_TYPEDEF_%s" % (cat)))
                d.append((i, "#endif"))
                d.append((i, ""))

                d.append(
                    (
                        i,
                        "#if (defined(%s) || !defined(REGAL_NAMESPACE) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_NAMESPACE_%s)"
                        % (cat, cat, cat),
                    )
                )
                d.append((i, "#define REGAL_NO_NAMESPACE_%s" % (cat)))
                d.append((i, "#endif"))
                d.append((i, ""))

                d.append(
                    (
                        i,
                        "#if (defined(%s) || !defined(REGAL_PLUGIN_MODE) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_PLUGIN_%s)"
                        % (cat, cat, cat),
                    )
                )
                d.append((i, "#define REGAL_NO_PLUGIN_%s" % (cat)))
                d.append((i, "#endif"))
                d.append((i, ""))

                d.append(
                    (
                        i,
                        "#if (defined(%s) || defined(REGAL_NO_DECLARATION) || defined(REGAL_NO_%s)) && !defined(REGAL_NO_DECLARATION_%s)"
                        % (cat, cat, cat),
                    )
                )
                d.append((i, "#define REGAL_NO_DECLARATION_%s" % (cat)))
                d.append((i, "#endif"))
                d.append((i, ""))

                d.append((i, "#ifndef %s" % (i)))
                d.append((i, "#define %s 1" % (i)))
                d.append((i, "#endif"))
                d.append((i, ""))

        e.sort(cmpEnum)
        e = alignDefineCategory(e)
        e = ifCategory(e, enumIfDef)
        e = spaceCategory(e)

        t.sort()
        t = ifCategory(t, typedefIfDef)
        t = spaceCategory(t)

        m.sort()
        m = ifCategory(m, namespaceIfDef)
        m = spaceCategory(m)

        f.sort()
        f = ifCategory(f, declarationIfDef)
        f = spaceCategory(f)

        p.sort()
        p = ifCategory(p, pluginIfDef)
        p = spaceCategory(p)

        d.extend(e)
        d.extend(t)
        d.extend(m)
        d.extend(f)
        d.extend(p)

        tmp = listToString(unfoldCategory(d, "/**\n ** %s\n **/", lambda x, y: cmp(x[0], y[0])))

        if api.name == "wgl":
            tmp = wrapIf("REGAL_SYS_WGL_DECLARE_WGL", tmp)
        if api.name in cond:
            tmp = wrapIf(cond[api.name], tmp)

        code += "%s\n" % (tmp)

    return code
Exemplo n.º 8
0
def generateTokenSource(apis, args):

    code = []

    code.append('  const char * GLenumToString( GLenum e ) {')
    code.append('    switch( e ) {')

    for i in apis:
        if i.name != 'gl':
            continue
        e = {}
        for j in i.enums:
            if j.name != 'defines':
                continue
            for k in j.enumerants:
                value = toLong(k.value)
                if value != None:
                    if not value in e:
                        e[value] = set()
                    e[value].add(k.name)

        e = sorted([(i, sorted(list(e[i]))) for i in e.iterkeys()])

        e = [i for i in e if i[0] < 0xfffffffff]

        # Filter out extension duplicates

        u = e
        for i in [
                '_ARB', '_EXT', '_NV', '_ATI', '_PGI', '_OES', '_IBM', '_SUN',
                '_SGI', '_SGIX', '_SGIS', '_APPLE'
        ]:
            u = [(j[0], [k for k in j[1] if not k.endswith(i)]) for j in u]

        # Filter out _BIT duplicates

        for i in ['_BIT', '_BITS']:
            u = [(j[0], [k for k in j[1] if not k.endswith(i)]) for j in u]

        u = [(i[0], [j for j in i[1] if not j.startswith('GL_KTX_')])
             for i in u]

        # Form tuple of value, filtered names, all names, per GLenum

        e = [(e[i][0], u[i][1], e[i][1]) for i in xrange(len(e))]

        for i in e:
            value = i[0]
            if len(i[1]):
                name = i[1][0]
            else:
                name = i[2][0]

            if value == 0:
                name = 'GL_ZERO'
            if value == 1:
                name = 'GL_ONE'

            code.append('      case %s: return "%s";' %
                        (hexValue(value, '0x%08x'), name))

    code.append('      default: break;')
    code.append('    }')
    code.append('  return "unknown_gl_enum";')
    code.append('  }')

    # GLerrorToString

    code.append('')
    code.append('  const char * GLerrorToString( GLenum e ) {')
    code.append('    switch( e ) {')
    for i in apis:
        if i.name != 'gl':
            continue
        for j in i.enums:
            if j.name != 'defines':
                continue
            for k in j.enumerants:
                if getattr(k, 'gluErrorString', None):
                    code.append('      case %s: return "%s";' %
                                (k.name, k.gluErrorString))
    code.append('      default: break;')
    code.append('    }')
    code.append('  return NULL;')
    code.append('  }')

    # GLX_VERSION

    code.append('')
    code.append('#if REGAL_SYS_GLX')
    code.append('  const char * GLXenumToString(int v) {')
    code.append('    switch( v ) {')

    for i in apis:
        if i.name != 'glx':
            continue
        e = {}
        for j in i.enums:
            if j.name != 'defines':
                continue
            for k in j.enumerants:
                value = toLong(k.value)
                if value != None:
                    if not value in e:
                        e[value] = set()
                    e[value].add(k.name)

        e = sorted([(i, sorted(list(e[i]))) for i in e.iterkeys()])

        e = [i for i in e if i[0] < 0xfffffffff]

        # Filter out extension duplicates

        u = e
        for i in [
                '_ARB', '_EXT', '_NV', '_ATI', '_PGI', '_OES', '_IBM', '_SUN',
                '_SGI', '_SGIX', '_SGIS', '_APPLE'
        ]:
            u = [(j[0], [k for k in j[1] if not k.endswith(i)]) for j in u]

        # Filter out _BIT duplicates

        for i in ['_BIT', '_BITS']:
            u = [(j[0], [k for k in j[1] if not k.endswith(i)]) for j in u]

        u = [(i[0], [j for j in i[1] if not j.startswith('GL_KTX_')])
             for i in u]

        # Form tuple of value, filtered names, all names, per GLenum

        e = [(e[i][0], u[i][1], e[i][1]) for i in xrange(len(e))]

        for i in e:
            value = i[0]
            if len(i[1]):
                name = i[1][0]
            else:
                name = i[2][0]

            code.append('      case %s: return "%s";' %
                        (hexValue(value, '0x%08x'), name))

    code.append('      default: break;')
    code.append('    }')
    code.append('    return "unknown_glx_enum";')
    code.append('  }')
    code.append('#endif // REGAL_SYS_GLX')

    substitute = {}
    substitute['LICENSE'] = args.license
    substitute['AUTOGENERATED'] = args.generated
    substitute['COPYRIGHT'] = args.copyright
    substitute['CODE'] = '\n'.join(code)
    outputCode('%s/RegalToken.cpp' % args.outdir,
               tokenSourceTemplate.substitute(substitute))