]> SALOME platform Git repositories - modules/kernel.git/blob - src/ModuleGenerator/IDLparser.py
Salome HOME
clean warning message
[modules/kernel.git] / src / ModuleGenerator / IDLparser.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 #  This library is free software; you can redistribute it and/or
8 #  modify it under the terms of the GNU Lesser General Public
9 #  License as published by the Free Software Foundation; either
10 #  version 2.1 of the License.
11 #
12 #  This library is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #  Lesser General Public License for more details.
16 #
17 #  You should have received a copy of the GNU Lesser General Public
18 #  License along with this library; if not, write to the Free Software
19 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22
23 #  File   : IDLparser.py
24 #  Module : SALOME
25
26 import string, sys, fpformat, re, os
27 import xml.sax
28 import pdb
29
30 from xml.sax.handler import *
31 from omniidl import idlast, idltype, idlvisitor, idlutil, output
32
33 # parameters not found in IDL file, user's specified in optional parameters
34 common_data={"AUTHOR"     : "",
35              "ICON"       : "",
36              "VERSION"    : "",
37              "COMP_TYPE"  : "",
38              "COMP_NAME"  : "",
39              "COMP_UNAME" : "",
40              "COMP_MULT"  : "",
41              "COMP_IMPL"  : ""
42              }
43
44 nb_components = 0
45
46 #--------------------------------------------------
47 # extract value of <param_name> from <args> list
48 # it's proposed that the matching <args> item
49 # looks like <param_name>=<value>, for example,
50 # catalog=/tmp/myxml.xml
51 #--------------------------------------------------
52 def getParamValue( param_name, default_value, args ):
53     pattern="^"+param_name+"="
54
55     res = default_value        #initial value
56     for opt in args:
57         s = re.compile(pattern).search(opt)
58         if s:
59             res = opt[s.end():]
60             break     #found
61
62     return res
63
64
65 #--------------------------------------------------
66 # print error message
67 #--------------------------------------------------
68 def error (message):
69     print "ERROR : ", message
70
71
72 #--------------------------------------------------
73 # base class implementing tree
74 #--------------------------------------------------
75 class Tree:
76
77     def __init__(self, name = '', content = '', key = None):
78         self.name = name
79         self.content = content
80         self.key = key
81         self.parent = None
82         self.childs = []
83         self.comments = []
84         self.attrs={}
85
86     def addChild(self, tree):
87         if tree is not None:
88             self.childs.append(tree)
89             tree.parent = self
90         return tree
91
92     def addNamedChild(self, name, content = ''):
93         return self.addChild(Tree(name, content))
94
95     def replaceChild(self, tree):
96          if tree is not None:
97             pos = 0
98             for i in self.childs:
99                 if (i.name == tree.name) & ((i.key is None) | (i.key == tree.key)):
100                     self.childs.pop(pos)
101                     self.childs.insert(pos, tree)
102                     return tree
103                 pos += 1
104
105          return self.addChild(tree)
106
107     def insertFirstChild(self, tree):
108         if tree is not None:
109             self.childs.insert(0, tree)
110         return tree
111
112     def insertFirstNamedChild(self, name, content = ''):
113         return self.insertFirstChild(Tree(name, content))
114
115     def output_xml(self, f, depth=0):
116         d = depth
117         if self.name != '':
118             s = string.ljust('', 4*depth)
119             s += '<' + self.name
120             for k,v in self.attrs.items():
121               s += ' ' + k + '="' + v + '"'
122             s += '>'
123             if self.content != '':
124                 s +=  self.content
125             else:
126                 if len(self.childs) > 0:
127                     s += '\n'
128             f.write(s)
129             d +=  1
130
131         for i in self.childs:
132             i.output_xml(f, d)
133
134         if self.name != '':
135             s = '</' + self.name + '>\n'
136             if len(self.childs) > 0 :
137                 s = string.ljust('', 4*depth) + s
138             f.write(s)
139
140     def Dump(self, levels=-1, depth=0):
141         #Dumps the tree contents
142
143         if levels == 0: return
144
145         s = string.ljust('', 4*depth)
146         print s, self, self.content
147         for i in self.childs:
148             i.Dump(levels-1, depth+1)
149
150     def parents(self):
151         #Returns list of the parents
152         l = []
153         p = self.parent
154         while p:
155             l.append(p)
156             l.append(p.name)
157             p = p.parent
158         return l
159
160     def getChild(self, name, content=None):
161         # return child node with a given name
162         # if content == None, don't compare contents
163         for i in self.childs:
164             if (i.name == name):
165                 if (content is None) | (i.content == content):
166                     return i
167         return None
168
169     def getNode(self, name, content='', depth=-1):
170         # recursive search of a node with a given name
171         # content == None, don't compare content
172         if (self.name == name):
173             if (content is None) | (self.content == content):
174                 return self
175
176         if (depth != 0):
177             for i in self.childs:
178                 n = i.getNode(name, content, depth-1)
179                 if n:  return n
180
181         return None
182
183     def __repr__(self):
184         s = '<'
185         if self.name != '':
186             s += self.name
187         else:
188             s +=  'None'
189         s += '>'
190         return s
191
192     def merge(self, t):
193         pass
194
195     def mergeChilds(self, t, list):
196         L_ext = t.getChild(list)
197         L_int = self.getChild(list)
198
199         L_merge = Tree(list)
200
201         for i_ext in L_ext.childs:
202             k_ext = i_ext.key
203             if k_ext is None:  continue
204             present = 0
205
206             for i_int in L_int.childs:
207                 k_int = i_int.key
208                 if k_int is None:  continue
209
210                 if (k_int == k_ext):
211                     present = 1
212                     break;
213
214             if present :
215                 i_int.merge(i_ext)
216                 L_merge.addChild(i_int)
217             else:
218                 L_merge.addChild(i_ext)
219
220         self.replaceChild(L_merge)
221
222     def setAttrib(self, name,value):
223       self.attrs[name]=value
224
225
226 #--------------------------------------------------
227 # implements parameter tree
228 #--------------------------------------------------
229 class parameter(Tree):
230
231     def __init__(self, name=None, mode = 'in', type='', comment='unknown'):
232         Tree.__init__(self, mode + 'Parameter', key=name)
233         self.mode = mode
234         if name is None:  return
235
236         self.addNamedChild(mode + 'Parameter-name', name)
237         self.addNamedChild(mode + 'Parameter-type', type)
238         self.addNamedChild(mode + 'Parameter-comment', comment)
239
240     def merge(self, P):
241
242         self.mode = P.mode
243         self.replaceChild(P.getChild(P.mode + 'Parameter-name'))
244         self.replaceChild(P.getChild(P.mode + 'Parameter-type'))
245         C = P.getChild(P.mode + 'Parameter-comment')
246         if C.content != 'unkonwn':
247             self.replaceChild(C)
248
249 #--------------------------------------------------
250 # implements dataStreamParameter tree
251 #--------------------------------------------------
252 class dataStreamParameter(parameter):
253
254     def __init__(self, name=None, mode='in', type='', dependency='', comment='unknown'):
255         parameter.__init__(self, name, mode, type, comment)
256         if name is None:  return
257
258         self.addNamedChild(mode + 'Parameter-dependency', dependency)
259         self.mode = mode
260
261     def merge(self, P):
262
263         parameter.merge(self, P)
264         self.replaceChild(P.getChild(mode + 'Parameter-dependency'))
265
266
267 def parseComment(comment):
268
269     spaces = '[\t\n ]*'
270     word = spaces + '([a-zA-Z][a-zA-Z0-9_]*)' + spaces
271
272     result = []
273     type = None
274     key = None
275
276     ## match :  // followed by a 'DataStreamPorts' string,
277     ## the service name, and a list of ports
278     pattern = '// *DataStreamPorts{,1}' + word
279     m = re.match(pattern, comment)
280
281     ## if there is a match, parse remaining part of comment
282     if m:
283         ## service
284         type = 'DataStreamPorts'
285         key = m.group(1)
286
287         sPorts = comment[m.end():]
288         pattern = word + '\('+word+','+word +','+word+'\)' \
289                   + spaces + ',{,1}' + spaces
290         while len(sPorts) > 0:
291             ## process next DataStreamPort
292             ## match a definition like xx(a,b,c) with a possible trailing ,
293             ## returns a tuple (xx, a, b, c) and
294             ## the remaining part of input string
295             m = re.match(pattern, sPorts)
296             if m is None:
297                 raise LookupError, \
298                       'format error in DataStreamPort definition : '+sPorts
299             sPorts = sPorts[m.end():]
300             result.append(m.groups())
301
302     return type, key, result;
303
304 #--------------------------------------------------
305 # implements service tree
306 #--------------------------------------------------
307 class Service(Tree):
308
309     def __init__(self, name=None, comment = 'unknown'):
310
311         Tree.__init__(self, 'component-service', key=name)
312         if name is None:  return
313
314         self.addNamedChild('service-name', name)
315         self.addNamedChild('service-author',common_data["AUTHOR"])
316         self.addNamedChild('service-version',common_data["VERSION"])
317         self.addNamedChild('service-comment', comment)
318         self.addNamedChild('service-by-default', "0")
319         self.addNamedChild('inParameter-list')
320         self.addNamedChild('outParameter-list')
321         self.addNamedChild('DataStream-list')
322
323     def createInParameter(self, name, type):
324         L = self.getChild('inParameter-list')
325         p = parameter(name, 'in', type)
326         L.replaceChild(p)
327         return p
328
329     def createOutParameter(self, name, type):
330         L = self.getChild('outParameter-list')
331         p = parameter(name, 'out', type)
332         L.replaceChild(p)
333         return p
334
335     def createDataStreamParameter(self, p):
336         L = self.getChild('DataStream-list')
337         p = dataStreamParameter(p[0], p[2], p[1], p[3])
338         L.replaceChild(p)
339         return p
340
341     def merge(self, S):
342
343         self.replaceChild(S.getChild('service-author'))
344         self.replaceChild(S.getChild('service-version'))
345         self.replaceChild(S.getChild('service-by-default'))
346         C = S.getChild('service-comment')
347         if C.content != 'unkonwn':
348             self.replaceChild(C)
349
350         for L in ['inParameter-list', 'outParameter-list', 'DataStream-list']:
351            self.mergeChilds(S, L)
352
353
354 #--------------------------------------------------
355 # implements interface tree
356 #--------------------------------------------------
357 class Interface(Tree):
358
359     def __init__(self, name=None, comment='unknown'):
360
361         Tree.__init__(self, key=name)
362
363         if name is None:  return
364
365         self.addNamedChild('component-interface-name', name)
366         self.addNamedChild('component-interface-comment', comment);
367         self.addNamedChild('component-service-list')
368
369     def createService(self, name):
370         L = self.getChild('component-service-list')
371
372         if L is None:
373             error ("Interface.createService() : 'component-service-list' is not found")
374             return None
375
376         s = Service(name)
377         L.addChild(s)
378         return s
379
380     def findService(self, key):
381         L = self.getChild('component-service-list')
382         for S in L.childs:
383             if S.key == key:
384                 return S
385         return None
386
387     def merge(self, I):
388
389         C = S.getChild('component-interface-comment')
390         if C.content != 'unkonwn':
391             self.replaceChild(C)
392
393         self.mergeChilds(I, 'component-service-list')
394
395     def processDataStreams(self):
396         for sComment in self.comments:
397
398             type, key, result = parseComment(sComment)
399
400             if type == 'DataStreamPorts':
401                 Service = self.findService(key)
402                 if Service is None:
403                     raise LookupError, \
404                           'service ' + key + \
405                           ' not found in interface : ' + self.key
406                 for p in result:
407                 ## process next DataStreamPort
408                     Service.createDataStreamParameter(p)
409
410
411 #--------------------------------------------------
412 # implements Component tree
413 #--------------------------------------------------
414 class Component(Tree):
415     def __init__(self, name=None):
416         Tree.__init__(self, 'component', key=name)
417         if name is None:  return
418
419 # ASV : fix for bug PAL8922 (Component name indicated by user in GUI is not taken into account
420         if common_data["COMP_NAME"] != '':
421             self.addNamedChild('component-name', common_data["COMP_NAME"])
422         else:
423             self.addNamedChild('component-name', name)
424
425 # ASV : if user name is NOT set, then use component-name instead.  Else - default.
426         if common_data["COMP_UNAME"] != '':
427             self.addNamedChild('component-username',   common_data["COMP_UNAME"])
428         else:
429             if common_data["COMP_NAME"] != '':
430                 self.addNamedChild('component-username', common_data["COMP_NAME"] )
431             else:
432                 self.addNamedChild('component-username',   name)
433
434         self.addNamedChild('component-type',       common_data["COMP_TYPE"])
435         self.addNamedChild('component-author',     common_data["AUTHOR"])
436         self.addNamedChild('component-version',    common_data["VERSION"])
437         self.addNamedChild('component-comment',    'unknown')
438         self.addNamedChild('component-multistudy', common_data["COMP_MULT"])
439         self.addNamedChild('component-impltype',   common_data["COMP_IMPL"])
440         self.addNamedChild('component-icone',      common_data["ICON"])
441         self.addNamedChild('constraint')
442         self.addNamedChild('component-interface-list')
443
444     def createInterface(self, name):
445         L = self.getChild('component-interface-list')
446         if L is None:
447             error("createInterface: No component-interface-list is found")
448             return None
449         i = Interface(name)
450         L.addChild(i)
451         return i
452
453     def merge(self, C):
454
455         for i in ['component-username', 'component-author',
456                   'component-type', 'component-icone', 'component-version',
457                   'component-multistudy', 'component-impltype', 'constraint']:
458             ext = C.getChild(i)
459             int = self.getChild(i)
460             if int is None:
461                 int = ext
462             elif ext is not None and len(ext.content):
463                 int.content = ext.content
464
465         Cc = C.getChild('component-comment')
466         if Cc.content != 'unkonwn':
467             self.replaceChild(Cc)
468
469         self.mergeChilds(C, 'component-interface-list')
470
471 #--------------------------------------------------
472 # implements document tree
473 #--------------------------------------------------
474 class Catalog(ContentHandler, Tree):
475     def __init__(self, filename = None):
476         Tree.__init__(self)
477         self.buffer = ''
478         self.list = []
479         if (filename):
480             parser = xml.sax.make_parser()
481             parser.setContentHandler(self)
482             parser.parse(filename)
483         else:
484             t = self.addNamedChild('begin-catalog')
485             t.addNamedChild('type-list')
486             t.addNamedChild('component-list')
487
488         n = self.getChild('begin-catalog')
489         if n is None:
490             error("Catalog.__init__ : No 'begin-catalog' is found!")
491             return
492         if n.getChild('path-prefix-list') is None:
493             n.insertFirstNamedChild('path-prefix-list')
494         if n.getChild('type-list') is None:
495             p=n.childs.index(n.getChild('path-prefix-list'))
496             n.childs.insert(p+1,Tree('type-list'))
497         if n.getChild('component-list') is None:
498             n.addNamedChild('component-list')
499
500     def removeComponent(self, name):
501         complist = self.getNode('component-list')
502         idx = 0
503         if complist is None:
504             print "Catalog.removeComponent() : 'component-list' is not found"
505             return
506         for comp in complist.childs:
507             cname = comp.getChild('component-name')
508             if cname is not None:
509                 if cname.content == name:
510                     complist.childs.pop(idx)
511                     print "Component " + name + " is removed"
512             idx += 1
513
514     def startDocument(self):
515         self.list.append(self)
516
517     def startElement(self, name, attrs):
518         p = self.list[len(self.list)-1]
519         if name == 'component':
520             e = p.addChild(Component())
521         elif name == 'component-interface-name':
522             e = p.addNamedChild(name)
523         elif name == 'component-service':
524             e = p.addChild(Service())
525         elif name == 'inParameter':
526             e = p.addChild(parameter(mode='in'))
527         elif name == 'outParameter':
528             e = p.addChild(parameter(mode='out'))
529         elif name == 'sequence':
530             e = p.addChild(SeqType(attrs["name"],attrs["content"]))
531         elif name == 'objref':
532             e = p.addChild(ObjType(attrs["name"]))
533         elif name == 'struct':
534             e = p.addChild(StructType(attrs["name"]))
535         elif name == 'type':
536             e = p.addChild(Type(attrs["name"],attrs["kind"]))
537         elif name == 'member':
538             e = p.addChild(Member(attrs["name"],attrs["type"]))
539         else:
540             e = p.addNamedChild(name)
541         self.list.append(e)
542         self.buffer = ''
543
544     def endElement(self, name):
545         self.buffer = string.join(string.split(self.buffer), ' ')
546         p = self.list[len(self.list)-1]
547         p.content = self.buffer
548         if name == 'component':
549             p.key = p.getChild('component-name').content
550         self.buffer = ''
551         e = self.list.pop()
552
553     def characters(self, ch):
554         self.buffer += ch
555
556     def mergeComponent(self, comp):
557
558         L_int = self.getNode('component-list')
559         if   L_int is None:
560             error("Catalog.mergeComponent : 'component-list' is not found")
561             return
562
563         i_ext = comp
564         present = 0
565         n_ext = i_ext.key
566         for i_int in L_int.childs:
567             if (i_int.key == n_ext):
568                 present = 1
569                 break;
570
571         if present == 0:
572             print '   add component', i_ext.getChild('component-name').content
573             L_int.addChild(i_ext)
574         else:
575             print '   replace component', i_ext.getChild('component-name').content
576             i_int.merge(i_ext)
577
578     def mergeType(self, type):
579       L_int = self.getNode('type-list')
580       if L_int is None:
581         error("Catalog.mergeType : 'type-list' is not found")
582         return
583       for t in L_int.childs:
584         if t.attrs["name"] == type.attrs["name"]:
585           t.merge(type)
586           return
587
588       L_int.addChild(type)
589
590 class Member(Tree):
591   def __init__(self, name,type):
592     Tree.__init__(self, 'member')
593     self.setAttrib("name",name)
594     self.setAttrib("type",type)
595
596 class Type(Tree):
597   def __init__(self, name,kind):
598     Tree.__init__(self, 'type')
599     self.setAttrib("name",name)
600     self.setAttrib("kind",kind)
601
602   def merge(self,t):
603     self.setAttrib("kind",t.attrs["kind"])
604
605 class SeqType(Tree):
606   def __init__(self, name,content):
607     Tree.__init__(self, 'sequence')
608     self.setAttrib("name",name)
609     self.setAttrib("content",content)
610
611   def merge(self,t):
612     self.setAttrib("content",t.attrs["content"])
613
614 class StructType(Tree):
615   def __init__(self, name):
616     Tree.__init__(self, 'struct')
617     self.setAttrib("name",name)
618
619   def merge(self,t):
620     #remove childs and replace by t childs
621     self.childs=[]
622     for c in t.childs:
623       self.childs.append(c)
624
625 class ObjType(Tree):
626   def __init__(self, name):
627     Tree.__init__(self, 'objref')
628     self.setAttrib("name",name)
629
630   def merge(self,t):
631     RepoId=t.attrs.get("id")
632     if RepoId:
633       self.setAttrib("id",RepoId)
634     #remove childs and replace by t childs
635     self.childs=[]
636     for c in t.childs:
637       self.childs.append(c)
638
639 # IDL file reader
640
641 ttsMap = {
642     idltype.tk_void:       "void",
643     idltype.tk_short:      "short",
644     idltype.tk_long:       "long",
645     idltype.tk_ushort:     "unsigned short",
646     idltype.tk_ulong:      "unsigned long",
647     idltype.tk_float:      "float",
648     idltype.tk_double:     "double",
649     idltype.tk_boolean:    "boolean",
650     idltype.tk_char:       "char",
651     idltype.tk_octet:      "octet",
652     idltype.tk_any:        "any",
653     idltype.tk_TypeCode:   "CORBA::TypeCode",
654     idltype.tk_Principal:  "CORBA::Principal",
655     idltype.tk_longlong:   "long long",
656     idltype.tk_ulonglong:  "unsigned long long",
657     idltype.tk_longdouble: "long double",
658     idltype.tk_wchar:      "wchar"
659     }
660
661
662 #--------------------------------------------------
663 # class ModuleCatalogVisitor
664 #--------------------------------------------------
665 class ModuleCatalogVisitor (idlvisitor.AstVisitor):
666
667     def __init__(self, catalog):
668         self.catalog = catalog
669         self.EngineType = 0
670         self.currentScope=None
671
672     def visitAST(self, node):
673         for n in node.declarations():
674             if n.mainFile():
675               n.accept(self)
676
677     def visitModule(self, node):
678         self.currentScope=node
679         for n in node.definitions():
680             n.accept(self)
681
682     def visitInterface(self, node):
683         if node.mainFile():
684
685             self.EngineType = 0
686
687             for i in node.inherits():
688                 s = i.scopedName();
689                 if s[0] == "Engines":
690                   if s[1] == "EngineComponent":
691                     self.EngineType = 1; break
692                   if s[1] == "Superv_Component":
693                     self.EngineType = 2; break
694
695             if self.EngineType:
696               #This interface is a SALOME component
697               Comp = Component(node.identifier())
698
699               self.currentInterface = Comp.createInterface(node.identifier())
700
701               for c in node.callables():
702                 if isinstance(c, idlast.Operation):
703                     c.accept(self)
704
705               for c in node.declarations():
706                 if isinstance(c, idlast.Struct):
707                     c.accept(self)
708
709               for i in node.comments():
710                 self.currentInterface.comments.append(str(i))
711
712               if self.EngineType == 2:
713                 self.currentInterface.processDataStreams()
714
715               global nb_components
716               nb_components = nb_components + 1
717               self.catalog.mergeComponent(Comp)
718
719             else:
720               #This interface is not a component : use it as a DataType
721               t=ObjType("/".join(node.scopedName()))
722               for i in node.inherits():
723                 t.addNamedChild("base","/".join(i.scopedName()))
724               self.catalog.mergeType(t)
725
726             self.EngineType = 0
727
728
729     def visitOperation(self, node):
730
731         self.currentService = self.currentInterface.createService \
732                                        (node.identifier())
733
734         node.returnType().accept(self)
735         if (self.currentType != "void"):
736             self.currentService.createOutParameter \
737                 ("return", self.currentType)
738
739         for c in node.parameters():
740             c.accept(self)
741
742         for i in node.comments():
743             self.currentInterface.comments.append(str(i))
744
745
746     def visitDeclaredType(self, type):
747         name=type.name()
748         scoped_name="/".join(type.scopedName())
749         self.currentType = scoped_name
750
751     def visitBaseType(self, type):
752         self.currentType = ttsMap[type.kind()]
753
754     def visitStringType(self, type):
755         self.currentType = "string"
756
757     def visitParameter(self, node):
758         node.paramType().accept(self)
759         if node.is_in():
760             self.currentService.createInParameter \
761                      (node.identifier(), self.currentType)
762         if node.is_out():
763             self.currentService.createOutParameter \
764                      (node.identifier(), self.currentType)
765
766     def visitSequenceType(self,type):
767       type.seqType().accept(self)
768       if type.bound() == 0:
769           self.contentType=self.currentType
770           self.currentType = "sequence"
771       else:
772           self.currentType = None
773
774     def visitTypedef(self, node):
775       if node.constrType():
776             node.aliasType().decl().accept(self)
777
778       node.aliasType().accept(self)
779       type  = self.currentType
780       if not type:
781         return
782       decll = []
783       for d in node.declarators():
784             d.accept(self)
785             if self.__result_declarator:
786               decll.append(self.__result_declarator)
787       if type == "sequence":
788         #it's a sequence type
789         for name in decll:
790           scoped_name="/".join(self.currentScope.scopedName()+[name])
791           self.catalog.mergeType(SeqType(scoped_name,self.contentType))
792       #else:
793         #it's an alias
794       #  for name in decll:
795       #    scoped_name="/".join(self.currentScope.scopedName()+[name])
796       #    self.catalog.mergeType(Type(scoped_name,type))
797
798     def visitStruct(self, node):
799       t=StructType("/".join(node.scopedName()))
800       for m in node.members():
801             if m.constrType():
802                 m.memberType().decl().accept(self)
803
804             m.memberType().accept(self)
805             type = self.currentType
806             for d in m.declarators():
807                 d.accept(self)
808                 t.addChild(Member(self.__result_declarator,type))
809
810       self.catalog.mergeType(t)
811
812     def visitDeclarator(self, node):
813         if node.sizes():
814           self.__result_declarator =None
815         else:
816           self.__result_declarator =node.identifier()
817
818 #--------------------------------------------------
819 # parse idl and store xml file
820 #--------------------------------------------------
821 def run(tree, args):
822
823     CatalogFileName=getParamValue("catalog", "CatalogModulePersonnel.xml", args)
824     if re.compile(".*?.xml$").match(CatalogFileName, 1) is None:
825         CatalogFileName = CatalogFileName + '.xml'
826
827     #=========  Read parameters  ======================
828     common_data["ICON"]       = getParamValue("icon",       "",                args)
829     common_data["AUTHOR"]     = getParamValue("author",     os.getenv("USER"), args)
830     common_data["VERSION"]    = getParamValue("version",    "1",               args)
831     common_data["COMP_NAME"]  = getParamValue("name",       "",                args)
832     common_data["COMP_UNAME"] = getParamValue("username",   "",                args)
833     common_data["COMP_TYPE"]  = getParamValue("type",       "OTHER",           args)
834     common_data["COMP_MULT"]  = getParamValue("multistudy", "1",               args)
835     common_data["COMP_IMPL"]  = getParamValue("impltype",   "1",               args)
836
837     print common_data
838
839     remove_comp = getParamValue("remove", "", args)
840
841     #==================================================
842
843     if (os.path.exists(CatalogFileName)):
844         print "Importing", CatalogFileName
845         C = Catalog(CatalogFileName)
846     else:
847         print "Creating ",CatalogFileName
848         C = Catalog()
849
850     print "Reading idl file"
851
852     visitor = ModuleCatalogVisitor(C)
853     tree.accept(visitor)
854
855 ##    C.Dump()
856
857     if remove_comp :
858         C.removeComponent(remove_comp)
859
860     if (os.path.exists(CatalogFileName)):
861         print "Updating", CatalogFileName
862         CatalogFileName_old = CatalogFileName + '_old'
863         os.rename(CatalogFileName, CatalogFileName_old)
864     else:
865         CatalogFileName_old = ""
866         print "Writing", CatalogFileName
867
868     CatalogFileName_new = CatalogFileName + '_new'
869     f=open(CatalogFileName_new, 'w')
870     f.write("<?xml version='1.0' encoding='us-ascii' ?>\n\n")
871     C.output_xml(f)
872     f.close()
873
874     os.rename(CatalogFileName_new, CatalogFileName)
875     if ((CatalogFileName_old != "") & os.path.exists(CatalogFileName_old)):
876         os.unlink(CatalogFileName_old)
877
878     print
879
880
881 if __name__ == "__main__":
882     print
883     print "Usage : omniidl -bIDLparser [-I<catalog files directory>]* -Wbcatalog=<my_catalog.xml>[,icon=<pngfile>][,version=<num>][,author=<name>][,name=<component_name>][,username=<component_username>][,multistudy=<component_multistudy>][,impltype=<implementation type : 0 (python), 1 (C++)>] <file.idl>"
884     print