Example #1
0
def enumerantListCode(enumerants, comments = None):

  lines = []
  size = len(enumerants)
  enumerantWidth = maxLength(enumerants, len) + 1
  commentWidth   = maxLength(comments, len)
  for i in xrange(size):
    enum = enumerants[i]
    if i < size - 1:
      enum += ','
    comment = ''
    if comments is not None and comments[i]:
      comment = ' /* %s */' % (comments[i].ljust(commentWidth))
    lines.append(('%s%s' % (enum.ljust(enumerantWidth), comment)).rstrip())
  return lines
Example #2
0
def enumerantListCode(enumerants, comments=None):

    lines = []
    size = len(enumerants)
    enumerantWidth = maxLength(enumerants, len) + 1
    commentWidth = maxLength(comments, len)
    for i in xrange(size):
        enum = enumerants[i]
        if i < size - 1:
            enum += ','
        comment = ''
        if comments is not None and comments[i]:
            comment = ' /* %s */' % (comments[i].ljust(commentWidth))
        lines.append(('%s%s' % (enum.ljust(enumerantWidth), comment)).rstrip())
    return lines
Example #3
0
 def align(code):
   tmp = []
   maxlen = [ 0,0,0,0 ]
   for i in code:
     l = lengths(i[1].split(' '))
     maxlen = maxLength(maxlen,l)
   if len(code)>1 and maxlen[3]>0:
     maxlen[2] = maxlen[2] + 4
   for i in code:
     s = i[1].split(' ')
     if len(s)>3:
       s[3] = ' '.join(s[3:])
     else:
       s.append('')
     tmp.append((i[0], '#define ' + s[1].ljust(maxlen[1]+1) + s[2].ljust(maxlen[2]+1) + s[3]))
   return tmp
Example #4
0
 def align(code):
     tmp = []
     maxlen = [0, 0, 0, 0]
     for i in code:
         l = lengths(i[1].split(' '))
         maxlen = maxLength(maxlen, l)
     if len(code) > 1 and maxlen[3] > 0:
         maxlen[2] = maxlen[2] + 4
     for i in code:
         s = i[1].split(' ')
         if len(s) > 3:
             s[3] = ' '.join(s[3:])
         else:
             s.append('')
         tmp.append((i[0], '#define ' + s[1].ljust(maxlen[1] + 1) +
                     s[2].ljust(maxlen[2] + 1) + s[3]))
     return tmp
Example #5
0
def enumerationQueryCode(enumerants, test, name, type):
    var = 'p'
    if type == 'CGtype':
        var = 't'
    ret = []
    ret.append('\ninline bool %s(const %s %s)' % (name, type, var))
    ret.append('{')
    subset = [i for i in enumerants if test(i)]
    if len(subset):
        width = maxLength(subset, lambda i: (len(i.name)))
        ret.append('  return')
        last = subset.pop()
        for i in subset:
            ret.append('    %s==%s ||' % (var, i.name.ljust(width)))
        ret.append('    %s==%s;' % (var, last.name))
    else:
        ret.append('  return false;')
    ret.append('}')
    return '\n'.join(ret)
Example #6
0
def enumerationQueryCode(enumerants, test, name, type):
  var = 'p'
  if type=='CGtype':
    var = 't'
  ret = []
  ret.append('\ninline bool %s(const %s %s)'%(name,type,var))
  ret.append('{')
  subset = [i for i in enumerants if test(i)];
  if len(subset):
    width = maxLength(subset, lambda i:( len(i.name) ))
    ret.append('  return')
    last = subset.pop()
    for i in subset:
      ret.append('    %s==%s ||'%(var,i.name.ljust(width)))
    ret.append('    %s==%s;'%(var,last.name))
  else:
    ret.append('  return false;')
  ret.append('}')
  return '\n'.join(ret)
Example #7
0
def enumerationQueryCode(enumerants, test, name, type):
    var = "p"
    if type == "CGtype":
        var = "t"
    ret = []
    ret.append("\ninline bool %s(const %s %s)" % (name, type, var))
    ret.append("{")
    subset = [i for i in enumerants if test(i)]
    if len(subset):
        width = maxLength(subset, lambda i: (len(i.name)))
        ret.append("  return")
        last = subset.pop()
        for i in subset:
            ret.append("    %s==%s ||" % (var, i.name.ljust(width)))
        ret.append("    %s==%s;" % (var, last.name))
    else:
        ret.append("  return false;")
    ret.append("}")
    return "\n".join(ret)