Refactoring of ScilabException in AST, exec, execstr.
[scilab.git] / scilab / modules / abstractSyntaxTree / includes / run_OpExp.hxx
1 /*
2 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 *  Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
4 *  Copyright (C) 2010-2010 - DIGITEO - Bruno JOFRET
5 *
6 *  This file must be used under the terms of the CeCILL.
7 *  This source file is licensed as described in the file COPYING, which
8 *  you should have received as part of this distribution.  The terms
9 *  are also available at
10 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11 *
12 */
13
14 // This code is separated in run_AssignExp.hxx
15 // but will be inlined in runvisitor.hxx
16 // using #include with RunVisitorT class declaration.
17 //
18 // If you need additionnal headers, please add it in runvisitor.hxx
19
20 void visitprivate(const OpExp &e)
21 {
22     T execMeL;
23     T execMeR;
24
25     try
26     {
27
28         /*getting what to assign*/
29         e.left_get().accept(execMeL);
30         /*getting what to assign*/
31         e.right_get().accept(execMeR);
32
33         InternalType *pITL          = execMeL.result_get();
34         InternalType *pITR          = execMeR.result_get();
35         GenericType::RealType TypeL = pITL->getType();
36         GenericType::RealType TypeR = pITR->getType();
37
38         if(TypeL == GenericType::RealImplicitList)
39         {
40             ImplicitList* pIL = pITL->getAsImplicitList();
41             if(pIL->isComputable())
42             {
43                 pITL = pIL->extractFullMatrix();
44                 TypeL = pITL->getType();
45             }
46         }
47
48         if(TypeR == GenericType::RealImplicitList)
49         {
50             ImplicitList* pIL = pITR->getAsImplicitList();
51             if(pIL->isComputable())
52             {
53                 pITR = pIL->extractFullMatrix();
54                 TypeR = pITR->getType();
55             }
56         }
57
58         InternalType *pResult   = NULL;
59
60         switch(e.oper_get())
61         {
62         case OpExp::plus :
63             {
64                 try
65                 {
66                     pResult = GenericPlus(pITL, pITR);
67                 }
68                 catch (ScilabException *pSE)
69                 {
70                     pSE->SetErrorLocation(e.right_get().location_get());
71                     throw pSE;
72                 }
73
74                 if (pResult == NULL)
75                 {
76                     // We did not have any algorithm matching, so we try to call OverLoad
77                     pResult = callOverload(e.oper_get(), &execMeL, &execMeR);
78
79                 }
80
81                 result_set(pResult);
82                 break;
83             }
84         case OpExp::minus :
85             {
86                 try
87                 {
88                     pResult = GenericMinus(pITL, pITR);
89                 }
90                 catch (ScilabException *pSE)
91                 {
92                     pSE->SetErrorLocation(e.right_get().location_get());
93                     throw pSE;
94                 }
95
96                 if (pResult == NULL)
97                 {
98                     // We did not have any algorithm matching, so we try to call OverLoad
99                     pResult = callOverload(e.oper_get(), &execMeL, &execMeR);
100
101                 }
102
103                 result_set(pResult);
104                 break;
105             }
106         case OpExp::times:
107             {
108                 try
109                 {
110                     pResult = GenericTimes(pITL, pITR);
111                 }
112                 catch (ScilabException *pSE)
113                 {
114                     pSE->SetErrorLocation(e.right_get().location_get());
115                     throw pSE;
116                 }
117
118                 if (pResult == NULL)
119                 {
120                     // We did not have any algorithm matching, so we try to call OverLoad
121                     pResult = callOverload(e.oper_get(), &execMeL, &execMeR);
122
123                 }
124                 result_set(pResult);
125                 break;
126             }
127         case OpExp::rdivide:
128             {
129                 try
130                 {
131                     pResult = GenericRDivide(pITL, pITR);
132                 }
133                 catch (ScilabException *pSE)
134                 {
135                     pSE->SetErrorLocation(e.right_get().location_get());
136                     throw pSE;
137                 }
138
139                 if (pResult == NULL)
140                 {
141                     // We did not have any algorithm matching, so we try to call OverLoad
142                     pResult = callOverload(e.oper_get(), &execMeL, &execMeR);
143
144                 }
145                 result_set(pResult);
146                 break;
147             }
148         case OpExp::dottimes :
149             {
150                 try
151                 {
152                     pResult = GenericDotTimes(execMeL.result_get(), execMeR.result_get());
153                 }
154                 catch (ScilabException *pSE)
155                 {
156                     pSE->SetErrorLocation(e.right_get().location_get());
157                     throw pSE;
158                 }
159
160                 if (pResult == NULL)
161                 {
162                     // We did not have any algorithm matching, so we try to call OverLoad
163                     pResult = callOverload(e.oper_get(), &execMeL, &execMeR);
164
165                 }
166                 result_set(pResult);
167                 break;
168             }
169         case OpExp::eq :
170             {
171                 if(TypeL == GenericType::RealDouble && pITL->getAs<Double>()->getSize() == 0)
172                 {//[] == xx
173                     if(TypeR != InternalType::RealDouble)
174                     {
175                         result_set(new Bool(false));
176                         return;
177                     }
178                 }
179
180                 if(TypeR == GenericType::RealDouble && pITR->getAs<Double>()->getSize() == 0)
181                 {//xx == []
182                     if(TypeL != InternalType::RealDouble)
183                     {
184                         result_set(new Bool(false));
185                         return;
186                     }
187                 }
188
189                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
190                 {
191                     Double *pL                  = pITL->getAs<Double>();
192                     Double *pR                  = pITR->getAs<Double>();
193
194                     if(pR->getSize() == 0 && pL->getSize() == 0)
195                     {
196                         pResult = new Bool(true);
197                     }
198                     else if(pL->getSize() == 0  || pR->getSize() == 0)
199                     {
200                         pResult = new Bool(false);
201                     }
202                     else if(pR->getSize() == 1)
203                     {
204                         pResult                         = new Bool(pL->getRows(), pL->getCols());
205                         double dblRef   = pR->getReal(0,0);
206                         for(int i = 0 ; i < pL->getRows() ; i++)
207                         {
208                             for(int j = 0 ; j < pL->getCols() ; j++)
209                             {
210                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) == dblRef);
211                             }
212                         }
213                     }
214                     else if(pL->getSize() == 1)
215                     {
216                         pResult                         = new Bool(pR->getRows(), pR->getCols());
217                         double dblRef   = pL->getReal(0,0);
218                         for(int i = 0 ; i < pR->getRows() ; i++)
219                         {
220                             for(int j = 0 ; j < pR->getCols() ; j++)
221                             {
222                                 pResult->getAs<types::Bool>()->set(i, j, dblRef == pR->getReal(i, j));
223                             }
224                         }
225                     }
226                     else if(pR->getRows() == pL->getRows() && pR->getCols() == pL->getCols())
227                     {
228                         pResult                         = new Bool(pR->getRows(), pR->getCols());
229                         for(int i = 0 ; i < pR->getRows() ; i++)
230                         {
231                             for(int j = 0 ; j < pR->getCols() ; j++)
232                             {
233                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) == pR->getReal(i, j));
234                             }
235                         }
236                     }
237                     else
238                     {
239                         pResult = new Bool(false);
240                     }
241
242                     result_set(pResult);
243                 }
244                 else if(TypeL == GenericType::RealString && TypeR == GenericType::RealString)
245                 {
246                     String *pL                  = pITL->getAs<types::String>();
247                     String *pR                  = pITR->getAs<types::String>();
248
249                     if(pL->getSize() == 1)
250                     {
251                         pResult = new Bool(pR->getRows(), pR->getCols());
252
253                         wchar_t* pstL = pL->get()[0];
254                         for(int i = 0 ; i < pR->getRows() ; i++)
255                         {
256                             for(int j = 0 ; j < pR->getCols() ; j++)
257                             {
258                                 wchar_t* pstR = pR->get(i,j);
259                                 if(wcscmp(pstL, pstR) == 0)
260                                 {
261                                     pResult->getAs<types::Bool>()->set(i,j,true);
262                                 }
263                                 else
264                                 {
265                                     pResult->getAs<types::Bool>()->set(i,j,false);
266                                 }
267                             }
268                         }
269                     }
270                     else if(pR->getSize() == 1)
271                     {
272                         pResult = new Bool(pL->getRows(), pL->getCols());
273
274                         wchar_t* pstR = pR->get()[0];
275                         for(int i = 0 ; i < pL->getRows() ; i++)
276                         {
277                             for(int j = 0 ; j < pL->getCols() ; j++)
278                             {
279                                 wchar_t* pstL = pL->get(i,j);
280                                 if(wcscmp(pstL, pstR) == 0)
281                                 {
282                                     pResult->getAs<types::Bool>()->set(i,j,true);
283                                 }
284                                 else
285                                 {
286                                     pResult->getAs<types::Bool>()->set(i,j,false);
287                                 }
288                             }
289                         }
290                     }
291                     else if(pL->getRows() == pR->getRows() && pL->getCols() == pR->getCols())
292                     {
293                         pResult = new Bool(pL->getRows(), pL->getCols());
294
295                         for(int i = 0 ; i < pL->getRows() ; i++)
296                         {
297                             for(int j = 0 ; j < pL->getCols() ; j++)
298                             {
299                                 wchar_t* pstR = pR->get(i,j);
300                                 wchar_t* pstL = pL->get(i,j);
301                                 if(wcscmp(pstL, pstR) == 0)
302                                 {
303                                     pResult->getAs<types::Bool>()->set(i,j,true);
304                                 }
305                                 else
306                                 {
307                                     pResult->getAs<types::Bool>()->set(i,j,false);
308                                 }
309                             }
310                         }
311                     }
312                     else
313                     {
314                         pResult = new Bool(false);
315                     }
316                     result_set(pResult);
317                 }
318                 else if(TypeL == GenericType::RealBool && TypeR == GenericType::RealBool)
319                 {
320                     Bool *pL                    = pITL->getAs<types::Bool>();
321                     Bool *pR                    = pITR->getAs<types::Bool>();
322
323                     if(pL->getSize() == 1)
324                     {
325                         pResult = new Bool(pR->getRows(), pR->getCols());
326
327                         int iL = pL->get()[0];
328                         for(int i = 0 ; i < pR->getRows() ; i++)
329                         {
330                             for(int j = 0 ; j < pR->getCols() ; j++)
331                             {
332                                 if(iL == pR->get(i,j))
333                                 {
334                                     pResult->getAs<types::Bool>()->set(i,j,true);
335                                 }
336                                 else
337                                 {
338                                     pResult->getAs<types::Bool>()->set(i,j,false);
339                                 }
340                             }
341                         }
342                     }
343                     else if(pR->getSize() == 1)
344                     {
345                         pResult = new Bool(pL->getRows(), pL->getCols());
346
347                         int iR = pR->get()[0];
348                         for(int i = 0 ; i < pL->getRows() ; i++)
349                         {
350                             for(int j = 0 ; j < pL->getCols() ; j++)
351                             {
352                                 if(iR == pL->get(i,j))
353                                 {
354                                     pResult->getAs<types::Bool>()->set(i,j,true);
355                                 }
356                                 else
357                                 {
358                                     pResult->getAs<types::Bool>()->set(i,j,false);
359                                 }
360                             }
361                         }
362                     }
363                     else if(pL->getRows() == pR->getRows() && pL->getCols() == pR->getCols())
364                     {
365                         pResult = new Bool(pL->getRows(), pL->getCols());
366
367                         for(int i = 0 ; i < pL->getRows() ; i++)
368                         {
369                             for(int j = 0 ; j < pL->getCols() ; j++)
370                             {
371                                 if(pL->get(i,j) == pR->get(i,j))
372                                 {
373                                     pResult->getAs<types::Bool>()->set(i,j,true);
374                                 }
375                                 else
376                                 {
377                                     pResult->getAs<types::Bool>()->set(i,j,false);
378                                 }
379                             }
380                         }
381                     }
382                     else
383                     {
384                         pResult = new Bool(false);
385                     }
386                     result_set(pResult);
387                 }
388                 else
389                 {
390                     result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
391                 }
392                 break;
393             }
394         case OpExp::ne :
395             {
396                 if(TypeL == GenericType::RealDouble && pITL->getAs<Double>()->getSize() == 0)
397                 {//[] <> xx
398                     if(TypeR != InternalType::RealDouble)
399                     {
400                         result_set(new Bool(true));
401                         return;
402                     }
403                 }
404
405                 if(TypeR == GenericType::RealDouble && pITR->getAs<Double>()->getSize() == 0)
406                 {//xx <> []
407                     if(TypeL != InternalType::RealDouble)
408                     {
409                         result_set(new Bool(true));
410                         return;
411                     }
412                 }
413
414                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
415                 {
416                     Double *pL                  = pITL->getAs<Double>();
417                     Double *pR                  = pITR->getAs<Double>();
418
419                     if(pR->getSize() == 0 && pL->getSize() == 0)
420                     {
421                         pResult = new Bool(false);
422                     }
423                     else if(pL->getSize() == 0  || pR->getSize() == 0)
424                     {
425                         pResult = new Bool(true);
426                     }
427                     else if(pR->getSize() == 1)
428                     {
429                         pResult                         = new Bool(pL->getRows(), pL->getCols());
430                         double dblRef   = pR->getReal(0,0);
431                         for(int i = 0 ; i < pL->getRows() ; i++)
432                         {
433                             for(int j = 0 ; j < pL->getCols() ; j++)
434                             {
435                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) != dblRef);
436                             }
437                         }
438                     }
439                     else if(pL->getSize() == 1)
440                     {
441                         pResult                         = new Bool(pR->getRows(), pR->getCols());
442                         double dblRef   = pL->getReal(0,0);
443                         for(int i = 0 ; i < pR->getRows() ; i++)
444                         {
445                             for(int j = 0 ; j < pR->getCols() ; j++)
446                             {
447                                 pResult->getAs<types::Bool>()->set(i, j, dblRef != pR->getReal(i, j));
448                             }
449                         }
450                     }
451                     else if(pR->getRows() == pL->getRows() && pR->getCols() == pL->getCols())
452                     {
453                         pResult                         = new Bool(pR->getRows(), pR->getCols());
454                         for(int i = 0 ; i < pR->getRows() ; i++)
455                         {
456                             for(int j = 0 ; j < pR->getCols() ; j++)
457                             {
458                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) != pR->getReal(i, j));
459                             }
460                         }
461                     }
462                     else
463                     {
464                         pResult = new Bool(false);
465                     }
466
467                     result_set(pResult);
468                 }
469                 else if(TypeL == GenericType::RealString && TypeR == GenericType::RealString)
470                 {
471                     String *pL                  = pITL->getAs<types::String>();
472                     String *pR                  = pITR->getAs<types::String>();
473
474                     if(pL->getSize() == 1)
475                     {
476                         pResult = new Bool(pR->getRows(), pR->getCols());
477
478                         wchar_t* pstL = pL->get()[0];
479                         for(int i = 0 ; i < pR->getRows() ; i++)
480                         {
481                             for(int j = 0 ; j < pR->getCols() ; j++)
482                             {
483                                 wchar_t* pstR = pR->get(i,j);
484                                 if(wcscmp(pstL, pstR) == 0)
485                                 {
486                                     pResult->getAs<types::Bool>()->set(i,j,false);
487                                 }
488                                 else
489                                 {
490                                     pResult->getAs<types::Bool>()->set(i,j,true);
491                                 }
492                             }
493                         }
494                     }
495                     else if(pR->getSize() == 1)
496                     {
497                         pResult = new Bool(pL->getRows(), pL->getCols());
498
499                         wchar_t* pstR = pR->get()[0];
500                         for(int i = 0 ; i < pL->getRows() ; i++)
501                         {
502                             for(int j = 0 ; j < pL->getCols() ; j++)
503                             {
504                                 wchar_t* pstL = pL->get(i,j);
505                                 if(wcscmp(pstL, pstR) == 0)
506                                 {
507                                     pResult->getAs<types::Bool>()->set(i,j,false);
508                                 }
509                                 else
510                                 {
511                                     pResult->getAs<types::Bool>()->set(i,j,true);
512                                 }
513                             }
514                         }
515                     }
516                     else if(pL->getRows() == pR->getRows() && pL->getCols() == pR->getCols())
517                     {
518                         pResult = new Bool(pL->getRows(), pL->getCols());
519
520                         for(int i = 0 ; i < pL->getRows() ; i++)
521                         {
522                             for(int j = 0 ; j < pL->getCols() ; j++)
523                             {
524                                 wchar_t* pstR = pR->get(i,j);
525                                 wchar_t* pstL = pL->get(i,j);
526                                 if(wcscmp(pstL, pstR) == 0)
527                                 {
528                                     pResult->getAs<types::Bool>()->set(i,j,false);
529                                 }
530                                 else
531                                 {
532                                     pResult->getAs<types::Bool>()->set(i,j,true);
533                                 }
534                             }
535                         }
536                     }
537                     else
538                     {
539                         pResult = new Bool(true);
540                     }
541                     result_set(pResult);
542                 }
543                 else
544                 {
545                     result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
546                 }
547                 break;
548             }
549         case OpExp::lt :
550             {
551                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
552                 {
553                     Double *pL                  = pITL->getAs<Double>();
554                     Double *pR                  = pITR->getAs<Double>();
555
556                     if(pR->getSize() == 1)
557                     {
558                         pResult                         = new Bool(pL->getRows(), pL->getCols());
559                         double dblRef   = pR->getReal(0,0);
560                         for(int i = 0 ; i < pL->getRows() ; i++)
561                         {
562                             for(int j = 0 ; j < pL->getCols() ; j++)
563                             {
564                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) < dblRef);
565                             }
566                         }
567                     }
568                     else if(pL->getSize() == 1)
569                     {
570                         pResult                         = new Bool(pR->getRows(), pR->getCols());
571                         double dblRef   = pL->getReal(0,0);
572                         for(int i = 0 ; i < pR->getRows() ; i++)
573                         {
574                             for(int j = 0 ; j < pR->getCols() ; j++)
575                             {
576                                 pResult->getAs<types::Bool>()->set(i, j, dblRef < pR->getReal(i, j));
577                             }
578                         }
579                     }
580                     else if(pR->getRows() == pL->getRows() && pR->getCols() == pL->getCols())
581                     {
582                         pResult                         = new Bool(pR->getRows(), pR->getCols());
583                         for(int i = 0 ; i < pR->getRows() ; i++)
584                         {
585                             for(int j = 0 ; j < pR->getCols() ; j++)
586                             {
587                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) < pR->getReal(i, j));
588                             }
589                         }
590                     }
591                     else
592                     {
593                         pResult = new Bool(false);
594                     }
595
596                     result_set(pResult);
597                 }
598                 else
599                 {
600                     result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
601                 }
602                 break;
603             }
604         case OpExp::le :
605             {
606                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
607                 {
608                     Double *pL                  = pITL->getAs<Double>();
609                     Double *pR                  = pITR->getAs<Double>();
610
611                     if(pR->getSize() == 1)
612                     {
613                         pResult                         = new Bool(pL->getRows(), pL->getCols());
614                         double dblRef   = pR->getReal(0,0);
615                         for(int i = 0 ; i < pL->getRows() ; i++)
616                         {
617                             for(int j = 0 ; j < pL->getCols() ; j++)
618                             {
619                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) <= dblRef);
620                             }
621                         }
622                     }
623                     else if(pL->getSize() == 1)
624                     {
625                         pResult                         = new Bool(pR->getRows(), pR->getCols());
626                         double dblRef   = pL->getReal(0,0);
627                         for(int i = 0 ; i < pR->getRows() ; i++)
628                         {
629                             for(int j = 0 ; j < pR->getCols() ; j++)
630                             {
631                                 pResult->getAs<types::Bool>()->set(i, j, dblRef <= pR->getReal(i, j));
632                             }
633                         }
634                     }
635                     else if(pR->getRows() == pL->getRows() && pR->getCols() == pL->getCols())
636                     {
637                         pResult                         = new Bool(pR->getRows(), pR->getCols());
638                         for(int i = 0 ; i < pR->getRows() ; i++)
639                         {
640                             for(int j = 0 ; j < pR->getCols() ; j++)
641                             {
642                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) <= pR->getReal(i, j));
643                             }
644                         }
645                     }
646                     else
647                     {
648                         pResult = new Bool(false);
649                     }
650
651                     result_set(pResult);
652                 }
653                 else
654                 {
655                     result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
656                 }
657                 break;
658             }
659         case OpExp::gt :
660             {
661                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
662                 {
663                     Double *pL                  = pITL->getAs<Double>();
664                     Double *pR                  = pITR->getAs<Double>();
665
666                     if(pR->getSize() == 1)
667                     {
668                         pResult                         = new Bool(pL->getRows(), pL->getCols());
669                         double dblRef   = pR->getReal(0,0);
670                         for(int i = 0 ; i < pL->getRows() ; i++)
671                         {
672                             for(int j = 0 ; j < pL->getCols() ; j++)
673                             {
674                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) > dblRef);
675                             }
676                         }
677                     }
678                     else if(pL->getSize() == 1)
679                     {
680                         pResult                         = new Bool(pR->getRows(), pR->getCols());
681                         double dblRef   = pL->getReal(0,0);
682                         for(int i = 0 ; i < pR->getRows() ; i++)
683                         {
684                             for(int j = 0 ; j < pR->getCols() ; j++)
685                             {
686                                 pResult->getAs<types::Bool>()->set(i, j, dblRef > pR->getReal(i, j));
687                             }
688                         }
689                     }
690                     else if(pR->getRows() == pL->getRows() && pR->getCols() == pL->getCols())
691                     {
692                         pResult                         = new Bool(pR->getRows(), pR->getCols());
693
694                         for(int i = 0 ; i < pR->getRows() ; i++)
695                         {
696                             for(int j = 0 ; j < pR->getCols() ; j++)
697                             {
698                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) > pR->getReal(i, j));
699                             }
700                         }
701                     }
702                     else
703                     {
704                         pResult = new Bool(false);
705                     }
706
707                     result_set(pResult);
708                 }
709                 else
710                 {
711                     result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
712                 }
713                 break;
714             }
715         case OpExp::ge :
716             {
717                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
718                 {
719                     Double *pL                  = pITL->getAs<Double>();
720                     Double *pR                  = pITR->getAs<Double>();
721
722                     if(pR->getSize() == 1)
723                     {
724                         pResult                         = new Bool(pL->getRows(), pL->getCols());
725                         double dblRef   = pR->getReal(0,0);
726                         for(int i = 0 ; i < pL->getRows() ; i++)
727                         {
728                             for(int j = 0 ; j < pL->getCols() ; j++)
729                             {
730                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) >= dblRef);
731                             }
732                         }
733                     }
734                     else if(pL->getSize() == 1)
735                     {
736                         pResult                         = new Bool(pR->getRows(), pR->getCols());
737                         double dblRef   = pL->getReal(0,0);
738                         for(int i = 0 ; i < pR->getRows() ; i++)
739                         {
740                             for(int j = 0 ; j < pR->getCols() ; j++)
741                             {
742                                 pResult->getAs<types::Bool>()->set(i, j, dblRef >= pR->getReal(i, j));
743                             }
744                         }
745                     }
746                     else if(pR->getRows() == pL->getRows() && pR->getCols() == pL->getCols())
747                     {
748                         pResult                         = new Bool(pR->getRows(), pR->getCols());
749                         for(int i = 0 ; i < pR->getRows() ; i++)
750                         {
751                             for(int j = 0 ; j < pR->getCols() ; j++)
752                             {
753                                 pResult->getAs<types::Bool>()->set(i, j, pL->getReal(i, j) >= pR->getReal(i, j));
754                             }
755                         }
756                     }
757                     else
758                     {
759                         pResult = new Bool(false);
760                     }
761
762                     result_set(pResult);
763                 }
764                 else
765                 {
766                     result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
767                 }
768                 break;
769             }
770         case OpExp::power :
771             {
772                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
773                 {
774                     Double *pL                  = pITL->getAs<Double>();
775                     Double *pR                  = pITR->getAs<Double>();
776
777                     int iResult = PowerDoubleByDouble(pL, pR, (Double**)&pResult);
778                     if(iResult != 0)
779                     {
780                         std::wostringstream os;
781                         os << _W("Inconsistent row/column dimensions.\n");
782                         //os << ((Location)e.right_get().location_get()).location_getString() << std::endl;
783                         throw ScilabError(os.str(), 999, e.right_get().location_get());
784                     }
785                     result_set(pResult);
786                 }
787                 else if(TypeL == GenericType::RealPoly && TypeR == GenericType::RealDouble)
788                 {
789                     Polynom *pL = pITL->getAs<types::Polynom>();
790                     Double *pR                  = pITR->getAs<Double>();
791
792                     int iResult = PowerPolyByDouble(pL, pR, (Polynom**)&pResult);
793                     if(iResult != 0)
794                     {
795                         std::wostringstream os;
796                         os << _W("Inconsistent row/column dimensions.\n");
797                         //os << ((Location)e.right_get().location_get()).location_getString() << std::endl;
798                         throw ScilabError(os.str(), 999, e.right_get().location_get());
799                     }
800                     result_set(pResult);
801                 }
802                 else
803                 {
804                     result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
805                 }
806                 break;
807             }
808         default :
809             // By default call overload if we do not know this operator ...
810             result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
811             break;
812         }
813     }
814     catch(ScilabError error)
815     {
816         error.SetErrorLocation(e.location_get());
817         throw error;
818     }
819 }
820
821 void visitprivate(const LogicalOpExp &e)
822 {
823     T execMeL;
824     T execMeR;
825
826     e.left_get().accept(execMeL);
827     InternalType *pITL          = execMeL.result_get();
828     InternalType *pITR          = NULL;
829
830     GenericType::RealType TypeL = pITL->getType();
831     Bool *pL    = NULL;
832
833     if(TypeL == GenericType::RealBool)
834     {
835         pL      = pITL->getAs<types::Bool>();
836     }
837     else
838     {
839         //TODO YaSp : Overloading %*_oper_*
840         e.right_get().accept(execMeR);
841         switch(e.oper_get())
842         {
843         case LogicalOpExp::logicalShortCutOr :
844         case LogicalOpExp::logicalOr :
845             result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
846             break;
847         case LogicalOpExp::logicalShortCutAnd :
848         case LogicalOpExp::logicalAnd :
849             result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
850             break;
851         default :
852             break;
853         }
854         return;
855     }
856
857     InternalType *pResult = NULL;
858     switch(e.oper_get())
859     {
860     case LogicalOpExp::logicalShortCutOr :
861         {
862             Bool *pB    = pITL->getAs<types::Bool>();
863             int *piL    = pB->get();
864             bool iL     = true;
865             // Check if all values are true
866             // true || <something is always true>
867             for(int i = 0 ; i < pB->getSize() ; i++)
868             {
869                 if(piL[i] == false)
870                 {
871                     iL = false;
872                     break;
873                 }
874             }
875
876             if(iL)
877             {//we don't need to look at ohers exp
878                 pResult = new Bool(true);
879                 result_set(pResult);
880                 return;
881             }
882             // DO NOT break here, falling into normal Or if this can not be shotcutted.
883         }
884     case LogicalOpExp::logicalOr :
885         {
886             e.right_get().accept(execMeR);
887             pITR = execMeR.result_get();
888             GenericType::RealType TypeR = pITR->getType();
889
890             if(TypeR == GenericType::RealBool)
891             {
892                 Bool *pR        = pITR->getAs<types::Bool>();
893                 int* piR = pR->get();
894                 int* piL = pL->get();
895                 int* piB        = NULL;
896
897                 // M | scalar
898                 if(pR->getSize() == 1)
899                 {
900                     pResult = new Bool(pL->getRows(), pL->getCols(), &piB);
901                     for(int i = 0 ; i < pL->getSize(); i++)
902                     {
903                         piB[i] = (piR[0] == 1) || (piL[i] == 1);
904                     }
905                     result_set(pResult);
906                     return;
907                 }
908
909                 // scalar | M
910                 if(pL->getSize() == 1)
911                 {
912                     pResult = new Bool(pR->getRows(), pR->getCols(), &piB);
913                     for(int i = 0 ; i < pR->getSize(); i++)
914                     {
915                         piB[i] = (piR[i] == 1) || (piL[0] == 1);
916                     }
917                     result_set(pResult);
918                     return;
919                 }
920
921                 // M | N (generic case)
922                 if(pR->getRows() == pL->getRows() && pR->getCols() == pL->getCols())
923                 {
924                     pResult = new Bool(pR->getRows(), pR->getCols(), &piB);
925                     for(int i = 0 ; i < pL->getSize(); i++)
926                     {
927                         piB[i] = (piR[i] == 1) || (piL[i] == 1);
928                     }
929                     result_set(pResult);
930                 }
931                 else
932                 {
933                     std::wostringstream os;
934                     os << _W("Inconsistent row/column dimensions.\n");
935                     //os << ((Location)e.right_get().location_get()).location_getString() << std::endl;
936                     throw ScilabError(os.str(), 999, e.right_get().location_get());
937                 }
938             }
939             else
940             {
941                 result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
942             }
943             break;
944         }
945     case LogicalOpExp::logicalShortCutAnd :
946         {
947             Bool *pB    = pITL->getAs<types::Bool>();
948             int *piL    = pB->get();
949             // Check if one value is false
950             // false && <something> is always false
951             for(int i = 0 ; i < pB->getSize() ; i++)
952             {
953                 if(piL[i] == false)
954                 {
955                     pResult = new Bool(false);
956                     result_set(pResult);
957                     return;
958                 }
959             }
960             // DO NOT break here, falling into normal And if this can not be shotcutted.
961         }
962     case LogicalOpExp::logicalAnd :
963         {
964             e.right_get().accept(execMeR);
965             pITR = execMeR.result_get();
966             GenericType::RealType TypeR = pITR->getType();
967
968             if(TypeR == GenericType::RealBool)
969             {
970                 Bool *pR        = pITR->getAs<types::Bool>();
971                 int* piR = pR->get();
972                 int* piL = pL->get();
973                 int* piB        = NULL;
974
975                 // M & scalar
976                 if(pR->getSize() == 1)
977                 {
978                     pResult = new Bool(pL->getRows(), pL->getCols(), &piB);
979                     for(int i = 0 ; i < pL->getSize(); i++)
980                     {
981                         piB[i] = (piR[0] == 1) && (piL[i] == 1);
982                     }
983                     result_set(pResult);
984                     return;
985                 }
986
987                 // scalar & M
988                 if(pL->getSize() == 1)
989                 {
990                     pResult = new Bool(pR->getRows(), pR->getCols(), &piB);
991                     for(int i = 0 ; i < pR->getSize(); i++)
992                     {
993                         piB[i] = (piR[i] == 1) && (piL[0] == 1);
994                     }
995                     result_set(pResult);
996                     return;
997                 }
998
999                 // M & N (generic case)
1000                 if(pR->getRows() == pL->getRows() && pR->getCols() == pL->getCols())
1001                 {
1002                     pResult = new Bool(pR->getRows(), pR->getCols(), &piB);
1003                     for(int i = 0 ; i < pL->getSize(); i++)
1004                     {
1005                         piB[i] = (piR[i] == 1) && (piL[i] == 1);
1006                     }
1007                     result_set(pResult);
1008                 }
1009                 else
1010                 {
1011                     std::wostringstream os;
1012                     os << _W("Inconsistent row/column dimensions.\n");
1013                     //os << ((Location)e.right_get().location_get()).location_getString() << std::endl;
1014                     throw ScilabError(os.str(), 999, e.right_get().location_get());
1015                 }
1016             }
1017             else
1018             {
1019                 result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
1020             }
1021             break;
1022         }
1023
1024     default :
1025         {
1026             result_set(callOverload(e.oper_get(), &execMeL, &execMeR));
1027             break;
1028         }
1029     }
1030 }
1031
1032 InternalType* callOverload(OpExp::Oper _oper, T *_paramL, T *_paramR)
1033 {
1034     T execMe;
1035     types::typed_list in;
1036     types::typed_list out;
1037     _paramL->result_get()->IncreaseRef();
1038     _paramR->result_get()->IncreaseRef();
1039     in.push_back(_paramL->result_get());
1040     in.push_back(_paramR->result_get());
1041
1042     Overload::generateNameAndCall(Overload::getNameFromOper(_oper), in, 1, out, &execMe);
1043     if(out[0] != NULL)
1044     {
1045         out[0]->IncreaseRef();
1046     }
1047     _paramL->result_get()->DecreaseRef();
1048     _paramR->result_get()->DecreaseRef();
1049     return out[0];
1050 }