Version: 9.15.0
typeParsers.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include "typeParsers.hxx"
21 #include "dataParsers.hxx"
22 #include "Exception.hxx"
23 #include "Proc.hxx"
24 #include "Runtime.hxx"
25 
26 #include <sstream>
27 
28 //#define _DEVDEBUG_
29 #include "YacsTrace.hxx"
30 
33 
34 namespace YACS
35 {
36  typetypeParser typetypeParser::typeParser;
37  seqtypeParser seqtypeParser::seqParser;
38  objtypeParser objtypeParser::objParser;
39  structtypeParser structtypeParser::structParser;
40  membertypeParser membertypeParser::memberParser;
41 
43  {
44  if (!attr)
45  return;
46  required("name",attr);
47  required("kind",attr);
48  for (int i = 0; attr[i]; i += 2)
49  {
50  if(std::string(attr[i]) == "name")name(attr[i+1]);
51  if(std::string(attr[i]) == "kind")kind(attr[i+1]);
52  }
53  }
55  void typetypeParser::name(const std::string& name)
56  {
57  DEBTRACE( "type_name: " << name )
58  _name=name;
59  }
60  void typetypeParser::kind(const std::string& name)
61  {
62  DEBTRACE( "type_kind: " << name )
63  _kind=name;
64  }
66  {
67  DEBTRACE( "type_post" )
68  mytype t;
69  t._kind=_kind;
70  t._name=_name;
71  return t;
72  }
73 
74  void seqtypeParser::onStart(const XML_Char* el, const XML_Char** attr)
75  {
76  DEBTRACE( "seqtypeParser::onStart: " << el )
79  pp->init();
80  pp->pre();
81  pp->buildAttr(attr);
82  }
83  void seqtypeParser::onEnd(const char *el,parser* child)
84  {
85  DEBTRACE( "seqtypeParser::onEnd: " << el )
86  }
88  {
89  if (!attr)
90  return;
91  required("name",attr);
92  required("content",attr);
93  for (int i = 0; attr[i]; i += 2)
94  {
95  if(std::string(attr[i]) == "name")name(attr[i+1]);
96  if(std::string(attr[i]) == "content")content(attr[i+1]);
97  }
98  }
99  void seqtypeParser::name(const std::string& name)
100  {
101  DEBTRACE( "seqtype_name: " << name )
102  _name=name;
103  }
104  void seqtypeParser::content(const std::string& name)
105  {
106  DEBTRACE( "seqtype_content: " << name )
107  if(currentProc->typeMap.count(name)==0)
108  {
109  //Check if the typecode is defined in the runtime
111  if(t==0)
112  {
113  std::stringstream msg;
114  msg << "Type " << name << " does not exist" << " (" <<__FILE__ << ":" << __LINE__ << ")";
115  throw Exception(msg.str());
116  }
117  else
118  {
120  t->incrRef();
121  }
122  }
124 
125  }
127  {
128  DEBTRACE( "seqtype_post" )
130  return t;
131  }
132 
133  void objtypeParser::onStart(const XML_Char* el, const XML_Char** attr)
134  {
135  DEBTRACE( "objtypeParser::onStart: " << el )
136  std::string element(el);
138  if(element == "base")pp=&stringtypeParser::stringParser;
139  SetUserDataAndPush(pp);
140  pp->init();
141  pp->pre();
142  pp->buildAttr(attr);
143  }
144  void objtypeParser::onEnd(const char *el,parser* child)
145  {
146  DEBTRACE( "objtypeParser::onEnd: " << el )
147  std::string element(el);
148  if(element == "base")base(((stringtypeParser*)child)->post());
149  }
151  {
152  if (!attr)
153  return;
154  required("name",attr);
155  for (int i = 0; attr[i]; i += 2)
156  {
157  if(std::string(attr[i]) == "name")name(attr[i+1]);
158  if(std::string(attr[i]) == "id")id(attr[i+1]);
159  }
160  }
162  {
163  _id="";
164  _ltc.clear();
165  }
166  void objtypeParser::name(const std::string& name)
167  {
168  DEBTRACE( "objtype_name: " << name )
169  _name=name;
170  }
171  void objtypeParser::id(const std::string& name)
172  {
173  DEBTRACE( "objtype_id: " << name )
174  _id=name;
175  }
176  void objtypeParser::base(const std::string& name)
177  {
178  DEBTRACE( "base_name: " << name )
179  if(currentProc->typeMap.count(name)==0)
180  {
181  //Check if the typecode is defined in the runtime
183  if(t==0)
184  {
185  std::stringstream msg;
186  msg << "Type " << name << " does not exist" << " (" <<__FILE__ << ":" << __LINE__ << ")";
187  throw Exception(msg.str());
188  }
189  else
190  {
192  t->incrRef();
193  }
194  }
195  if(currentProc->typeMap[name]->kind() != ENGINE::Objref)
196  {
197  std::stringstream msg;
198  msg << "Type " << name << " is not an objref" ;
199  msg << " (" <<__FILE__ << ":" << __LINE__ << ")";
200  throw Exception(msg.str());
201  }
203  }
205  {
206  DEBTRACE( "objtype_post" )
208  return t;
209  }
210 
212  {
213  if (!attr)
214  return;
215  required("name",attr);
216  required("type",attr);
217  for (int i = 0; attr[i]; i += 2)
218  {
219  if(std::string(attr[i]) == "name")name(attr[i+1]);
220  if(std::string(attr[i]) == "type")type(attr[i+1]);
221  }
222  }
223  void membertypeParser::name(const std::string& name){ _prop._name=name; }
224  void membertypeParser::type(const std::string& name){ _prop._value=name; }
226 
227  void structtypeParser::onStart(const XML_Char* el, const XML_Char** attr)
228  {
229  DEBTRACE( "structtypeParser::onStart: " << el )
230  std::string element(el);
232  if(element == "member")pp=&membertypeParser::memberParser;
233  SetUserDataAndPush(pp);
234  pp->init();
235  pp->pre();
236  pp->buildAttr(attr);
237  }
238  void structtypeParser::onEnd(const char *el,parser* child)
239  {
240  DEBTRACE( "structtypeParser::onEnd: " << el )
241  std::string element(el);
242  if(element == "member")member(((membertypeParser*)child)->post());
243  }
245  {
246  if (!attr)
247  return;
248  required("name",attr);
249  for (int i = 0; attr[i]; i += 2)
250  {
251  if(std::string(attr[i]) == "name")name(attr[i+1]);
252  if(std::string(attr[i]) == "id")id(attr[i+1]);
253  }
254  }
256  {
257  _id="";
258  _members.clear();
259  }
260  void structtypeParser::name(const std::string& name)
261  {
262  DEBTRACE( "structtype_name: " << name );
263  _name=name;
264  }
265  void structtypeParser::id(const std::string& name)
266  {
267  DEBTRACE( "structtype_id: " << name );
268  _id=name;
269  }
270  void structtypeParser::member (const myprop& prop)
271  {
272  DEBTRACE( "structtype_member: " << prop._name << prop._value );
273  if(currentProc->typeMap.count(prop._value)==0)
274  {
275  //Check if the typecode is defined in the runtime
277  if(t==0)
278  {
279  std::string msg="Unknown type " + prop._value + " for member " + prop._name + " in struct " + _name;
280  throw Exception(msg);
281  }
282  else
283  {
284  currentProc->typeMap[prop._value]=t;
285  t->incrRef();
286  }
287  }
288 
289  _members.push_back(prop);
290  }
292  {
293  DEBTRACE( "structtype_post" );
295  if(currentProc->typeMap.count(_name)!=0)
296  {
297  //reuse a forward declaration
299  if(tt->kind()==YACS::ENGINE::Struct)
300  {
302  }
303  else
304  {
305  std::string msg="Forward declaration must be a struct type but " + std::string(tt->name()) + " is not one" ;
306  throw Exception(msg);
307  }
308  }
309  else
310  {
312  }
313  std::vector<myprop>::const_iterator iter;
314  for(iter=_members.begin();iter!=_members.end();iter++)
315  {
316  DEBTRACE("member: " << iter->_name << " " <<iter->_value);
317  t->addMember(iter->_name,currentProc->typeMap[iter->_value]);
318  }
319  return t;
320  }
321 }
322 
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
Base class for all schema objects.
Definition: Proc.hxx:44
virtual TypeCode * createSequenceTc(const std::string &id, const std::string &name, TypeCode *content)
Create a sequence TypeCode.
Definition: Proc.cxx:150
std::map< std::string, TypeCode * > typeMap
Definition: Proc.hxx:90
virtual TypeCode * createStructTc(const std::string &id, const std::string &name)
Definition: Proc.cxx:161
virtual TypeCode * createInterfaceTc(const std::string &id, const std::string &name, std::list< TypeCodeObjref * > ltc)
Create an object reference TypeCode.
Definition: Proc.cxx:132
virtual TypeCode * getTypeCode(const std::string &name)
Get a typecode by its name from runtime catalogs.
Definition: Runtime.cxx:333
Class for reference objects.
Definition: TypeCode.hxx:126
Class for struct type.
Definition: TypeCode.hxx:228
Base class for all type objects.
Definition: TypeCode.hxx:68
virtual const char * name() const
Definition: TypeCode.cxx:72
DynType kind() const
Definition: TypeCode.cxx:47
char XML_Char
Definition: parserBase.hxx:37
Class for member parser.
virtual void name(const std::string &name)
virtual void buildAttr(const XML_Char **attr)
virtual void type(const std::string &name)
static membertypeParser memberParser
virtual void onStart(const XML_Char *el, const XML_Char **attr)
virtual void base(const std::string &name)
virtual void pre()
virtual void buildAttr(const XML_Char **attr)
virtual void name(const std::string &name)
virtual void id(const std::string &name)
virtual YACS::ENGINE::TypeCode * post()
static objtypeParser objParser
std::list< YACS::ENGINE::TypeCodeObjref * > _ltc
virtual void onEnd(const char *el, parser *child)
virtual void init()
Definition: parserBase.cxx:86
virtual void pre()
Definition: parserBase.hxx:61
virtual void SetUserDataAndPush(parser *pp)
Definition: parserBase.cxx:55
virtual void required(const std::string &name, const XML_Char **attr)
Definition: parserBase.cxx:186
virtual void buildAttr(const XML_Char **attr)
Definition: parserBase.cxx:195
static parser main_parser
Definition: parserBase.hxx:41
YACS::ENGINE::TypeCode * _contentType
Definition: typeParsers.hxx:78
virtual void buildAttr(const XML_Char **attr)
Definition: typeParsers.cxx:87
void content(const std::string &name)
void name(const std::string &name)
Definition: typeParsers.cxx:99
YACS::ENGINE::TypeCode * post()
static seqtypeParser seqParser
Definition: typeParsers.hxx:71
virtual void onStart(const XML_Char *el, const XML_Char **attr)
Definition: typeParsers.cxx:74
virtual void onEnd(const char *el, parser *child)
Definition: typeParsers.cxx:83
Class for string parser.
Definition: dataParsers.hxx:32
static stringtypeParser stringParser
Definition: dataParsers.hxx:33
virtual void onEnd(const char *el, parser *child)
virtual void onStart(const XML_Char *el, const XML_Char **attr)
virtual void member(const myprop &prop)
virtual YACS::ENGINE::TypeCode * post()
static structtypeParser structParser
virtual void name(const std::string &name)
virtual void id(const std::string &name)
virtual void buildAttr(const XML_Char **attr)
std::vector< myprop > _members
static typetypeParser typeParser
Definition: typeParsers.hxx:45
virtual void name(const std::string &name)
Definition: typeParsers.cxx:55
virtual void buildAttr(const XML_Char **attr)
Definition: typeParsers.cxx:42
virtual mytype post()
Definition: typeParsers.cxx:65
virtual void pre()
Definition: typeParsers.cxx:54
virtual void kind(const std::string &name)
Definition: typeParsers.cxx:60
std::string _name
Definition: factory.hxx:96
std::string _value
Definition: factory.hxx:97
YACS::ENGINE::Runtime * theRuntime
Definition: parsers.cxx:40
YACS::ENGINE::Proc * currentProc
Definition: parserBase.cxx:30