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