Remove trailing whitespace and add modelines info
svn path=/trunk/; revision=53751
This commit is contained in:
parent
ede151cbba
commit
225161b1be
@ -33,12 +33,12 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
# Description:
|
# Description:
|
||||||
#
|
#
|
||||||
# Omniidl Back-end which parses an IDL data structure provided by the frontend
|
# Omniidl Back-end which parses an IDL data structure provided by the frontend
|
||||||
# and generates packet-idl-xxx.[ch] for compiling as a dissector in
|
# and generates packet-idl-xxx.[ch] for compiling as a dissector in
|
||||||
# Wireshark IP protocol anlayser.
|
# Wireshark IP protocol anlayser.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Strategy.
|
# Strategy.
|
||||||
@ -72,7 +72,7 @@ from wireshark_gen import wireshark_gen_C
|
|||||||
class WiresharkVisitor:
|
class WiresharkVisitor:
|
||||||
|
|
||||||
DEBUG = 0 # debug flag
|
DEBUG = 0 # debug flag
|
||||||
|
|
||||||
def __init__(self, st):
|
def __init__(self, st):
|
||||||
self.st = st
|
self.st = st
|
||||||
self.oplist = [] # list of operation nodes
|
self.oplist = [] # list of operation nodes
|
||||||
@ -81,11 +81,11 @@ class WiresharkVisitor:
|
|||||||
self.stlist = [] # list of struct nodes
|
self.stlist = [] # list of struct nodes
|
||||||
self.unlist = [] # list of union nodes
|
self.unlist = [] # list of union nodes
|
||||||
|
|
||||||
|
|
||||||
def visitAST(self, node):
|
def visitAST(self, node):
|
||||||
if self.DEBUG:
|
if self.DEBUG:
|
||||||
print "XXX visitAST() node = ", node
|
print "XXX visitAST() node = ", node
|
||||||
|
|
||||||
for n in node.declarations():
|
for n in node.declarations():
|
||||||
if isinstance(n, idlast.Module):
|
if isinstance(n, idlast.Module):
|
||||||
self.visitModule(n)
|
self.visitModule(n)
|
||||||
@ -103,22 +103,22 @@ class WiresharkVisitor:
|
|||||||
self.visitUnion(n)
|
self.visitUnion(n)
|
||||||
|
|
||||||
# Check for Typedef structs and unions
|
# Check for Typedef structs and unions
|
||||||
|
|
||||||
if isinstance(n, idlast.Typedef):
|
if isinstance(n, idlast.Typedef):
|
||||||
self.visitTypedef(n) # who are you ?
|
self.visitTypedef(n) # who are you ?
|
||||||
|
|
||||||
|
|
||||||
def visitModule(self, node):
|
def visitModule(self, node):
|
||||||
if self.DEBUG:
|
if self.DEBUG:
|
||||||
print "XXX visitModule() node = ", node
|
print "XXX visitModule() node = ", node
|
||||||
|
|
||||||
for n in node.definitions():
|
for n in node.definitions():
|
||||||
if isinstance(n, idlast.Module):
|
if isinstance(n, idlast.Module):
|
||||||
self.visitModule(n)
|
self.visitModule(n)
|
||||||
if isinstance(n, idlast.Interface):
|
if isinstance(n, idlast.Interface):
|
||||||
self.visitInterface(n)
|
self.visitInterface(n)
|
||||||
if isinstance(n, idlast.Operation):
|
if isinstance(n, idlast.Operation):
|
||||||
self.visitOperation(n)
|
self.visitOperation(n)
|
||||||
if isinstance(n, idlast.Attribute):
|
if isinstance(n, idlast.Attribute):
|
||||||
self.visitAttribute(n)
|
self.visitAttribute(n)
|
||||||
if isinstance(n, idlast.Enum):
|
if isinstance(n, idlast.Enum):
|
||||||
@ -129,38 +129,36 @@ class WiresharkVisitor:
|
|||||||
self.visitUnion(n)
|
self.visitUnion(n)
|
||||||
|
|
||||||
# Check for Typedef structs and unions
|
# Check for Typedef structs and unions
|
||||||
|
|
||||||
if isinstance(n, idlast.Typedef):
|
if isinstance(n, idlast.Typedef):
|
||||||
self.visitTypedef(n) # who are you ?
|
self.visitTypedef(n) # who are you ?
|
||||||
|
|
||||||
|
|
||||||
def visitInterface(self, node):
|
def visitInterface(self, node):
|
||||||
if self.DEBUG:
|
if self.DEBUG:
|
||||||
print "XXX visitInterface() node = ", node
|
print "XXX visitInterface() node = ", node
|
||||||
|
|
||||||
for c in node.callables():
|
for c in node.callables():
|
||||||
if isinstance(c, idlast.Operation):
|
if isinstance(c, idlast.Operation):
|
||||||
self.visitOperation(c)
|
self.visitOperation(c)
|
||||||
if isinstance(c, idlast.Attribute):
|
if isinstance(c, idlast.Attribute):
|
||||||
self.visitAttribute(c)
|
self.visitAttribute(c)
|
||||||
|
|
||||||
for d in node.contents():
|
for d in node.contents():
|
||||||
if isinstance(d, idlast.Enum):
|
if isinstance(d, idlast.Enum):
|
||||||
self.visitEnum(d)
|
self.visitEnum(d)
|
||||||
|
|
||||||
if isinstance(d, idlast.Struct):
|
if isinstance(d, idlast.Struct):
|
||||||
self.visitStruct(d)
|
self.visitStruct(d)
|
||||||
|
|
||||||
if isinstance(d, idlast.Union):
|
if isinstance(d, idlast.Union):
|
||||||
self.visitUnion(d)
|
self.visitUnion(d)
|
||||||
|
|
||||||
# Check for Typedef structs and unions
|
# Check for Typedef structs and unions
|
||||||
|
|
||||||
if isinstance(d, idlast.Typedef):
|
if isinstance(d, idlast.Typedef):
|
||||||
self.visitTypedef(d) # who are you ?
|
self.visitTypedef(d) # who are you ?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# visitOperation
|
# visitOperation
|
||||||
@ -168,7 +166,7 @@ class WiresharkVisitor:
|
|||||||
# populates the operations node list "oplist"
|
# populates the operations node list "oplist"
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
def visitOperation(self,opnode):
|
def visitOperation(self,opnode):
|
||||||
if not opnode in self.oplist:
|
if not opnode in self.oplist:
|
||||||
self.oplist.append(opnode) # store operation node
|
self.oplist.append(opnode) # store operation node
|
||||||
@ -179,7 +177,7 @@ class WiresharkVisitor:
|
|||||||
# populates the attribute node list "atlist"
|
# populates the attribute node list "atlist"
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
def visitAttribute(self,atnode):
|
def visitAttribute(self,atnode):
|
||||||
if not atnode in self.atlist:
|
if not atnode in self.atlist:
|
||||||
self.atlist.append(atnode) # store attribute node
|
self.atlist.append(atnode) # store attribute node
|
||||||
@ -191,7 +189,7 @@ class WiresharkVisitor:
|
|||||||
# populates the Enum node list "enlist"
|
# populates the Enum node list "enlist"
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
def visitEnum(self,enode):
|
def visitEnum(self,enode):
|
||||||
if not enode in self.enlist:
|
if not enode in self.enlist:
|
||||||
self.enlist.append(enode) # store enum node if unique
|
self.enlist.append(enode) # store enum node if unique
|
||||||
@ -203,12 +201,12 @@ class WiresharkVisitor:
|
|||||||
#
|
#
|
||||||
# eg: typdef enum colors {red, green, blue } mycolors;
|
# eg: typdef enum colors {red, green, blue } mycolors;
|
||||||
#
|
#
|
||||||
|
|
||||||
def visitTypedef(self,td):
|
def visitTypedef(self,td):
|
||||||
d = td.aliasType() # get Type, possibly Declared
|
d = td.aliasType() # get Type, possibly Declared
|
||||||
if isinstance(d,idltype.Declared):
|
if isinstance(d,idltype.Declared):
|
||||||
self.visitDeclared(d)
|
self.visitDeclared(d)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# visitDeclared
|
# visitDeclared
|
||||||
@ -216,13 +214,13 @@ class WiresharkVisitor:
|
|||||||
# Search to see if its a struct, union, or enum
|
# Search to see if its a struct, union, or enum
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
def visitDeclared(self,d):
|
def visitDeclared(self,d):
|
||||||
if isinstance(d,idltype.Declared):
|
if isinstance(d,idltype.Declared):
|
||||||
sue = d.decl() # grab the struct or union or enum
|
sue = d.decl() # grab the struct or union or enum
|
||||||
|
|
||||||
if isinstance(sue, idlast.Struct):
|
if isinstance(sue, idlast.Struct):
|
||||||
self.visitStruct(sue)
|
self.visitStruct(sue)
|
||||||
if isinstance(sue, idlast.Union):
|
if isinstance(sue, idlast.Union):
|
||||||
self.visitUnion(sue)
|
self.visitUnion(sue)
|
||||||
if isinstance(sue, idlast.Enum):
|
if isinstance(sue, idlast.Enum):
|
||||||
@ -238,9 +236,9 @@ class WiresharkVisitor:
|
|||||||
# and checks its members also
|
# and checks its members also
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
def visitStruct(self,stnode):
|
def visitStruct(self,stnode):
|
||||||
if not stnode in self.stlist:
|
if not stnode in self.stlist:
|
||||||
self.stlist.append(stnode) # store struct node if unique and avoid recursive loops
|
self.stlist.append(stnode) # store struct node if unique and avoid recursive loops
|
||||||
# if we come across recursive structs
|
# if we come across recursive structs
|
||||||
|
|
||||||
@ -250,7 +248,6 @@ class WiresharkVisitor:
|
|||||||
self.visitDeclared(mt) # if declared, then check it out
|
self.visitDeclared(mt) # if declared, then check it out
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# visitUnion
|
# visitUnion
|
||||||
#
|
#
|
||||||
@ -258,7 +255,7 @@ class WiresharkVisitor:
|
|||||||
# and checks its members also
|
# and checks its members also
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
def visitUnion(self,unnode):
|
def visitUnion(self,unnode):
|
||||||
if not unnode in self.unlist:
|
if not unnode in self.unlist:
|
||||||
self.unlist.append(unnode) # store union node if unique
|
self.unlist.append(unnode) # store union node if unique
|
||||||
@ -271,23 +268,21 @@ class WiresharkVisitor:
|
|||||||
ct = c.caseType()
|
ct = c.caseType()
|
||||||
if isinstance(ct,idltype.Declared):
|
if isinstance(ct,idltype.Declared):
|
||||||
self.visitDeclared(ct) # if declared, then check it out
|
self.visitDeclared(ct) # if declared, then check it out
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run(tree, args):
|
def run(tree, args):
|
||||||
|
|
||||||
st = output.Stream(sys.stdout, 4) # set indent for stream
|
st = output.Stream(sys.stdout, 4) # set indent for stream
|
||||||
ev = WiresharkVisitor(st) # create visitor object
|
ev = WiresharkVisitor(st) # create visitor object
|
||||||
|
|
||||||
ev.visitAST(tree) # go find some operations
|
ev.visitAST(tree) # go find some operations
|
||||||
|
|
||||||
#
|
#
|
||||||
# Grab name of main IDL file being compiled.
|
# Grab name of main IDL file being compiled.
|
||||||
#
|
#
|
||||||
# Assumption: Name is of the form abcdefg.xyz (eg: CosNaming.idl)
|
# Assumption: Name is of the form abcdefg.xyz (eg: CosNaming.idl)
|
||||||
#
|
#
|
||||||
|
|
||||||
fname = path.basename(tree.file()) # grab basename only, dont care about path
|
fname = path.basename(tree.file()) # grab basename only, dont care about path
|
||||||
nl = string.split(fname,".")[0] # split name of main IDL file using "." as separator
|
nl = string.split(fname,".")[0] # split name of main IDL file using "." as separator
|
||||||
# and grab first field (eg: CosNaming)
|
# and grab first field (eg: CosNaming)
|
||||||
@ -298,21 +293,28 @@ def run(tree, args):
|
|||||||
for i in ev.atlist:
|
for i in ev.atlist:
|
||||||
print "XXX - Attribute node ", i, " identifiers() = ", i.identifiers()
|
print "XXX - Attribute node ", i, " identifiers() = ", i.identifiers()
|
||||||
for i in ev.enlist:
|
for i in ev.enlist:
|
||||||
print "XXX - Enum node ", i, " repoId() = ", i.repoId()
|
print "XXX - Enum node ", i, " repoId() = ", i.repoId()
|
||||||
for i in ev.stlist:
|
for i in ev.stlist:
|
||||||
print "XXX - Struct node ", i, " repoId() = ", i.repoId()
|
print "XXX - Struct node ", i, " repoId() = ", i.repoId()
|
||||||
for i in ev.unlist:
|
for i in ev.unlist:
|
||||||
print "XXX - Union node ", i, " repoId() = ", i.repoId()
|
print "XXX - Union node ", i, " repoId() = ", i.repoId()
|
||||||
|
|
||||||
|
|
||||||
# create a C generator object
|
# create a C generator object
|
||||||
# and generate some C code
|
# and generate some C code
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
eg = wireshark_gen_C(ev.st, string.upper(nl), string.lower(nl), string.capitalize(nl) + " Dissector Using GIOP API")
|
eg = wireshark_gen_C(ev.st, string.upper(nl), string.lower(nl), string.capitalize(nl) + " Dissector Using GIOP API")
|
||||||
eg.genCode(ev.oplist, ev.atlist, ev.enlist, ev.stlist, ev.unlist) # pass them onto the C generator
|
eg.genCode(ev.oplist, ev.atlist, ev.enlist, ev.stlist, ev.unlist) # pass them onto the C generator
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Editor modelines - http://www.wireshark.org/tools/modelines.html
|
||||||
|
#
|
||||||
|
# Local variables:
|
||||||
|
# c-basic-offset: 4
|
||||||
|
# indent-tabs-mode: nil
|
||||||
|
# End:
|
||||||
|
#
|
||||||
|
# vi: set shiftwidth=4 expandtab:
|
||||||
|
# :indentSize=4:noTabs=true:
|
||||||
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user