Bug 918651 - part 3 - add optional |from header| qualification to using statements in ipdl; r=bent

This commit is contained in:
Nathan Froyd 2013-09-23 21:20:18 -04:00
Родитель 0726779150
Коммит f177ad89af
2 изменённых файлов: 34 добавлений и 4 удалений

Просмотреть файл

@ -186,9 +186,20 @@ class Include(Node):
self.file = "%s.%s" % (name, suffix)
class UsingStmt(Node):
def __init__(self, loc, cxxTypeSpec):
def __init__(self, loc, cxxTypeSpec, cxxHeader=None, kind=None):
Node.__init__(self, loc)
assert not isinstance(cxxTypeSpec, str)
assert cxxHeader is None or isinstance(cxxHeader, str);
assert kind is None or kind == 'class' or kind == 'struct'
self.type = cxxTypeSpec
self.header = cxxHeader
self.kind = kind
def canBeForwardDeclared(self):
return self.isClass() or self.isStruct()
def isClass(self):
return self.kind == 'class'
def isStruct(self):
return self.kind == 'struct'
# "singletons"
class PrettyPrinted:

Просмотреть файл

@ -121,9 +121,11 @@ reserved = set((
'bridges',
'call',
'child',
'class',
'compress',
'__delete__',
'delete', # reserve 'delete' to prevent its use
'from',
'goto',
'include',
'intr',
@ -267,13 +269,30 @@ def p_IncludeStmt(p):
if path is None:
raise ParseError(loc, "can't locate include file `%s'"% (
inc.file))
inc.tu = Parser(type, id).parse(open(path).read(), path, Parser.current.includedirs, Parser.current.errout)
p[0] = inc
def p_UsingStmt(p):
"""UsingStmt : USING CxxType"""
p[0] = UsingStmt(locFromTok(p, 1), p[2])
"""UsingStmt : USING CxxType
| USING CxxType FROM STRING
| USING CLASS CxxType FROM STRING
| USING STRUCT CxxType FROM STRING"""
if 6 == len(p):
header = p[5]
elif 5 == len(p):
header = p[4]
else:
header = None
if 6 == len(p):
kind = p[2]
else:
kind = None
if 6 == len(p):
cxxtype = p[3]
else:
cxxtype = p[2]
p[0] = UsingStmt(locFromTok(p, 1), cxxtype, header, kind)
##--------------------
## Namespaced stuff