Back to index

salome-kernel  6.5.0
IDLparser.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 #  File   : IDLparser.py
00025 #  Module : SALOME
00026 
00027 import string, sys, fpformat, re, os
00028 import xml.sax
00029 import pdb
00030 
00031 from xml.sax.handler import *
00032 from omniidl import idlast, idltype, idlvisitor, idlutil, output
00033 
00034 # parameters not found in IDL file, user's specified in optional parameters
00035 common_data={"AUTHOR"     : "",
00036              "ICON"       : "",
00037              "VERSION"    : "",
00038              "COMP_TYPE"  : "",
00039              "COMP_NAME"  : "",
00040              "COMP_UNAME" : "",
00041              "COMP_MULT"  : "",
00042              "COMP_IMPL"  : ""
00043              }
00044 
00045 nb_components = 0
00046 
00047 #--------------------------------------------------
00048 # extract value of <param_name> from <args> list
00049 # it's proposed that the matching <args> item
00050 # looks like <param_name>=<value>, for example,
00051 # catalog=/tmp/myxml.xml
00052 #--------------------------------------------------
00053 def getParamValue( param_name, default_value, args ):
00054     pattern="^"+param_name+"="
00055 
00056     res = default_value        #initial value
00057     for opt in args:
00058         s = re.compile(pattern).search(opt)
00059         if s:
00060             res = opt[s.end():]
00061             break     #found
00062 
00063     return res
00064 
00065 
00066 #--------------------------------------------------
00067 # print error message
00068 #--------------------------------------------------
00069 def error (message):
00070     print "ERROR : ", message
00071 
00072 
00073 #--------------------------------------------------
00074 # base class implementing tree
00075 #--------------------------------------------------
00076 class Tree:
00077 
00078     def __init__(self, name = '', content = '', key = None):
00079         self.name = name
00080         self.content = content
00081         self.key = key
00082         self.parent = None
00083         self.childs = []
00084         self.comments = []
00085         self.attrs={}
00086 
00087     def addChild(self, tree):
00088         if tree is not None:
00089             self.childs.append(tree)
00090             tree.parent = self
00091         return tree
00092 
00093     def addNamedChild(self, name, content = ''):
00094         return self.addChild(Tree(name, content))
00095 
00096     def replaceChild(self, tree):
00097          if tree is not None:
00098             pos = 0
00099             for i in self.childs:
00100                 if (i.name == tree.name) & ((i.key is None) | (i.key == tree.key)):
00101                     self.childs.pop(pos)
00102                     self.childs.insert(pos, tree)
00103                     return tree
00104                 pos += 1
00105 
00106          return self.addChild(tree)
00107 
00108     def insertFirstChild(self, tree):
00109         if tree is not None:
00110             self.childs.insert(0, tree)
00111         return tree
00112 
00113     def insertFirstNamedChild(self, name, content = ''):
00114         return self.insertFirstChild(Tree(name, content))
00115 
00116     def output_xml(self, f, depth=0):
00117         d = depth
00118         if self.name != '':
00119             s = string.ljust('', 4*depth)
00120             s += '<' + self.name
00121             for k,v in self.attrs.items():
00122               s += ' ' + k + '="' + v + '"'
00123             s += '>'
00124             if self.content != '':
00125                 s +=  self.content
00126             else:
00127                 if len(self.childs) > 0:
00128                     s += '\n'
00129             f.write(s)
00130             d +=  1
00131 
00132         for i in self.childs:
00133             i.output_xml(f, d)
00134 
00135         if self.name != '':
00136             s = '</' + self.name + '>\n'
00137             if len(self.childs) > 0 :
00138                 s = string.ljust('', 4*depth) + s
00139             f.write(s)
00140 
00141     def Dump(self, levels=-1, depth=0):
00142         #Dumps the tree contents
00143 
00144         if levels == 0: return
00145 
00146         s = string.ljust('', 4*depth)
00147         print s, self, self.content
00148         for i in self.childs:
00149             i.Dump(levels-1, depth+1)
00150 
00151     def parents(self):
00152         #Returns list of the parents
00153         l = []
00154         p = self.parent
00155         while p:
00156             l.append(p)
00157             l.append(p.name)
00158             p = p.parent
00159         return l
00160 
00161     def getChild(self, name, content=None):
00162         # return child node with a given name
00163         # if content == None, don't compare contents
00164         for i in self.childs:
00165             if (i.name == name):
00166                 if (content is None) | (i.content == content):
00167                     return i
00168         return None
00169 
00170     def getNode(self, name, content='', depth=-1):
00171         # recursive search of a node with a given name
00172         # content == None, don't compare content
00173         if (self.name == name):
00174             if (content is None) | (self.content == content):
00175                 return self
00176 
00177         if (depth != 0):
00178             for i in self.childs:
00179                 n = i.getNode(name, content, depth-1)
00180                 if n:  return n
00181 
00182         return None
00183 
00184     def __repr__(self):
00185         s = '<'
00186         if self.name != '':
00187             s += self.name
00188         else:
00189             s +=  'None'
00190         s += '>'
00191         return s
00192 
00193     def merge(self, t):
00194         pass
00195 
00196     def mergeChilds(self, t, list):
00197         L_ext = t.getChild(list)
00198         L_int = self.getChild(list)
00199 
00200         L_merge = Tree(list)
00201 
00202         for i_ext in L_ext.childs:
00203             k_ext = i_ext.key
00204             if k_ext is None:  continue
00205             present = 0
00206 
00207             for i_int in L_int.childs:
00208                 k_int = i_int.key
00209                 if k_int is None:  continue
00210 
00211                 if (k_int == k_ext):
00212                     present = 1
00213                     break;
00214 
00215             if present :
00216                 i_int.merge(i_ext)
00217                 L_merge.addChild(i_int)
00218             else:
00219                 L_merge.addChild(i_ext)
00220 
00221         self.replaceChild(L_merge)
00222 
00223     def setAttrib(self, name,value):
00224       self.attrs[name]=value
00225 
00226 
00227 #--------------------------------------------------
00228 # implements parameter tree
00229 #--------------------------------------------------
00230 class parameter(Tree):
00231 
00232     def __init__(self, name=None, mode = 'in', type='', comment='unknown'):
00233         Tree.__init__(self, mode + 'Parameter', key=name)
00234         self.mode = mode
00235         if name is None:  return
00236 
00237         self.addNamedChild(mode + 'Parameter-name', name)
00238         self.addNamedChild(mode + 'Parameter-type', type)
00239         self.addNamedChild(mode + 'Parameter-comment', comment)
00240 
00241     def merge(self, P):
00242 
00243         self.mode = P.mode
00244         self.replaceChild(P.getChild(P.mode + 'Parameter-name'))
00245         self.replaceChild(P.getChild(P.mode + 'Parameter-type'))
00246         C = P.getChild(P.mode + 'Parameter-comment')
00247         if C.content != 'unkonwn':
00248             self.replaceChild(C)
00249 
00250 #--------------------------------------------------
00251 # implements dataStreamParameter tree
00252 #--------------------------------------------------
00253 class dataStreamParameter(parameter):
00254 
00255     def __init__(self, name=None, mode='in', type='', dependency='', comment='unknown'):
00256         parameter.__init__(self, name, mode, type, comment)
00257         if name is None:  return
00258 
00259         self.addNamedChild(mode + 'Parameter-dependency', dependency)
00260         self.mode = mode
00261 
00262     def merge(self, P):
00263 
00264         parameter.merge(self, P)
00265         self.replaceChild(P.getChild(mode + 'Parameter-dependency'))
00266 
00267 
00268 def parseComment(comment):
00269 
00270     spaces = '[\t\n ]*'
00271     word = spaces + '([a-zA-Z][a-zA-Z0-9_]*)' + spaces
00272 
00273     result = []
00274     type = None
00275     key = None
00276 
00277     ## match :  // followed by a 'DataStreamPorts' string,
00278     ## the service name, and a list of ports
00279     pattern = '// *DataStreamPorts{,1}' + word
00280     m = re.match(pattern, comment)
00281 
00282     ## if there is a match, parse remaining part of comment
00283     if m:
00284         ## service
00285         type = 'DataStreamPorts'
00286         key = m.group(1)
00287 
00288         sPorts = comment[m.end():]
00289         pattern = word + '\('+word+','+word +','+word+'\)' \
00290                   + spaces + ',{,1}' + spaces
00291         while len(sPorts) > 0:
00292             ## process next DataStreamPort
00293             ## match a definition like xx(a,b,c) with a possible trailing ,
00294             ## returns a tuple (xx, a, b, c) and
00295             ## the remaining part of input string
00296             m = re.match(pattern, sPorts)
00297             if m is None:
00298                 raise LookupError, \
00299                       'format error in DataStreamPort definition : '+sPorts
00300             sPorts = sPorts[m.end():]
00301             result.append(m.groups())
00302 
00303     return type, key, result;
00304 
00305 #--------------------------------------------------
00306 # implements service tree
00307 #--------------------------------------------------
00308 class Service(Tree):
00309 
00310     def __init__(self, name=None, comment = 'unknown'):
00311 
00312         Tree.__init__(self, 'component-service', key=name)
00313         if name is None:  return
00314 
00315         self.addNamedChild('service-name', name)
00316         self.addNamedChild('service-author',common_data["AUTHOR"])
00317         self.addNamedChild('service-version',common_data["VERSION"])
00318         self.addNamedChild('service-comment', comment)
00319         self.addNamedChild('service-by-default', "0")
00320         self.addNamedChild('inParameter-list')
00321         self.addNamedChild('outParameter-list')
00322         self.addNamedChild('DataStream-list')
00323 
00324     def createInParameter(self, name, type):
00325         L = self.getChild('inParameter-list')
00326         p = parameter(name, 'in', type)
00327         L.replaceChild(p)
00328         return p
00329 
00330     def createOutParameter(self, name, type):
00331         L = self.getChild('outParameter-list')
00332         p = parameter(name, 'out', type)
00333         L.replaceChild(p)
00334         return p
00335 
00336     def createDataStreamParameter(self, p):
00337         L = self.getChild('DataStream-list')
00338         p = dataStreamParameter(p[0], p[2], p[1], p[3])
00339         L.replaceChild(p)
00340         return p
00341 
00342     def merge(self, S):
00343 
00344         self.replaceChild(S.getChild('service-author'))
00345         self.replaceChild(S.getChild('service-version'))
00346         self.replaceChild(S.getChild('service-by-default'))
00347         C = S.getChild('service-comment')
00348         if C.content != 'unkonwn':
00349             self.replaceChild(C)
00350 
00351         for L in ['inParameter-list', 'outParameter-list', 'DataStream-list']:
00352            self.mergeChilds(S, L)
00353 
00354 
00355 #--------------------------------------------------
00356 # implements interface tree
00357 #--------------------------------------------------
00358 class Interface(Tree):
00359 
00360     def __init__(self, name=None, comment='unknown'):
00361 
00362         Tree.__init__(self, key=name)
00363 
00364         if name is None:  return
00365 
00366         self.addNamedChild('component-interface-name', name)
00367         self.addNamedChild('component-interface-comment', comment);
00368         self.addNamedChild('component-service-list')
00369 
00370     def createService(self, name):
00371         L = self.getChild('component-service-list')
00372 
00373         if L is None:
00374             error ("Interface.createService() : 'component-service-list' is not found")
00375             return None
00376 
00377         s = Service(name)
00378         L.addChild(s)
00379         return s
00380 
00381     def findService(self, key):
00382         L = self.getChild('component-service-list')
00383         for S in L.childs:
00384             if S.key == key:
00385                 return S
00386         return None
00387 
00388     def merge(self, I):
00389 
00390         C = S.getChild('component-interface-comment')
00391         if C.content != 'unkonwn':
00392             self.replaceChild(C)
00393 
00394         self.mergeChilds(I, 'component-service-list')
00395 
00396     def processDataStreams(self):
00397         for sComment in self.comments:
00398 
00399             type, key, result = parseComment(sComment)
00400 
00401             if type == 'DataStreamPorts':
00402                 Service = self.findService(key)
00403                 if Service is None:
00404                     raise LookupError, \
00405                           'service ' + key + \
00406                           ' not found in interface : ' + self.key
00407                 for p in result:
00408                 ## process next DataStreamPort
00409                     Service.createDataStreamParameter(p)
00410 
00411 
00412 #--------------------------------------------------
00413 # implements Component tree
00414 #--------------------------------------------------
00415 class Component(Tree):
00416     def __init__(self, name=None):
00417         Tree.__init__(self, 'component', key=name)
00418         if name is None:  return
00419 
00420 # ASV : fix for bug PAL8922 (Component name indicated by user in GUI is not taken into account
00421         if common_data["COMP_NAME"] != '':
00422             self.addNamedChild('component-name', common_data["COMP_NAME"])
00423         else:
00424             self.addNamedChild('component-name', name)
00425 
00426 # ASV : if user name is NOT set, then use component-name instead.  Else - default.
00427         if common_data["COMP_UNAME"] != '':
00428             self.addNamedChild('component-username',   common_data["COMP_UNAME"])
00429         else:
00430             if common_data["COMP_NAME"] != '':
00431                 self.addNamedChild('component-username', common_data["COMP_NAME"] )
00432             else:
00433                 self.addNamedChild('component-username',   name)
00434 
00435         self.addNamedChild('component-type',       common_data["COMP_TYPE"])
00436         self.addNamedChild('component-author',     common_data["AUTHOR"])
00437         self.addNamedChild('component-version',    common_data["VERSION"])
00438         self.addNamedChild('component-comment',    'unknown')
00439         self.addNamedChild('component-multistudy', common_data["COMP_MULT"])
00440         self.addNamedChild('component-impltype',   common_data["COMP_IMPL"])
00441         self.addNamedChild('component-icone',      common_data["ICON"])
00442         self.addNamedChild('constraint')
00443         self.addNamedChild('component-interface-list')
00444 
00445     def createInterface(self, name):
00446         L = self.getChild('component-interface-list')
00447         if L is None:
00448             error("createInterface: No component-interface-list is found")
00449             return None
00450         i = Interface(name)
00451         L.addChild(i)
00452         return i
00453 
00454     def merge(self, C):
00455 
00456         for i in ['component-username', 'component-author',
00457                   'component-type', 'component-icone', 'component-version',
00458                   'component-multistudy', 'component-impltype', 'constraint']:
00459             ext = C.getChild(i)
00460             int = self.getChild(i)
00461             if int is None:
00462                 int = ext
00463             elif ext is not None and len(ext.content):
00464                 int.content = ext.content
00465 
00466         Cc = C.getChild('component-comment')
00467         if Cc.content != 'unkonwn':
00468             self.replaceChild(Cc)
00469 
00470         self.mergeChilds(C, 'component-interface-list')
00471 
00472 #--------------------------------------------------
00473 # implements document tree
00474 #--------------------------------------------------
00475 class Catalog(ContentHandler, Tree):
00476     def __init__(self, filename = None):
00477         Tree.__init__(self)
00478         self.buffer = ''
00479         self.list = []
00480         if (filename):
00481             parser = xml.sax.make_parser()
00482             parser.setContentHandler(self)
00483             parser.parse(filename)
00484         else:
00485             t = self.addNamedChild('begin-catalog')
00486             t.addNamedChild('type-list')
00487             t.addNamedChild('component-list')
00488 
00489         n = self.getChild('begin-catalog')
00490         if n is None:
00491             error("Catalog.__init__ : No 'begin-catalog' is found!")
00492             return
00493         if n.getChild('path-prefix-list') is None:
00494             n.insertFirstNamedChild('path-prefix-list')
00495         if n.getChild('type-list') is None:
00496             p=n.childs.index(n.getChild('path-prefix-list'))
00497             n.childs.insert(p+1,Tree('type-list'))
00498         if n.getChild('component-list') is None:
00499             n.addNamedChild('component-list')
00500 
00501     def removeComponent(self, name):
00502         complist = self.getNode('component-list')
00503         idx = 0
00504         if complist is None:
00505             print "Catalog.removeComponent() : 'component-list' is not found"
00506             return
00507         for comp in complist.childs:
00508             cname = comp.getChild('component-name')
00509             if cname is not None:
00510                 if cname.content == name:
00511                     complist.childs.pop(idx)
00512                     print "Component " + name + " is removed"
00513             idx += 1
00514 
00515     def startDocument(self):
00516         self.list.append(self)
00517 
00518     def startElement(self, name, attrs):
00519         p = self.list[len(self.list)-1]
00520         if name == 'component':
00521             e = p.addChild(Component())
00522         elif name == 'component-interface-name':
00523             e = p.addNamedChild(name)
00524         elif name == 'component-service':
00525             e = p.addChild(Service())
00526         elif name == 'inParameter':
00527             e = p.addChild(parameter(mode='in'))
00528         elif name == 'outParameter':
00529             e = p.addChild(parameter(mode='out'))
00530         elif name == 'sequence':
00531             e = p.addChild(SeqType(attrs["name"],attrs["content"]))
00532         elif name == 'objref':
00533             e = p.addChild(ObjType(attrs["name"]))
00534         elif name == 'struct':
00535             e = p.addChild(StructType(attrs["name"]))
00536         elif name == 'type':
00537             e = p.addChild(Type(attrs["name"],attrs["kind"]))
00538         elif name == 'member':
00539             e = p.addChild(Member(attrs["name"],attrs["type"]))
00540         else:
00541             e = p.addNamedChild(name)
00542         self.list.append(e)
00543         self.buffer = ''
00544 
00545     def endElement(self, name):
00546         self.buffer = string.join(string.split(self.buffer), ' ')
00547         p = self.list[len(self.list)-1]
00548         p.content = self.buffer
00549         if name == 'component':
00550             p.key = p.getChild('component-name').content
00551         self.buffer = ''
00552         e = self.list.pop()
00553 
00554     def characters(self, ch):
00555         self.buffer += ch
00556 
00557     def mergeComponent(self, comp):
00558 
00559         L_int = self.getNode('component-list')
00560         if   L_int is None:
00561             error("Catalog.mergeComponent : 'component-list' is not found")
00562             return
00563 
00564         i_ext = comp
00565         present = 0
00566         n_ext = i_ext.key
00567         for i_int in L_int.childs:
00568             if (i_int.key == n_ext):
00569                 present = 1
00570                 break;
00571 
00572         if present == 0:
00573             print '   add component', i_ext.getChild('component-name').content
00574             L_int.addChild(i_ext)
00575         else:
00576             print '   replace component', i_ext.getChild('component-name').content
00577             i_int.merge(i_ext)
00578 
00579     def mergeType(self, type):
00580       L_int = self.getNode('type-list')
00581       if L_int is None:
00582         error("Catalog.mergeType : 'type-list' is not found")
00583         return
00584       for t in L_int.childs:
00585         if t.attrs["name"] == type.attrs["name"]:
00586           t.merge(type)
00587           return
00588 
00589       L_int.addChild(type)
00590 
00591 class Member(Tree):
00592   def __init__(self, name,type):
00593     Tree.__init__(self, 'member')
00594     self.setAttrib("name",name)
00595     self.setAttrib("type",type)
00596 
00597 class Type(Tree):
00598   def __init__(self, name,kind):
00599     Tree.__init__(self, 'type')
00600     self.setAttrib("name",name)
00601     self.setAttrib("kind",kind)
00602 
00603   def merge(self,t):
00604     self.setAttrib("kind",t.attrs["kind"])
00605 
00606 class SeqType(Tree):
00607   def __init__(self, name,content):
00608     Tree.__init__(self, 'sequence')
00609     self.setAttrib("name",name)
00610     self.setAttrib("content",content)
00611 
00612   def merge(self,t):
00613     self.setAttrib("content",t.attrs["content"])
00614 
00615 class StructType(Tree):
00616   def __init__(self, name):
00617     Tree.__init__(self, 'struct')
00618     self.setAttrib("name",name)
00619 
00620   def merge(self,t):
00621     #remove childs and replace by t childs
00622     self.childs=[]
00623     for c in t.childs:
00624       self.childs.append(c)
00625 
00626 class ObjType(Tree):
00627   def __init__(self, name):
00628     Tree.__init__(self, 'objref')
00629     self.setAttrib("name",name)
00630 
00631   def merge(self,t):
00632     RepoId=t.attrs.get("id")
00633     if RepoId:
00634       self.setAttrib("id",RepoId)
00635     #remove childs and replace by t childs
00636     self.childs=[]
00637     for c in t.childs:
00638       self.childs.append(c)
00639 
00640 # IDL file reader
00641 
00642 ttsMap = {
00643     idltype.tk_void:       "void",
00644     idltype.tk_short:      "short",
00645     idltype.tk_long:       "long",
00646     idltype.tk_ushort:     "unsigned short",
00647     idltype.tk_ulong:      "unsigned long",
00648     idltype.tk_float:      "float",
00649     idltype.tk_double:     "double",
00650     idltype.tk_boolean:    "boolean",
00651     idltype.tk_char:       "char",
00652     idltype.tk_octet:      "octet",
00653     idltype.tk_any:        "any",
00654     idltype.tk_TypeCode:   "CORBA::TypeCode",
00655     idltype.tk_Principal:  "CORBA::Principal",
00656     idltype.tk_longlong:   "long long",
00657     idltype.tk_ulonglong:  "unsigned long long",
00658     idltype.tk_longdouble: "long double",
00659     idltype.tk_wchar:      "wchar"
00660     }
00661 
00662 
00663 #--------------------------------------------------
00664 # class ModuleCatalogVisitor
00665 #--------------------------------------------------
00666 class ModuleCatalogVisitor (idlvisitor.AstVisitor):
00667 
00668     def __init__(self, catalog):
00669         self.catalog = catalog
00670         self.EngineType = 0
00671         self.currentScope=None
00672 
00673     def visitAST(self, node):
00674         for n in node.declarations():
00675             if n.mainFile():
00676               n.accept(self)
00677 
00678     def visitModule(self, node):
00679         self.currentScope=node
00680         for n in node.definitions():
00681             n.accept(self)
00682 
00683     def visitInterface(self, node):
00684         if node.mainFile():
00685 
00686             self.EngineType = 0
00687 
00688             for i in node.inherits():
00689                 s = i.scopedName();
00690                 if s[0] == "Engines":
00691                   if s[1] == "EngineComponent":
00692                     self.EngineType = 1; break
00693                   if s[1] == "Superv_Component":
00694                     self.EngineType = 2; break
00695 
00696             if self.EngineType:
00697               #This interface is a SALOME component
00698               Comp = Component(node.identifier())
00699 
00700               self.currentInterface = Comp.createInterface(node.identifier())
00701 
00702               for c in node.callables():
00703                 if isinstance(c, idlast.Operation):
00704                     c.accept(self)
00705 
00706               for c in node.declarations():
00707                 if isinstance(c, idlast.Struct):
00708                     c.accept(self)
00709 
00710               for i in node.comments():
00711                 self.currentInterface.comments.append(str(i))
00712 
00713               if self.EngineType == 2:
00714                 self.currentInterface.processDataStreams()
00715 
00716               global nb_components
00717               nb_components = nb_components + 1
00718               self.catalog.mergeComponent(Comp)
00719 
00720             else:
00721               #This interface is not a component : use it as a DataType
00722               t=ObjType("/".join(node.scopedName()))
00723               for i in node.inherits():
00724                 t.addNamedChild("base","/".join(i.scopedName()))
00725               self.catalog.mergeType(t)
00726 
00727             self.EngineType = 0
00728 
00729 
00730     def visitOperation(self, node):
00731 
00732         self.currentService = self.currentInterface.createService \
00733                                        (node.identifier())
00734 
00735         node.returnType().accept(self)
00736         if (self.currentType != "void"):
00737             self.currentService.createOutParameter \
00738                 ("return", self.currentType)
00739 
00740         for c in node.parameters():
00741             c.accept(self)
00742 
00743         for i in node.comments():
00744             self.currentInterface.comments.append(str(i))
00745 
00746 
00747     def visitDeclaredType(self, type):
00748         name=type.name()
00749         scoped_name="/".join(type.scopedName())
00750         self.currentType = scoped_name
00751 
00752     def visitBaseType(self, type):
00753         self.currentType = ttsMap[type.kind()]
00754 
00755     def visitStringType(self, type):
00756         self.currentType = "string"
00757 
00758     def visitParameter(self, node):
00759         node.paramType().accept(self)
00760         if node.is_in():
00761             self.currentService.createInParameter \
00762                      (node.identifier(), self.currentType)
00763         if node.is_out():
00764             self.currentService.createOutParameter \
00765                      (node.identifier(), self.currentType)
00766 
00767     def visitSequenceType(self,type):
00768       type.seqType().accept(self)
00769       if type.bound() == 0:
00770           self.contentType=self.currentType
00771           self.currentType = "sequence"
00772       else:
00773           self.currentType = None
00774 
00775     def visitTypedef(self, node):
00776       if node.constrType():
00777             node.aliasType().decl().accept(self)
00778 
00779       node.aliasType().accept(self)
00780       type  = self.currentType
00781       if not type:
00782         return
00783       decll = []
00784       for d in node.declarators():
00785             d.accept(self)
00786             if self.__result_declarator:
00787               decll.append(self.__result_declarator)
00788       if type == "sequence":
00789         #it's a sequence type
00790         for name in decll:
00791           scoped_name="/".join(self.currentScope.scopedName()+[name])
00792           self.catalog.mergeType(SeqType(scoped_name,self.contentType))
00793       #else:
00794         #it's an alias
00795       #  for name in decll:
00796       #    scoped_name="/".join(self.currentScope.scopedName()+[name])
00797       #    self.catalog.mergeType(Type(scoped_name,type))
00798 
00799     def visitStruct(self, node):
00800       t=StructType("/".join(node.scopedName()))
00801       for m in node.members():
00802             if m.constrType():
00803                 m.memberType().decl().accept(self)
00804 
00805             m.memberType().accept(self)
00806             type = self.currentType
00807             for d in m.declarators():
00808                 d.accept(self)
00809                 t.addChild(Member(self.__result_declarator,type))
00810 
00811       self.catalog.mergeType(t)
00812 
00813     def visitDeclarator(self, node):
00814         if node.sizes():
00815           self.__result_declarator =None
00816         else:
00817           self.__result_declarator =node.identifier()
00818 
00819 #--------------------------------------------------
00820 # parse idl and store xml file
00821 #--------------------------------------------------
00822 def run(tree, args):
00823 
00824     CatalogFileName=getParamValue("catalog", "CatalogModulePersonnel.xml", args)
00825     if re.compile(".*?.xml$").match(CatalogFileName, 1) is None:
00826         CatalogFileName = CatalogFileName + '.xml'
00827 
00828     #=========  Read parameters  ======================
00829     common_data["ICON"]       = getParamValue("icon",       "",                args)
00830     common_data["AUTHOR"]     = getParamValue("author",     os.getenv("USER"), args)
00831     common_data["VERSION"]    = getParamValue("version",    "1",               args)
00832     common_data["COMP_NAME"]  = getParamValue("name",       "",                args)
00833     common_data["COMP_UNAME"] = getParamValue("username",   "",                args)
00834     common_data["COMP_TYPE"]  = getParamValue("type",       "OTHER",           args)
00835     common_data["COMP_MULT"]  = getParamValue("multistudy", "1",               args)
00836     common_data["COMP_IMPL"]  = getParamValue("impltype",   "1",               args)
00837 
00838     print common_data
00839 
00840     remove_comp = getParamValue("remove", "", args)
00841 
00842     #==================================================
00843 
00844     if (os.path.exists(CatalogFileName)):
00845         print "Importing", CatalogFileName
00846         C = Catalog(CatalogFileName)
00847     else:
00848         print "Creating ",CatalogFileName
00849         C = Catalog()
00850 
00851     print "Reading idl file"
00852 
00853     visitor = ModuleCatalogVisitor(C)
00854     tree.accept(visitor)
00855 
00856 ##    C.Dump()
00857 
00858     if remove_comp :
00859         C.removeComponent(remove_comp)
00860 
00861     if (os.path.exists(CatalogFileName)):
00862         print "Updating", CatalogFileName
00863         CatalogFileName_old = CatalogFileName + '_old'
00864         os.rename(CatalogFileName, CatalogFileName_old)
00865     else:
00866         CatalogFileName_old = ""
00867         print "Writing", CatalogFileName
00868 
00869     CatalogFileName_new = CatalogFileName + '_new'
00870     f=open(CatalogFileName_new, 'w')
00871     f.write("<?xml version='1.0' encoding='us-ascii' ?>\n\n")
00872     C.output_xml(f)
00873     f.close()
00874 
00875     os.rename(CatalogFileName_new, CatalogFileName)
00876     if ((CatalogFileName_old != "") & os.path.exists(CatalogFileName_old)):
00877         os.unlink(CatalogFileName_old)
00878 
00879     print
00880 
00881 
00882 if __name__ == "__main__":
00883     print
00884     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>"
00885     print