From: caremoli Date: Fri, 26 Sep 2008 07:54:27 +0000 (+0000) Subject: CCAR: update IDLparser.py with developments for YACS (mainly, DataTypes description X-Git-Tag: RELIQUAT_4x_25102008~31 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ba16755542bc348162f9cba9c706af0d849aea02;p=modules%2Fkernel.git CCAR: update IDLparser.py with developments for YACS (mainly, DataTypes description and new Superv_Component interface for SALOME components) Not all definitions are converted to DataTypes YACS, only local definitions (main file) that are : - unbounded sequences - non recursive structs (and non forward ones also) - interfaces that are not derivation from SALOME components The tests have been updated : - add some idl files in tests to be able to run tests only in KERNEL_BUILD - adjust some paths (very old SALOME 1 ??) to run with KERNEL only --- diff --git a/src/ModuleGenerator/IDLparser.py b/src/ModuleGenerator/IDLparser.py index 0b74eb3af..7ffd96c34 100644 --- a/src/ModuleGenerator/IDLparser.py +++ b/src/ModuleGenerator/IDLparser.py @@ -80,6 +80,7 @@ class Tree: self.parent = None self.childs = [] self.comments = [] + self.attrs={} def addChild(self, tree): if tree is not None: @@ -114,7 +115,10 @@ class Tree: d = depth if self.name != '': s = string.ljust('', 4*depth) - s += '<' + self.name + '>' + s += '<' + self.name + for k,v in self.attrs.items(): + s += ' ' + k + '="' + v + '"' + s += '>' if self.content != '': s += self.content else: @@ -213,6 +217,9 @@ class Tree: L_merge.addChild(i_ext) self.replaceChild(L_merge) + + def setAttrib(self, name,value): + self.attrs[name]=value @@ -476,6 +483,7 @@ class Catalog(ContentHandler, Tree): parser.parse(filename) else: t = self.addNamedChild('begin-catalog') + t.addNamedChild('type-list') t.addNamedChild('component-list') n = self.getChild('begin-catalog') @@ -484,6 +492,9 @@ class Catalog(ContentHandler, Tree): return if n.getChild('path-prefix-list') is None: n.insertFirstNamedChild('path-prefix-list') + if n.getChild('type-list') is None: + p=n.childs.index(n.getChild('path-prefix-list')) + n.childs.insert(p+1,Tree('type-list')) if n.getChild('component-list') is None: n.addNamedChild('component-list') @@ -516,6 +527,16 @@ class Catalog(ContentHandler, Tree): e = p.addChild(parameter(mode='in')) elif name == 'outParameter': e = p.addChild(parameter(mode='out')) + elif name == 'sequence': + e = p.addChild(SeqType(attrs["name"],attrs["content"])) + elif name == 'objref': + e = p.addChild(ObjType(attrs["name"])) + elif name == 'struct': + e = p.addChild(StructType(attrs["name"])) + elif name == 'type': + e = p.addChild(Type(attrs["name"],attrs["kind"])) + elif name == 'member': + e = p.addChild(Member(attrs["name"],attrs["type"])) else: e = p.addNamedChild(name) self.list.append(e) @@ -555,8 +576,66 @@ class Catalog(ContentHandler, Tree): print ' replace component', i_ext.getChild('component-name').content i_int.merge(i_ext) - - + def mergeType(self, type): + L_int = self.getNode('type-list') + if L_int is None: + error("Catalog.mergeType : 'type-list' is not found") + return + for t in L_int.childs: + if t.attrs["name"] == type.attrs["name"]: + t.merge(type) + return + + L_int.addChild(type) + +class Member(Tree): + def __init__(self, name,type): + Tree.__init__(self, 'member') + self.setAttrib("name",name) + self.setAttrib("type",type) + +class Type(Tree): + def __init__(self, name,kind): + Tree.__init__(self, 'type') + self.setAttrib("name",name) + self.setAttrib("kind",kind) + + def merge(self,t): + self.setAttrib("kind",t.attrs["kind"]) + +class SeqType(Tree): + def __init__(self, name,content): + Tree.__init__(self, 'sequence') + self.setAttrib("name",name) + self.setAttrib("content",content) + + def merge(self,t): + self.setAttrib("content",t.attrs["content"]) + +class StructType(Tree): + def __init__(self, name): + Tree.__init__(self, 'struct') + self.setAttrib("name",name) + + def merge(self,t): + #remove childs and replace by t childs + self.childs=[] + for c in t.childs: + self.childs.append(c) + +class ObjType(Tree): + def __init__(self, name): + Tree.__init__(self, 'objref') + self.setAttrib("name",name) + + def merge(self,t): + RepoId=t.attrs.get("id") + if RepoId: + self.setAttrib("id",RepoId) + #remove childs and replace by t childs + self.childs=[] + for c in t.childs: + self.childs.append(c) # IDL file reader @@ -589,47 +668,61 @@ class ModuleCatalogVisitor (idlvisitor.AstVisitor): def __init__(self, catalog): self.catalog = catalog self.EngineType = 0 + self.currentScope=None def visitAST(self, node): for n in node.declarations(): - n.accept(self) + if n.mainFile(): + n.accept(self) def visitModule(self, node): + self.currentScope=node for n in node.definitions(): n.accept(self) def visitInterface(self, node): - if node.mainFile(): self.EngineType = 0 for i in node.inherits(): s = i.scopedName(); - if ((s[0] == "Engines") & (s[1] == "Component")): + if s[0] == "Engines": + if s[1] == "Component": self.EngineType = 1; break + if s[1] == "Superv_Component": + self.EngineType = 2; break - Comp = Component(node.identifier()) + if self.EngineType: + #This interface is a SALOME component + Comp = Component(node.identifier()) - self.currentInterface = Comp.createInterface(node.identifier()) + self.currentInterface = Comp.createInterface(node.identifier()) - for c in node.callables(): + for c in node.callables(): if isinstance(c, idlast.Operation): c.accept(self) - for c in node.declarations(): + for c in node.declarations(): if isinstance(c, idlast.Struct): c.accept(self) - for i in node.comments(): + for i in node.comments(): self.currentInterface.comments.append(str(i)) - self.currentInterface.processDataStreams() + if self.EngineType == 2: + self.currentInterface.processDataStreams() - if (self.EngineType): - global nb_components - nb_components = nb_components + 1 - self.catalog.mergeComponent(Comp) + global nb_components + nb_components = nb_components + 1 + self.catalog.mergeComponent(Comp) + + else: + #This interface is not a component : use it as a DataType + t=ObjType("/".join(node.scopedName())) + for i in node.inherits(): + t.addNamedChild("base","/".join(i.scopedName())) + self.catalog.mergeType(t) self.EngineType = 0 @@ -652,7 +745,9 @@ class ModuleCatalogVisitor (idlvisitor.AstVisitor): def visitDeclaredType(self, type): - self.currentType = type.name() + name=type.name() + scoped_name="/".join(type.scopedName()) + self.currentType = scoped_name def visitBaseType(self, type): self.currentType = ttsMap[type.kind()] @@ -669,6 +764,58 @@ class ModuleCatalogVisitor (idlvisitor.AstVisitor): self.currentService.createOutParameter \ (node.identifier(), self.currentType) + def visitSequenceType(self,type): + type.seqType().accept(self) + if type.bound() == 0: + self.contentType=self.currentType + self.currentType = "sequence" + else: + self.currentType = None + + def visitTypedef(self, node): + if node.constrType(): + node.aliasType().decl().accept(self) + + node.aliasType().accept(self) + type = self.currentType + if not type: + return + decll = [] + for d in node.declarators(): + d.accept(self) + if self.__result_declarator: + decll.append(self.__result_declarator) + if type == "sequence": + #it's a sequence type + for name in decll: + scoped_name="/".join(self.currentScope.scopedName()+[name]) + self.catalog.mergeType(SeqType(scoped_name,self.contentType)) + #else: + #it's an alias + # for name in decll: + # scoped_name="/".join(self.currentScope.scopedName()+[name]) + # self.catalog.mergeType(Type(scoped_name,type)) + + def visitStruct(self, node): + t=StructType("/".join(node.scopedName())) + for m in node.members(): + if m.constrType(): + m.memberType().decl().accept(self) + + m.memberType().accept(self) + type = self.currentType + for d in m.declarators(): + d.accept(self) + t.addChild(Member(self.__result_declarator,type)) + + self.catalog.mergeType(t) + + def visitDeclarator(self, node): + if node.sizes(): + self.__result_declarator =None + else: + self.__result_declarator =node.identifier() + #-------------------------------------------------- # parse idl and store xml file #-------------------------------------------------- diff --git a/src/ModuleGenerator/testIDLparser.in b/src/ModuleGenerator/testIDLparser.in index 64709e7ac..fbb90b735 100755 --- a/src/ModuleGenerator/testIDLparser.in +++ b/src/ModuleGenerator/testIDLparser.in @@ -4,7 +4,7 @@ ROOT_SRCDIR=@ROOT_SRCDIR@ export ROOT_SRCDIR ROOT_BUILDDIR=@ROOT_BUILDDIR@ export ROOT_BUILDDIR -SRCDIR=${ROOT_SRCDIR}/SALOME/src/ModuleGenerator +SRCDIR=${ROOT_SRCDIR}/src/ModuleGenerator export SRCDIR ${SRCDIR}/tests/test$1.sh diff --git a/src/ModuleGenerator/tests/AddComponent.idl b/src/ModuleGenerator/tests/AddComponent.idl new file mode 100644 index 000000000..6a13292bf --- /dev/null +++ b/src/ModuleGenerator/tests/AddComponent.idl @@ -0,0 +1,67 @@ +// Copyright (C) 2005 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : AddComponent.idl +// Author : Jean Rahuel + +#ifndef _ADDCOMPONENT_IDL +#define _ADDCOMPONENT_IDL + +#include "SALOME_Component.idl" + +module SuperVisionTest { + + interface Adder ; + + interface AddComponent : Engines::Component { + double Add( in double x , in double y , out double z ) ; + double AddWithoutSleep( in double x , in double y , out double z ) ; + void Setx( in double x ) ; + void Sety( in double y ) ; + double Addxy() ; + double AddyTox( in double y ) ; + long Sigma( in long n ) ; + double LastResult() ; + + Adder Addition() ; + boolean AdditionObjRef1( out Adder anAdder ) ; + void AdditionObjRef2( out boolean FuncValue , out Adder anAdder ) ; + boolean AdditionObjRefs( in AddComponent AddComponent1 , + in AddComponent Adder2 , + in AddComponent Adder3 , + out AddComponent RetAddComponent1 , + out AddComponent RetAdder2 , + out AddComponent RetAdder3 ) ; + }; + + interface Adder : Engines::Component { + double Add( in double x , in double y , out double z ) ; + double AddWithoutSleep( in double x , in double y , out double z ) ; + double AddAndCompare( in double x , in double y , in Adder anOtherAdder, + out double z ) ; + void SetLastResult( in double z ) ; + void LastResult( out double z ) ; + Engines::Component LccAddComponent( in string aContainer , + in string aComponentName ) ; + }; + +} ; + +#endif diff --git a/src/ModuleGenerator/tests/SubComponent.idl b/src/ModuleGenerator/tests/SubComponent.idl new file mode 100644 index 000000000..d651d236e --- /dev/null +++ b/src/ModuleGenerator/tests/SubComponent.idl @@ -0,0 +1,37 @@ +// Copyright (C) 2005 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : SubComponent.idl +// Author : Jean Rahuel + +#ifndef _SUBCOMPONENT_IDL +#define _SUBCOMPONENT_IDL + +#include "SALOME_Component.idl" + +module SuperVisionTest { + + interface SubComponent : Engines::Component { + void Sub( in double x , in double y , out double z ) ; + } ; +}; + + +#endif diff --git a/src/ModuleGenerator/tests/test1.sh b/src/ModuleGenerator/tests/test1.sh index 34dd9cddd..6133420cd 100755 --- a/src/ModuleGenerator/tests/test1.sh +++ b/src/ModuleGenerator/tests/test1.sh @@ -32,7 +32,8 @@ echo "test1: \rm -f my_catalog.xml* -${ROOT_BUILDDIR}/bin/runIDLparser \ +sh ${ROOT_BUILDDIR}/bin/runIDLparser -p ${SRCDIR} \ + -I${ROOT_SRCDIR}/idl \ -Wbcatalog=my_catalog.xml \ - ${ROOT_SRCDIR}/idl/AddComponent.idl + ${SRCDIR}/tests/AddComponent.idl diff --git a/src/ModuleGenerator/tests/test1b.sh b/src/ModuleGenerator/tests/test1b.sh index 8af58c555..4d323a402 100755 --- a/src/ModuleGenerator/tests/test1b.sh +++ b/src/ModuleGenerator/tests/test1b.sh @@ -24,7 +24,7 @@ # File : test1b.sh # Module : SALOME -echo "test6: +echo "test1b: test derivation Engine::Component " @@ -36,7 +36,8 @@ echo " --> creation d'un nouveau catalogue avec un composant " -${ROOT_BUILDDIR}/bin/runIDLparser \ - -Wbcatalog=my_catalog.xml \ +sh ${ROOT_BUILDDIR}/bin/runIDLparser -p ${SRCDIR} \ + -I${ROOT_SRCDIR}/idl \ + -Wbcatalog=my_catalog.xml \ ${SRCDIR}/tests/TrucComponent.idl diff --git a/src/ModuleGenerator/tests/test2.sh b/src/ModuleGenerator/tests/test2.sh index dc2ba48d8..7ce6b0c5f 100755 --- a/src/ModuleGenerator/tests/test2.sh +++ b/src/ModuleGenerator/tests/test2.sh @@ -37,25 +37,28 @@ echo " --> creation d'un nouveau catalogue avec un composant " -${ROOT_BUILDDIR}/bin/runIDLparser \ +sh ${ROOT_BUILDDIR}/bin/runIDLparser -p ${SRCDIR} \ + -I${ROOT_SRCDIR}/idl \ -Wbcatalog=my_catalog.xml \ - ${ROOT_SRCDIR}/idl/AddComponent.idl + ${SRCDIR}/tests/AddComponent.idl echo " --> ajout d'un nouveau composant dans le catalogue " -${ROOT_BUILDDIR}/bin/runIDLparser \ +sh ${ROOT_BUILDDIR}/bin/runIDLparser -p ${SRCDIR} \ + -I${ROOT_SRCDIR}/idl \ -Wbcatalog=my_catalog.xml \ - ${ROOT_SRCDIR}/idl/SubComponent.idl + ${SRCDIR}/tests/SubComponent.idl echo " --> remplacement du premier composant dans le catalogue " -${ROOT_BUILDDIR}/bin/runIDLparser \ +sh ${ROOT_BUILDDIR}/bin/runIDLparser -p ${SRCDIR} \ + -I${ROOT_SRCDIR}/idl \ -Wbcatalog=my_catalog.xml \ - ${ROOT_SRCDIR}/idl/AddComponent.idl + ${SRCDIR}/tests/AddComponent.idl diff --git a/src/ModuleGenerator/tests/test3.sh b/src/ModuleGenerator/tests/test3.sh index 8bead0b7e..236550d83 100755 --- a/src/ModuleGenerator/tests/test3.sh +++ b/src/ModuleGenerator/tests/test3.sh @@ -37,14 +37,17 @@ echo " --> creation d'un nouveau catalogue avec un composant " -${ROOT_BUILDDIR}/bin/runIDLparser \ - -Wbcatalog=my_catalog.xml \ - ${ROOT_SRCDIR}/idl/AddComponent.idl +sh ${ROOT_BUILDDIR}/bin/runIDLparser -p ${SRCDIR} \ + -I${ROOT_SRCDIR}/idl \ + -Wbcatalog=my_catalog.xml \ + ${SRCDIR}/tests/AddComponent.idl + echo " --> remplacement du composant dans le catalogue (meme idl) " -${ROOT_BUILDDIR}/bin/runIDLparser \ - -Wbcatalog=my_catalog.xml \ - ${ROOT_SRCDIR}/idl/AddComponent.idl +sh ${ROOT_BUILDDIR}/bin/runIDLparser -p ${SRCDIR} \ + -I${ROOT_SRCDIR}/idl \ + -Wbcatalog=my_catalog.xml \ + ${SRCDIR}/tests/AddComponent.idl diff --git a/src/ModuleGenerator/tests/test4.sh b/src/ModuleGenerator/tests/test4.sh index 7c6b77c76..b14f3b0bd 100755 --- a/src/ModuleGenerator/tests/test4.sh +++ b/src/ModuleGenerator/tests/test4.sh @@ -36,9 +36,10 @@ echo " --> creation d'un nouveau catalogue avec un composant " -${ROOT_BUILDDIR}/bin/runIDLparser \ - -Wbcatalog=my_catalog.xml \ - ${ROOT_SRCDIR}/idl/AddComponent.idl +sh ${ROOT_BUILDDIR}/bin/runIDLparser -p ${SRCDIR} \ + -I${ROOT_SRCDIR}/idl \ + -Wbcatalog=my_catalog.xml \ + ${SRCDIR}/tests/AddComponent.idl mv my_catalog.xml C1 @@ -53,7 +54,8 @@ mv C1 my_catalog.xml --> remplacement du composant dans le catalogue (autre idl) " -${ROOT_BUILDDIR}/bin/runIDLparser \ - -Wbcatalog=my_catalog.xml \ - ${SRCDIR}/tests/Truc2Component.idl +sh ${ROOT_BUILDDIR}/bin/runIDLparser -p ${SRCDIR} \ + -I${ROOT_SRCDIR}/idl \ + -Wbcatalog=my_catalog.xml \ + ${SRCDIR}/tests/Truc2Component.idl diff --git a/src/ModuleGenerator/tests/test5.sh b/src/ModuleGenerator/tests/test5.sh index 8f03323b2..02783763f 100755 --- a/src/ModuleGenerator/tests/test5.sh +++ b/src/ModuleGenerator/tests/test5.sh @@ -24,7 +24,7 @@ # File : test5.sh # Module : SALOME -echo "test4: +echo "test5: creation d'un catalogue avec tous les idl de Salome (au 29/3/2002) @@ -37,6 +37,7 @@ do echo echo " processing " `basename $i` echo - ${ROOT_BUILDDIR}/bin/runIDLparser \ - -Wbcatalog=my_catalog.xml $i + sh ${ROOT_BUILDDIR}/bin/runIDLparser -p ${SRCDIR} \ + -I${ROOT_SRCDIR}/idl \ + -Wbcatalog=my_catalog.xml $i done