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