131
131
Builtin('double', 'double', True, False),
132
132
Builtin('char', 'char', True, False),
133
133
Builtin('string', 'char *', False, False),
134
Builtin('wchar', 'PRUnichar', False, False),
135
Builtin('wstring', 'PRUnichar *', False, False),
134
Builtin('wchar', 'char16_t', False, False),
135
Builtin('wstring', 'char16_t *', False, False),
429
429
return self.modifier == 'ref'
431
431
def isPtr(self, calltype):
432
return self.modifier == 'ptr' or (self.modifier == 'ref' and self.specialtype == 'jsval' and calltype == 'out')
432
return self.modifier == 'ptr'
434
434
def isRef(self, calltype):
435
return self.modifier == 'ref' and not (self.specialtype == 'jsval' and calltype == 'out')
435
return self.modifier == 'ref'
437
437
def nativeType(self, calltype, const=False, shared=False):
443
443
if self.specialtype is not None and calltype == 'in':
446
if self.specialtype == 'jsval':
447
if calltype == 'out' or calltype == 'inout':
448
return "JS::MutableHandleValue "
449
return "JS::HandleValue "
446
451
if self.isRef(calltype):
448
453
elif self.isPtr(calltype):
454
459
def __str__(self):
455
460
return "native %s(%s)\n" % (self.name, self.nativename)
457
class BaseInterface(object):
462
class Interface(object):
458
465
def __init__(self, name, attlist, base, members, location, doccomments):
460
467
self.attributes = InterfaceAttributes(attlist, location)
462
if self.kind == 'dictionary':
463
members.sort(key=lambda x:x.name)
464
469
self.members = members
465
470
self.location = location
466
471
self.namemap = NameMap()
498
503
parent.setName(self)
499
504
if self.base is not None:
500
505
realbase = parent.getName(self.base, self.location)
501
if realbase.kind != self.kind:
502
raise IDLError("%s '%s' inherits from non-%s type '%s'" % (self.kind, self.name, self.kind, self.base), self.location)
506
if realbase.kind != 'interface':
507
raise IDLError("interface '%s' inherits from non-interface type '%s'" % (self.name, self.base), self.location)
504
509
if self.attributes.scriptable and not realbase.attributes.scriptable:
505
510
print >>sys.stderr, IDLError("interface '%s' is scriptable but derives from non-scriptable '%s'" % (self.name, self.base), self.location, warning=True)
570
575
total += realbase.countEntries()
573
class Interface(BaseInterface):
576
def __init__(self, name, attlist, base, members, location, doccomments):
577
BaseInterface.__init__(self, name, attlist, base, members, location, doccomments)
579
if self.attributes.uuid is None:
580
raise IDLError("interface has no uuid", location)
582
class Dictionary(BaseInterface):
585
def __init__(self, name, attlist, base, members, location, doccomments):
586
BaseInterface.__init__(self, name, attlist, base, members, location, doccomments)
588
578
class InterfaceAttributes(object):
590
580
scriptable = False
693
686
deprecated = False
695
687
infallible = False
698
def __init__(self, type, name, attlist, readonly, nullable, defvalue, location, doccomments):
689
def __init__(self, type, name, attlist, readonly, location, doccomments):
701
692
self.attlist = attlist
702
693
self.readonly = readonly
703
self.nullable = nullable
704
self.defvalue = defvalue
705
694
self.location = location
706
695
self.doccomments = doccomments
762
751
getBuiltinOrNativeTypeName(self.realtype) != '[domstring]'):
763
752
raise IDLError("'Undefined' attribute can only be used on DOMString",
765
if (self.nullable and
766
getBuiltinOrNativeTypeName(self.realtype) != '[domstring]'):
767
raise IDLError("Nullable types (T?) is supported only for DOMString",
769
754
if self.infallible and not self.realtype.kind == 'builtin':
770
755
raise IDLError('[infallible] only works on builtin types '
771
756
'(numbers, booleans, and raw char types)',
1074
1057
t.value = value
1077
def t_STRING(self, t):
1079
begin, value, end = t.value.split('"')
1083
1060
def t_directive(self, t):
1084
1061
r'\#(?P<directive>[a-zA-Z]+)[^\n]+'
1085
1062
raise IDLError("Unrecognized directive %s" % t.lexer.lexmatch.group('directive'),
1309
1285
p[0] = lambda i: n1(i) | n2(i)
1311
1287
def p_member_att(self, p):
1312
"""member : attributes optreadonly ATTRIBUTE IDENTIFIER identifier ';'"""
1288
"""member : attributes optreadonly ATTRIBUTE IDENTIFIER IDENTIFIER ';'"""
1313
1289
if 'doccomments' in p[1]:
1314
1290
doccomments = p[1]['doccomments']
1315
1291
elif p[2] is not None:
1384
def p_dictionary(self, p):
1385
"""dictionary : attributes DICTIONARY IDENTIFIER ifacebase dictbody ';'"""
1386
atts, DICTIONARY, name, base, body, SEMI = p[1:]
1387
attlist = atts['attlist']
1389
if 'doccomments' in atts:
1390
doccomments.extend(atts['doccomments'])
1391
doccomments.extend(p.slice[2].doccomments)
1393
l = lambda: self.getLocation(p, 2)
1395
p[0] = Dictionary(name=name,
1400
doccomments=doccomments)
1402
def p_dictbody(self, p):
1403
"""dictbody : '{' dictmembers '}'
1408
def p_dictmembers_start(self, p):
1409
"""dictmembers : """
1412
def p_dictmembers_continue(self, p):
1413
"""dictmembers : dictmember dictmembers"""
1415
p[0].insert(0, p[1])
1417
def p_dictmember(self, p):
1418
"""dictmember : attributes IDENTIFIER optnullable IDENTIFIER optdefvalue ';'"""
1419
if 'doccomments' in p[1]:
1420
doccomments = p[1]['doccomments']
1422
doccomments = p.slice[2].doccomments
1424
p[0] = Attribute(type=p[2],
1426
attlist=p[1]['attlist'],
1428
nullable=p[3] is not None,
1430
location=self.getLocation(p, 1),
1431
doccomments=doccomments)
1433
def p_optnullable(self, p):
1434
"""optnullable : '?'
1441
def p_optdefvalue(self, p):
1442
"""optdefvalue : '=' STRING
1447
p[0] = "".join(p[2:])
1451
def p_identifier(self, p):
1452
"""identifier : DICTIONARY
1456
1358
def p_raises(self, p):
1457
1359
"""raises : RAISES '(' idlist ')'