Salome HOME
Merge V9_dev branch into master
[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 list(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('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('service ' + key + \
404                           ' not found in interface : ' + self.key)
405                 for p in result:
406                 ## process next DataStreamPort
407                     Service.createDataStreamParameter(p)
408
409
410 #--------------------------------------------------
411 # implements Component tree
412 #--------------------------------------------------
413 class Component(Tree):
414     def __init__(self, name=None):
415         Tree.__init__(self, 'component', key=name)
416         if name is None:  return
417
418 # ASV : fix for bug PAL8922 (Component name indicated by user in GUI is not taken into account
419         if common_data["COMP_NAME"] != '':
420             self.addNamedChild('component-name', common_data["COMP_NAME"])
421         else:
422             self.addNamedChild('component-name', name)
423
424 # ASV : if user name is NOT set, then use component-name instead.  Else - default.
425         if common_data["COMP_UNAME"] != '':
426             self.addNamedChild('component-username',   common_data["COMP_UNAME"])
427         else:
428             if common_data["COMP_NAME"] != '':
429                 self.addNamedChild('component-username', common_data["COMP_NAME"] )
430             else:
431                 self.addNamedChild('component-username',   name)
432
433         self.addNamedChild('component-type',       common_data["COMP_TYPE"])
434         self.addNamedChild('component-author',     common_data["AUTHOR"])
435         self.addNamedChild('component-version',    common_data["VERSION"])
436         self.addNamedChild('component-comment',    'unknown')
437         self.addNamedChild('component-impltype',   common_data["COMP_IMPL"])
438         self.addNamedChild('component-icone',      common_data["ICON"])
439         self.addNamedChild('constraint')
440         self.addNamedChild('component-interface-list')
441
442     def createInterface(self, name):
443         L = self.getChild('component-interface-list')
444         if L is None:
445             error("createInterface: No component-interface-list is found")
446             return None
447         i = Interface(name)
448         L.addChild(i)
449         return i
450
451     def merge(self, C):
452
453         for i in ['component-username', 'component-author',
454                   'component-type', 'component-icone', 'component-version',
455                   'component-impltype', 'constraint']:
456             ext = C.getChild(i)
457             int = self.getChild(i)
458             if int is None:
459                 int = ext
460             elif ext is not None and len(ext.content):
461                 int.content = ext.content
462
463         Cc = C.getChild('component-comment')
464         if Cc.content != 'unkonwn':
465             self.replaceChild(Cc)
466
467         self.mergeChilds(C, 'component-interface-list')
468
469 #--------------------------------------------------
470 # implements document tree
471 #--------------------------------------------------
472 class Catalog(ContentHandler, Tree):
473     def __init__(self, filename = None):
474         Tree.__init__(self)
475         self.buffer = ''
476         self.list = []
477         if (filename):
478             parser = xml.sax.make_parser()
479             parser.setContentHandler(self)
480             parser.parse(filename)
481         else:
482             t = self.addNamedChild('begin-catalog')
483             t.addNamedChild('type-list')
484             t.addNamedChild('component-list')
485
486         n = self.getChild('begin-catalog')
487         if n is None:
488             error("Catalog.__init__ : No 'begin-catalog' is found!")
489             return
490         if n.getChild('path-prefix-list') is None:
491             n.insertFirstNamedChild('path-prefix-list')
492         if n.getChild('type-list') is None:
493             p=n.childs.index(n.getChild('path-prefix-list'))
494             n.childs.insert(p+1,Tree('type-list'))
495         if n.getChild('component-list') is None:
496             n.addNamedChild('component-list')
497
498     def removeComponent(self, name):
499         complist = self.getNode('component-list')
500         idx = 0
501         if complist is None:
502             print("Catalog.removeComponent() : 'component-list' is not found")
503             return
504         for comp in complist.childs:
505             cname = comp.getChild('component-name')
506             if cname is not None:
507                 if cname.content == name:
508                     complist.childs.pop(idx)
509                     print("Component " + name + " is removed")
510             idx += 1
511
512     def startDocument(self):
513         self.list.append(self)
514
515     def startElement(self, name, attrs):
516         p = self.list[len(self.list)-1]
517         if name == 'component':
518             e = p.addChild(Component())
519         elif name == 'component-interface-name':
520             e = p.addNamedChild(name)
521         elif name == 'component-service':
522             e = p.addChild(Service())
523         elif name == 'inParameter':
524             e = p.addChild(parameter(mode='in'))
525         elif name == 'outParameter':
526             e = p.addChild(parameter(mode='out'))
527         elif name == 'sequence':
528             e = p.addChild(SeqType(attrs["name"],attrs["content"]))
529         elif name == 'objref':
530             e = p.addChild(ObjType(attrs["name"]))
531         elif name == 'struct':
532             e = p.addChild(StructType(attrs["name"]))
533         elif name == 'type':
534             e = p.addChild(Type(attrs["name"],attrs["kind"]))
535         elif name == 'member':
536             e = p.addChild(Member(attrs["name"],attrs["type"]))
537         else:
538             e = p.addNamedChild(name)
539         self.list.append(e)
540         self.buffer = ''
541
542     def endElement(self, name):
543         self.buffer = string.join(string.split(self.buffer), ' ')
544         p = self.list[len(self.list)-1]
545         p.content = self.buffer
546         if name == 'component':
547             p.key = p.getChild('component-name').content
548         self.buffer = ''
549         e = self.list.pop()
550
551     def characters(self, ch):
552         self.buffer += ch
553
554     def mergeComponent(self, comp):
555
556         L_int = self.getNode('component-list')
557         if   L_int is None:
558             error("Catalog.mergeComponent : 'component-list' is not found")
559             return
560
561         i_ext = comp
562         present = 0
563         n_ext = i_ext.key
564         for i_int in L_int.childs:
565             if (i_int.key == n_ext):
566                 present = 1
567                 break;
568
569         if present == 0:
570             print('   add component', i_ext.getChild('component-name').content)
571             L_int.addChild(i_ext)
572         else:
573             print('   replace component', i_ext.getChild('component-name').content)
574             i_int.merge(i_ext)
575
576     def mergeType(self, type):
577       L_int = self.getNode('type-list')
578       if L_int is None:
579         error("Catalog.mergeType : 'type-list' is not found")
580         return
581       for t in L_int.childs:
582         if t.attrs["name"] == type.attrs["name"]:
583           t.merge(type)
584           return
585
586       L_int.addChild(type)
587
588 class Member(Tree):
589   def __init__(self, name,type):
590     Tree.__init__(self, 'member')
591     self.setAttrib("name",name)
592     self.setAttrib("type",type)
593
594 class Type(Tree):
595   def __init__(self, name,kind):
596     Tree.__init__(self, 'type')
597     self.setAttrib("name",name)
598     self.setAttrib("kind",kind)
599
600   def merge(self,t):
601     self.setAttrib("kind",t.attrs["kind"])
602
603 class SeqType(Tree):
604   def __init__(self, name,content):
605     Tree.__init__(self, 'sequence')
606     self.setAttrib("name",name)
607     self.setAttrib("content",content)
608
609   def merge(self,t):
610     self.setAttrib("content",t.attrs["content"])
611
612 class StructType(Tree):
613   def __init__(self, name):
614     Tree.__init__(self, 'struct')
615     self.setAttrib("name",name)
616
617   def merge(self,t):
618     #remove childs and replace by t childs
619     self.childs=[]
620     for c in t.childs:
621       self.childs.append(c)
622
623 class ObjType(Tree):
624   def __init__(self, name):
625     Tree.__init__(self, 'objref')
626     self.setAttrib("name",name)
627
628   def merge(self,t):
629     RepoId=t.attrs.get("id")
630     if RepoId:
631       self.setAttrib("id",RepoId)
632     #remove childs and replace by t childs
633     self.childs=[]
634     for c in t.childs:
635       self.childs.append(c)
636
637 # IDL file reader
638
639 ttsMap = {
640     idltype.tk_void:       "void",
641     idltype.tk_short:      "short",
642     idltype.tk_long:       "long",
643     idltype.tk_ushort:     "unsigned short",
644     idltype.tk_ulong:      "unsigned long",
645     idltype.tk_float:      "float",
646     idltype.tk_double:     "double",
647     idltype.tk_boolean:    "boolean",
648     idltype.tk_char:       "char",
649     idltype.tk_octet:      "octet",
650     idltype.tk_any:        "any",
651     idltype.tk_TypeCode:   "CORBA::TypeCode",
652     idltype.tk_Principal:  "CORBA::Principal",
653     idltype.tk_longlong:   "long long",
654     idltype.tk_ulonglong:  "unsigned long long",
655     idltype.tk_longdouble: "long double",
656     idltype.tk_wchar:      "wchar"
657     }
658
659
660 #--------------------------------------------------
661 # class ModuleCatalogVisitor
662 #--------------------------------------------------
663 class ModuleCatalogVisitor (idlvisitor.AstVisitor):
664
665     def __init__(self, catalog):
666         self.catalog = catalog
667         self.EngineType = 0
668         self.currentScope=None
669
670     def visitAST(self, node):
671         for n in node.declarations():
672             if n.mainFile():
673               n.accept(self)
674
675     def visitModule(self, node):
676         self.currentScope=node
677         for n in node.definitions():
678             n.accept(self)
679
680     def visitInterface(self, node):
681         if node.mainFile():
682
683             self.EngineType = 0
684
685             for i in node.inherits():
686                 s = i.scopedName();
687                 if s[0] == "Engines":
688                   if s[1] == "EngineComponent":
689                     self.EngineType = 1; break
690                   if s[1] == "Superv_Component":
691                     self.EngineType = 2; break
692
693             if self.EngineType:
694               #This interface is a SALOME component
695               Comp = Component(node.identifier())
696
697               self.currentInterface = Comp.createInterface(node.identifier())
698
699               for c in node.callables():
700                 if isinstance(c, idlast.Operation):
701                     c.accept(self)
702
703               for c in node.declarations():
704                 if isinstance(c, idlast.Struct):
705                     c.accept(self)
706
707               for i in node.comments():
708                 self.currentInterface.comments.append(str(i))
709
710               if self.EngineType == 2:
711                 self.currentInterface.processDataStreams()
712
713               global nb_components
714               nb_components = nb_components + 1
715               self.catalog.mergeComponent(Comp)
716
717             else:
718               #This interface is not a component : use it as a DataType
719               t=ObjType("/".join(node.scopedName()))
720               for i in node.inherits():
721                 t.addNamedChild("base","/".join(i.scopedName()))
722               self.catalog.mergeType(t)
723
724             self.EngineType = 0
725
726
727     def visitOperation(self, node):
728
729         self.currentService = self.currentInterface.createService \
730                                        (node.identifier())
731
732         node.returnType().accept(self)
733         if (self.currentType != "void"):
734             self.currentService.createOutParameter \
735                 ("return", self.currentType)
736
737         for c in node.parameters():
738             c.accept(self)
739
740         for i in node.comments():
741             self.currentInterface.comments.append(str(i))
742
743
744     def visitDeclaredType(self, type):
745         name=type.name()
746         scoped_name="/".join(type.scopedName())
747         self.currentType = scoped_name
748
749     def visitBaseType(self, type):
750         self.currentType = ttsMap[type.kind()]
751
752     def visitStringType(self, type):
753         self.currentType = "string"
754
755     def visitParameter(self, node):
756         node.paramType().accept(self)
757         if node.is_in():
758             self.currentService.createInParameter \
759                      (node.identifier(), self.currentType)
760         if node.is_out():
761             self.currentService.createOutParameter \
762                      (node.identifier(), self.currentType)
763
764     def visitSequenceType(self,type):
765       type.seqType().accept(self)
766       if type.bound() == 0:
767           self.contentType=self.currentType
768           self.currentType = "sequence"
769       else:
770           self.currentType = None
771
772     def visitTypedef(self, node):
773       if node.constrType():
774             node.aliasType().decl().accept(self)
775
776       node.aliasType().accept(self)
777       type  = self.currentType
778       if not type:
779         return
780       decll = []
781       for d in node.declarators():
782             d.accept(self)
783             if self.__result_declarator:
784               decll.append(self.__result_declarator)
785       if type == "sequence":
786         #it's a sequence type
787         for name in decll:
788           scoped_name="/".join(self.currentScope.scopedName()+[name])
789           self.catalog.mergeType(SeqType(scoped_name,self.contentType))
790       #else:
791         #it's an alias
792       #  for name in decll:
793       #    scoped_name="/".join(self.currentScope.scopedName()+[name])
794       #    self.catalog.mergeType(Type(scoped_name,type))
795
796     def visitStruct(self, node):
797       t=StructType("/".join(node.scopedName()))
798       for m in node.members():
799             if m.constrType():
800                 m.memberType().decl().accept(self)
801
802             m.memberType().accept(self)
803             type = self.currentType
804             for d in m.declarators():
805                 d.accept(self)
806                 t.addChild(Member(self.__result_declarator,type))
807
808       self.catalog.mergeType(t)
809
810     def visitDeclarator(self, node):
811         if node.sizes():
812           self.__result_declarator =None
813         else:
814           self.__result_declarator =node.identifier()
815
816 #--------------------------------------------------
817 # parse idl and store xml file
818 #--------------------------------------------------
819 def run(tree, args):
820
821     CatalogFileName=getParamValue("catalog", "CatalogModulePersonnel.xml", args)
822     if re.compile(".*?.xml$").match(CatalogFileName, 1) is None:
823         CatalogFileName = CatalogFileName + '.xml'
824
825     #=========  Read parameters  ======================
826     common_data["ICON"]       = getParamValue("icon",       "",                args)
827     common_data["AUTHOR"]     = getParamValue("author",     getUserName(),     args)
828     common_data["VERSION"]    = getParamValue("version",    "1",               args)
829     common_data["COMP_NAME"]  = getParamValue("name",       "",                args)
830     common_data["COMP_UNAME"] = getParamValue("username",   "",                args)
831     common_data["COMP_TYPE"]  = getParamValue("type",       "OTHER",           args)
832     common_data["COMP_IMPL"]  = getParamValue("impltype",   "1",               args)
833
834     print(common_data)
835
836     remove_comp = getParamValue("remove", "", args)
837
838     #==================================================
839
840     if (os.path.exists(CatalogFileName)):
841         print("Importing", CatalogFileName)
842         C = Catalog(CatalogFileName)
843     else:
844         print("Creating ",CatalogFileName)
845         C = Catalog()
846
847     print("Reading idl file")
848
849     visitor = ModuleCatalogVisitor(C)
850     tree.accept(visitor)
851
852 ##    C.Dump()
853
854     if remove_comp :
855         C.removeComponent(remove_comp)
856
857     if (os.path.exists(CatalogFileName)):
858         print("Updating", CatalogFileName)
859         CatalogFileName_old = CatalogFileName + '_old'
860         os.rename(CatalogFileName, CatalogFileName_old)
861     else:
862         CatalogFileName_old = ""
863         print("Writing", CatalogFileName)
864
865     CatalogFileName_new = CatalogFileName + '_new'
866     f=open(CatalogFileName_new, 'w')
867     f.write("<?xml version='1.0' encoding='us-ascii' ?>\n\n")
868     C.output_xml(f)
869     f.close()
870
871     os.rename(CatalogFileName_new, CatalogFileName)
872     if ((CatalogFileName_old != "") & os.path.exists(CatalogFileName_old)):
873         os.unlink(CatalogFileName_old)
874
875     print()
876
877
878 if __name__ == "__main__":
879     print()
880     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>")
881     print()