зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1155968 - Add blank lines where needed in xpcom/idl-parser. r=khuey
This commit is contained in:
Родитель
ec7138788a
Коммит
5562b1dcb8
|
@ -24,22 +24,27 @@ else:
|
|||
def printComments(fd, clist, indent):
|
||||
pass
|
||||
|
||||
|
||||
def firstCap(str):
|
||||
return str[0].upper() + str[1:]
|
||||
|
||||
|
||||
def attributeParamName(a):
|
||||
return "a" + firstCap(a.name)
|
||||
|
||||
|
||||
def attributeParamNames(a):
|
||||
l = [attributeParamName(a)]
|
||||
if a.implicit_jscontext:
|
||||
l.insert(0, "cx")
|
||||
return ", ".join(l)
|
||||
|
||||
|
||||
def attributeNativeName(a, getter):
|
||||
binaryname = a.binaryname is not None and a.binaryname or firstCap(a.name)
|
||||
return "%s%s" % (getter and 'Get' or 'Set', binaryname)
|
||||
|
||||
|
||||
def attributeReturnType(a, macro):
|
||||
"""macro should be NS_IMETHOD or NS_IMETHODIMP"""
|
||||
if (a.nostdcall):
|
||||
|
@ -47,6 +52,7 @@ def attributeReturnType(a, macro):
|
|||
else:
|
||||
return macro
|
||||
|
||||
|
||||
def attributeParamlist(a, getter):
|
||||
l = ["%s%s" % (a.realtype.nativeType(getter and 'out' or 'in'),
|
||||
attributeParamName(a))]
|
||||
|
@ -55,6 +61,7 @@ def attributeParamlist(a, getter):
|
|||
|
||||
return ", ".join(l)
|
||||
|
||||
|
||||
def attributeAsNative(a, getter):
|
||||
deprecated = a.deprecated and "NS_DEPRECATED " or ""
|
||||
params = {'deprecated': deprecated,
|
||||
|
@ -63,9 +70,11 @@ def attributeAsNative(a, getter):
|
|||
'paramlist': attributeParamlist(a, getter)}
|
||||
return "%(deprecated)s%(returntype)s %(binaryname)s(%(paramlist)s)" % params
|
||||
|
||||
|
||||
def methodNativeName(m):
|
||||
return m.binaryname is not None and m.binaryname or firstCap(m.name)
|
||||
|
||||
|
||||
def methodReturnType(m, macro):
|
||||
"""macro should be NS_IMETHOD or NS_IMETHODIMP"""
|
||||
if m.nostdcall and m.notxpcom:
|
||||
|
@ -78,11 +87,13 @@ def methodReturnType(m, macro):
|
|||
else:
|
||||
return macro
|
||||
|
||||
|
||||
def methodAsNative(m):
|
||||
return "%s %s(%s)" % (methodReturnType(m, 'NS_IMETHOD'),
|
||||
methodNativeName(m),
|
||||
paramlistAsNative(m))
|
||||
|
||||
|
||||
def paramlistAsNative(m, empty='void'):
|
||||
l = [paramAsNative(p) for p in m.params]
|
||||
|
||||
|
@ -105,10 +116,12 @@ def paramlistAsNative(m, empty='void'):
|
|||
|
||||
return ", ".join(l)
|
||||
|
||||
|
||||
def paramAsNative(p):
|
||||
return "%s%s" % (p.nativeType(),
|
||||
p.name)
|
||||
|
||||
|
||||
def paramlistNames(m):
|
||||
names = [p.name for p in m.params]
|
||||
|
||||
|
@ -162,10 +175,12 @@ forward_decl = """class %(name)s; /* forward declaration */
|
|||
|
||||
"""
|
||||
|
||||
|
||||
def idl_basename(f):
|
||||
"""returns the base name of a file with the last extension stripped"""
|
||||
return os.path.basename(f).rpartition('.')[0]
|
||||
|
||||
|
||||
def print_header(idl, fd, filename):
|
||||
fd.write(header % {'filename': filename,
|
||||
'basename': idl_basename(filename)})
|
||||
|
@ -307,6 +322,7 @@ attr_infallible_tmpl = """\
|
|||
}
|
||||
"""
|
||||
|
||||
|
||||
def write_interface(iface, fd):
|
||||
if iface.namemap is None:
|
||||
raise Exception("Interface was not resolved.")
|
||||
|
|
|
@ -9,6 +9,7 @@ import mozunit
|
|||
import unittest
|
||||
import xpidl
|
||||
|
||||
|
||||
class TestParser(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.p = xpidl.IDLParser()
|
||||
|
|
|
@ -48,10 +48,12 @@ TypeMap = {
|
|||
'jsval': xpt.Type.Tags.jsval
|
||||
}
|
||||
|
||||
|
||||
# XXXkhuey dipper types should go away (bug 677784)
|
||||
def isDipperType(type):
|
||||
return type == xpt.Type.Tags.DOMString or type == xpt.Type.Tags.AString or type == xpt.Type.Tags.CString or type == xpt.Type.Tags.UTF8String
|
||||
|
||||
|
||||
def build_interface(iface, ifaces):
|
||||
def get_type(type, calltype, iid_is=None, size_is=None):
|
||||
""" Return the appropriate xpt.Type object for this param """
|
||||
|
@ -236,6 +238,7 @@ def build_interface(iface, ifaces):
|
|||
builtinclass=iface.attributes.builtinclass,
|
||||
main_process_scriptable_only=iface.attributes.main_process_scriptable_only)
|
||||
|
||||
|
||||
def write_typelib(idl, fd, filename):
|
||||
""" Generate the typelib. """
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ Interface members const/method/attribute conform to the following pattern:
|
|||
'returns the member signature as IDL'
|
||||
"""
|
||||
|
||||
|
||||
def attlistToIDL(attlist):
|
||||
if len(attlist) == 0:
|
||||
return ''
|
||||
|
@ -45,6 +46,7 @@ _paramsHardcode = {
|
|||
3: ('array', 'size_is', 'const'),
|
||||
}
|
||||
|
||||
|
||||
def paramAttlistToIDL(attlist):
|
||||
if len(attlist) == 0:
|
||||
return ''
|
||||
|
@ -69,12 +71,14 @@ def paramAttlistToIDL(attlist):
|
|||
return '[%s] ' % ', '.join(["%s%s" % (name, value is not None and ' (%s)' % value or '')
|
||||
for name, value, aloc in sorted])
|
||||
|
||||
|
||||
def unaliasType(t):
|
||||
while t.kind == 'typedef':
|
||||
t = t.realtype
|
||||
assert t is not None
|
||||
return t
|
||||
|
||||
|
||||
def getBuiltinOrNativeTypeName(t):
|
||||
t = unaliasType(t)
|
||||
if t.kind == 'builtin':
|
||||
|
@ -85,6 +89,7 @@ def getBuiltinOrNativeTypeName(t):
|
|||
else:
|
||||
return None
|
||||
|
||||
|
||||
class BuiltinLocation(object):
|
||||
def get(self):
|
||||
return "<builtin type>"
|
||||
|
@ -92,6 +97,7 @@ class BuiltinLocation(object):
|
|||
def __str__(self):
|
||||
return self.get()
|
||||
|
||||
|
||||
class Builtin(object):
|
||||
kind = 'builtin'
|
||||
location = BuiltinLocation
|
||||
|
@ -142,6 +148,7 @@ builtinMap = {}
|
|||
for b in builtinNames:
|
||||
builtinMap[b.name] = b
|
||||
|
||||
|
||||
class Location(object):
|
||||
_line = None
|
||||
|
||||
|
@ -181,6 +188,7 @@ class Location(object):
|
|||
return "%s line %s:%s\n%s\n%s" % (self._file, self._lineno, self._colno,
|
||||
self._line, self.pointerline())
|
||||
|
||||
|
||||
class NameMap(object):
|
||||
"""Map of name -> object. Each object must have a .name and .location property.
|
||||
Setting the same name twice throws an error."""
|
||||
|
@ -221,6 +229,7 @@ class NameMap(object):
|
|||
except KeyError:
|
||||
raise IDLError("Name '%s' not found", location)
|
||||
|
||||
|
||||
class IDLError(Exception):
|
||||
def __init__(self, message, location, warning=False):
|
||||
self.message = message
|
||||
|
@ -231,6 +240,7 @@ class IDLError(Exception):
|
|||
return "%s: %s, %s" % (self.warning and 'warning' or 'error',
|
||||
self.message, self.location)
|
||||
|
||||
|
||||
class Include(object):
|
||||
kind = 'include'
|
||||
|
||||
|
@ -259,6 +269,7 @@ class Include(object):
|
|||
|
||||
raise IDLError("File '%s' not found" % self.filename, self.location)
|
||||
|
||||
|
||||
class IDL(object):
|
||||
def __init__(self, productions):
|
||||
self.productions = productions
|
||||
|
@ -300,6 +311,7 @@ class IDL(object):
|
|||
return True
|
||||
return False
|
||||
|
||||
|
||||
class CDATA(object):
|
||||
kind = 'cdata'
|
||||
_re = re.compile(r'\n+')
|
||||
|
@ -317,6 +329,7 @@ class CDATA(object):
|
|||
def count(self):
|
||||
return 0
|
||||
|
||||
|
||||
class Typedef(object):
|
||||
kind = 'typedef'
|
||||
|
||||
|
@ -343,6 +356,7 @@ class Typedef(object):
|
|||
def __str__(self):
|
||||
return "typedef %s %s\n" % (self.type, self.name)
|
||||
|
||||
|
||||
class Forward(object):
|
||||
kind = 'forward'
|
||||
|
||||
|
@ -377,6 +391,7 @@ class Forward(object):
|
|||
def __str__(self):
|
||||
return "forward-declared %s\n" % self.name
|
||||
|
||||
|
||||
class Native(object):
|
||||
kind = 'native'
|
||||
|
||||
|
@ -462,6 +477,7 @@ class Native(object):
|
|||
def __str__(self):
|
||||
return "native %s(%s)\n" % (self.name, self.nativename)
|
||||
|
||||
|
||||
class Interface(object):
|
||||
kind = 'interface'
|
||||
|
||||
|
@ -578,6 +594,7 @@ class Interface(object):
|
|||
total += realbase.countEntries()
|
||||
return total
|
||||
|
||||
|
||||
class InterfaceAttributes(object):
|
||||
uuid = None
|
||||
scriptable = False
|
||||
|
@ -655,6 +672,7 @@ class InterfaceAttributes(object):
|
|||
l.append("\tmain_process_scriptable_only\n")
|
||||
return "".join(l)
|
||||
|
||||
|
||||
class ConstMember(object):
|
||||
kind = 'const'
|
||||
def __init__(self, type, name, value, location, doccomments):
|
||||
|
@ -684,6 +702,7 @@ class ConstMember(object):
|
|||
def count(self):
|
||||
return 0
|
||||
|
||||
|
||||
class Attribute(object):
|
||||
kind = 'attribute'
|
||||
noscript = False
|
||||
|
@ -787,6 +806,7 @@ class Attribute(object):
|
|||
def count(self):
|
||||
return self.readonly and 1 or 2
|
||||
|
||||
|
||||
class Method(object):
|
||||
kind = 'method'
|
||||
noscript = False
|
||||
|
@ -889,6 +909,7 @@ class Method(object):
|
|||
def count(self):
|
||||
return 1
|
||||
|
||||
|
||||
class Param(object):
|
||||
size_is = None
|
||||
iid_is = None
|
||||
|
@ -981,6 +1002,7 @@ class Param(object):
|
|||
self.type,
|
||||
self.name)
|
||||
|
||||
|
||||
class Array(object):
|
||||
def __init__(self, basetype):
|
||||
self.type = basetype
|
||||
|
@ -992,6 +1014,7 @@ class Array(object):
|
|||
return "%s%s*" % (const and 'const ' or '',
|
||||
self.type.nativeType(calltype))
|
||||
|
||||
|
||||
class IDLParser(object):
|
||||
keywords = {
|
||||
'const': 'CONST',
|
||||
|
|
Загрузка…
Ссылка в новой задаче