]> SALOME platform Git repositories - modules/kernel.git/blob - src/ModuleGenerator/IDLparser.py
Salome HOME
Merge multi-study removal branch.
[modules/kernel.git] / src / ModuleGenerator / IDLparser.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  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, or (at your option) any later version.
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
24 #  File   : IDLparser.py
25 #  Module : SALOME
26
27 import string, sys, fpformat, re, os
28 import xml.sax
29 import pdb
30
31 from xml.sax.handler import *
32 from omniidl import idlast, idltype, idlvisitor, idlutil, output
33 from salome_utils import getUserName
34
35 # parameters not found in IDL file, user's specified in optional parameters
36 common_data={"AUTHOR"     : "",
37              "ICON"       : "",
38              "VERSION"    : "",
39              "COMP_TYPE"  : "",
40              "COMP_NAME"  : "",
41              "COMP_UNAME" : "",
42              "COMP_IMPL"  : ""
43              }
44
45 nb_components = 0
46
47 #--------------------------------------------------
48 # extract value of <param_name> from <args> list
49 # it's proposed that the matching <args> item
50 # looks like <param_name>=<value>, for example,
51 # catalog=/tmp/myxml.xml
52 #--------------------------------------------------
53 def getParamValue( param_name, default_value, args ):
54     pattern="^"+param_name+"="
55
56     res = default_value        #initial value
57     for opt in args:
58         s = re.compile(pattern).search(opt)
59         if s:
60             res = opt[s.end():]
61             break     #found
62
63     return res
64
65
66 #--------------------------------------------------
67 # print error message
68 #--------------------------------------------------
69 def error (message):
70     print "ERROR : ", message
71
72
73 #--------------------------------------------------
74 # base class implementing tree
75 #--------------------------------------------------
76 class Tree:
77
78     def __init__(self, name = '', content = '', key = None):
79         self.name = name
80         self.content = content
81         self.key = key
82         self.parent = None
83         self.childs = []
84         self.comments = []
85         self.attrs={}
86
87     def addChild(self, tree):
88         if tree is not None:
89             self.childs.append(tree)
90             tree.parent = self
91         return tree
92
93     def addNamedChild(self, name, content = ''):
94         return self.addChild(Tree(name, content))
95
96     def replaceChild(self, tree):
97          if tree is not None:
98             pos = 0
99             for i in self.childs:
100                 if (i.name == tree.name) & ((i.key is None) | (i.key == tree.key)):
101                     self.childs.pop(pos)
102                     self.childs.insert(pos, tree)
103                     return tree
104                 pos += 1
105
106          return self.addChild(tree)
107
108     def insertFirstChild(self, tree):
109         if tree is not None:
110             self.childs.insert(0, tree)
111         return tree
112
113     def insertFirstNamedChild(self, name, content = ''):
114         return self.insertFirstChild(Tree(name, content))
115
116     def output_xml(self, f, depth=0):
117         d = depth
118         if self.name != '':
119             s = string.ljust('', 4*depth)
120             s += '<' + self.name
121             for k,v in self.attrs.items():
122               s += ' ' + k + '="' + v + '"'
123             s += '>'
124             if self.content != '':
125                 s +=  self.content
126             else:
127                 if len(self.childs) > 0:
128                     s += '\n'
129             f.write(s)
130             d +=  1
131
132         for i in self.childs:
133             i.output_xml(f, d)
134
135         if self.name != '':
136             s = '</' + self.name + '>\n'
137             if len(self.childs) > 0 :
138                 s = string.ljust('', 4*depth) + s
139             f.write(s)
140
141     def Dump(self, levels=-1, depth=0):
142         #Dumps the tree contents
143
144         if levels == 0: return
145
146         s = string.ljust('', 4*depth)
147         print s, self, self.content
148         for i in self.childs:
149             i.Dump(levels-1, depth+1)
150
151     def parents(self):
152         #Returns list of the parents
153         l = []
154         p = self.parent
155         while p:
156             l.append(p)
157             l.append(p.name)
158             p = p.parent
159         return l
160
161     def getChild(self, name, content=None):
162         # return child node with a given name
163         # if content == None, don't compare contents
164         for i in self.childs:
165             if (i.name == name):
166                 if (content is None) | (i.content == content):
167                     return i
168         return None
169
170     def getNode(self, name, content='', depth=-1):
171         # recursive search of a node with a given name
172         # content == None, don't compare content
173         if (self.name == name):
174             if (content is None) | (self.content == content):
175                 return self
176
177         if (depth != 0):
178             for i in self.childs:
179                 n = i.getNode(name, content, depth-1)
180                 if n:  return n
181
182         return None
183
184     def __repr__(self):
185         s = '<'
186         if self.name != '':
187             s += self.name
188         else:
189             s +=  'None'
190         s += '>'
191         return s
192
193     def merge(self, t):
194         pass
195
196     def mergeChilds(self, t, list):
197         L_ext = t.getChild(list)
198         L_int = self.getChild(list)
199
200         L_merge = Tree(list)
201
202         for i_ext in L_ext.childs:
203             k_ext = i_ext.key
204             if k_ext is None:  continue
205             present = 0
206
207             for i_int in L_int.childs:
208                 k_int = i_int.key
209                 if k_int is None:  continue
210
211                 if (k_int == k_ext):
212                     present = 1
213                     break;
214
215             if present :
216                 i_int.merge(i_ext)
217                 L_merge.addChild(i_int)
218             else:
219                 L_merge.addChild(i_ext)
220
221         self.replaceChild(L_merge)
222
223     def setAttrib(self, name,value):
224       self.attrs[name]=value
225
226
227 #--------------------------------------------------
228 # implements parameter tree
229 #--------------------------------------------------
230 class parameter(Tree):
231
232     def __init__(self, name=None, mode = 'in', type='', comment='unknown'):
233         Tree.__init__(self, mode + 'Parameter', key=name)
234         self.mode = mode
235         if name is None:  return
236
237         self.addNamedChild(mode + 'Parameter-name', name)
238         self.addNamedChild(mode + 'Parameter-type', type)
239         self.addNamedChild(mode + 'Parameter-comment', comment)
240
241     def merge(self, P):
242
243         self.mode = P.mode
244         self.replaceChild(P.getChild(P.mode + 'Parameter-name'))
245         self.replaceChild(P.getChild(P.mode + 'Parameter-type'))
246         C = P.getChild(P.mode + 'Parameter-comment')
247         if C.content != 'unkonwn':
248             self.replaceChild(C)
249
250 #--------------------------------------------------
251 # implements dataStreamParameter tree
252 #--------------------------------------------------
253 class dataStreamParameter(parameter):
254
255     def __init__(self, name=None, mode='in', type='', dependency='', comment='unknown'):
256         parameter.__init__(self, name, mode, type, comment)
257         if name is None:  return
258
259         self.addNamedChild(mode + 'Parameter-dependency', dependency)
260         self.mode = mode
261
262     def merge(self, P):
263
264         parameter.merge(self, P)
265         self.replaceChild(P.getChild(mode + 'Parameter-dependency'))
266
267
268 def parseComment(comment):
269
270     spaces = '[\t\n ]*'
271     word = spaces + '([a-zA-Z][a-zA-Z0-9_]*)' + spaces
272
273     result = []
274     type = None
275     key = None
276
277     ## match :  // followed by a 'DataStreamPorts' string,
278     ## the service name, and a list of ports
279     pattern = '// *DataStreamPorts{,1}' + word
280     m = re.match(pattern, comment)
281
282     ## if there is a match, parse remaining part of comment
283     if m:
284         ## service
285         type = 'DataStreamPorts'
286         key = m.group(1)
287
288         sPorts = comment[m.end():]
289         pattern = word + '\('+word+','+word +','+word+'\)' \
290                   + spaces + ',{,1}' + spaces
291         while len(sPorts) > 0:
292             ## process next DataStreamPort
293             ## match a definition like xx(a,b,c) with a possible trailing ,
294             ## returns a tuple (xx, a, b, c) and
295             ## the remaining part of input string
296             m = re.match(pattern, sPorts)
297             if m is None:
298                 raise LookupError, \
299                       'format error in DataStreamPort definition : '+sPorts
300             sPorts = sPorts[m.end():]
301             result.append(m.groups())
302
303     return type, key, result;
304
305 #--------------------------------------------------
306 # implements service tree
307 #--------------------------------------------------
308 class Service(Tree):
309
310     def __init__(self, name=None, comment = 'unknown'):
311
312         Tree.__init__(self, 'component-service', key=name)
313         if name is None:  return
314
315         self.addNamedChild('service-name', name)
316         self.addNamedChild('service-author',common_data["AUTHOR"])
317         self.addNamedChild('service-version',common_data["VERSION"])
318         self.addNamedChild('service-comment', comment)
319         self.addNamedChild('service-by-default', "0")
320         self.addNamedChild('inParameter-list')
321         self.addNamedChild('outParameter-list')
322         self.addNamedChild('DataStream-list')
323
324     def createInParameter(self, name, type):
325         L = self.getChild('inParameter-list')
326         p = parameter(name, 'in', type)
327         L.replaceChild(p)
328         return p
329
330     def createOutParameter(self, name, type):
331         L = self.getChild('outParameter-list')
332         p = parameter(name, 'out', type)
333         L.replaceChild(p)
334         return p
335
336     def createDataStreamParameter(self, p):
337         L = self.getChild('DataStream-list')
338         p = dataStreamParameter(p[0], p[2], p[1], p[3])
339         L.replaceChild(p)
340         return p
341
342     def merge(self, S):
343
344         self.replaceChild(S.getChild('service-author'))
345         self.replaceChild(S.getChild('service-version'))
346         self.replaceChild(S.getChild('service-by-default'))
347         C = S.getChild('service-comment')
348         if C.content != 'unkonwn':
349             self.replaceChild(C)
350
351         for L in ['inParameter-list', 'outParameter-list', 'DataStream-list']:
352            self.mergeChilds(S, L)
353
354
355 #--------------------------------------------------
356 # implements interface tree
357 #--------------------------------------------------
358 class Interface(Tree):
359
360     def __init__(self, name=None, comment='unknown'):
361
362         Tree.__init__(self, key=name)
363
364         if name is None:  return
365
366         self.addNamedChild('component-interface-name', name)
367         self.addNamedChild('component-interface-comment', comment);
368         self.addNamedChild('component-service-list')
369
370     def createService(self, name):
371         L = self.getChild('component-service-list')
372
373         if L is None:
374             error ("Interface.createService() : 'component-service-list' is not found")
375             return None
376
377         s = Service(name)
378         L.addChild(s)
379         return s
380
381     def findService(self, key):
382         L = self.getChild('component-service-list')
383         for S in L.childs:
384             if S.key == key:
385                 return S
386         return None
387
388     def merge(self, I):
389
390         C = S.getChild('component-interface-comment')
391         if C.content != 'unkonwn':
392             self.replaceChild(C)
393
394         self.mergeChilds(I, 'component-service-list')
395
396     def processDataStreams(self):
397         for sComment in self.comments:
398
399             type, key, result = parseComment(sComment)
400
401             if type == 'DataStreamPorts':
402                 Service = self.findService(key)
403                 if Service is None:
404                     raise LookupError, \
405                           'service ' + key + \
406                           ' not found in interface : ' + self.key
407                 for p in result:
408                 ## process next DataStreamPort
409                     Service.createDataStreamParameter(p)
410
411
412 #--------------------------------------------------
413 # implements Component tree
414 #--------------------------------------------------
415 class Component(Tree):
416     def __init__(self, name=None):
417         Tree.__init__(self, 'component', key=name)
418         if name is None:  return
419
420 # ASV : fix for bug PAL8922 (Component name indicated by user in GUI is not taken into account
421         if common_data["COMP_NAME"] != '':
422             self.addNamedChild('component-name', common_data["COMP_NAME"])
423         else:
424             self.addNamedChild('component-name', name)
425
426 # ASV : if user name is NOT set, then use component-name instead.  Else - default.
427         if common_data["COMP_UNAME"] != '':
428             self.addNamedChild('component-username',   common_data["COMP_UNAME"])
429         else:
430             if common_data["COMP_NAME"] != '':
431                 self.addNamedChild('component-username', common_data["COMP_NAME"] )
432             else:
433                 self.addNamedChild('component-username',   name)
434
435         self.addNamedChild('component-type',       common_data["COMP_TYPE"])
436         self.addNamedChild('component-author',     common_data["AUTHOR"])
437         self.addNamedChild('component-version',    common_data["VERSION"])
438         self.addNamedChild('component-comment',    'unknown')
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-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",     getUserName(),     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_IMPL"]  = getParamValue("impltype",   "1",               args)
835
836     print common_data
837
838     remove_comp = getParamValue("remove", "", args)
839
840     #==================================================
841
842     if (os.path.exists(CatalogFileName)):
843         print "Importing", CatalogFileName
844         C = Catalog(CatalogFileName)
845     else:
846         print "Creating ",CatalogFileName
847         C = Catalog()
848
849     print "Reading idl file"
850
851     visitor = ModuleCatalogVisitor(C)
852     tree.accept(visitor)
853
854 ##    C.Dump()
855
856     if remove_comp :
857         C.removeComponent(remove_comp)
858
859     if (os.path.exists(CatalogFileName)):
860         print "Updating", CatalogFileName
861         CatalogFileName_old = CatalogFileName + '_old'
862         os.rename(CatalogFileName, CatalogFileName_old)
863     else:
864         CatalogFileName_old = ""
865         print "Writing", CatalogFileName
866
867     CatalogFileName_new = CatalogFileName + '_new'
868     f=open(CatalogFileName_new, 'w')
869     f.write("<?xml version='1.0' encoding='us-ascii' ?>\n\n")
870     C.output_xml(f)
871     f.close()
872
873     os.rename(CatalogFileName_new, CatalogFileName)
874     if ((CatalogFileName_old != "") & os.path.exists(CatalogFileName_old)):
875         os.unlink(CatalogFileName_old)
876
877     print
878
879
880 if __name__ == "__main__":
881     print
882     print "Usage : omniidl -bIDLparser [-I<catalog files directory>]* -Wbcatalog=<my_catalog.xml>[,icon=<pngfile>][,version=<num>][,author=<name>][,name=<component_name>][,username=<component_username>][,impltype=<implementation type : 0 (python), 1 (C++)>] <file.idl>"
883     print