identificateur.cc
42.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
// -*- mode:C++ ; compile-command: "g++-3.4 -I. -I.. -I../include -DHAVE_CONFIG_H -DIN_GIAC -g -c -Wall identificateur.cc" -*-
#include "giacPCH.h"
/*
* Copyright (C) 2000,14 B. Parisse, Institut Fourier, 38402 St Martin d'Heres
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using namespace std;
#include <cmath>
#include <fstream>
#include <string>
//#include <unistd.h> // For reading arguments from file
#include "identificateur.h"
#include "gen.h"
#include "sym2poly.h"
#include "rpn.h"
#include "prog.h"
#include "usual.h"
#include "giacintl.h"
#ifdef BESTA_OS
// Local replacement for strdup on BESTA OS.
static char* strdup(char* str)
{
if ( ! str )
{
return str;
}
int len = strlen(str) + 2;
char* p = new char[len];
strcpy(p, str);
return p;
}
#endif
#ifndef NO_NAMESPACE_GIAC
namespace giac {
#endif // ndef NO_NAMESPACE_GIAC
// bool variables_are_files=true; // FIXME -> false and change rpn.cc at_VARS
int protection_level=0; // for local variables in null context
struct int_string_shortint_bool {
int i;
const char * s;
short int b;
bool s_dynalloc;
};
struct alias_identificateur {
int * ref_count;
gen * value;
const char * id_name;
vecteur * localvalue;
short int * quoted;
};
#ifdef DOUBLEVAL // #ifdef GIAC_GENERIC_CONSTANTS
const char string_euler_gamma[]="euler_gamma";
identificateur _IDNT_euler_gamma(string_euler_gamma,(double) .577215664901533);
gen cst_euler_gamma(_IDNT_euler_gamma);
const char string_pi[]="pi";
identificateur & _IDNT_pi(){
static identificateur * ans=new identificateur(string_pi,(double) M_PI);
return * ans;
}
// identificateur _IDNT_pi(string_pi,(double) M_PI);
alias_ref_identificateur ref_pi={-1,0,0,string_pi,0,0};
gen cst_pi(_IDNT_pi());
const char string_infinity[]="infinity";
identificateur & _IDNT_infinity(){
static identificateur * ans=new identificateur("infinity");
return * ans;
}
gen unsigned_inf(_IDNT_infinity());
alias_gen & alias_unsigned_inf = *(alias_gen *) & unsigned_inf;
alias_ref_identificateur ref_infinity={-1,0,0,string_infinity,0,0};
const char string_undef[]="undef";
identificateur & _IDNT_undef(){
static identificateur * ans=new identificateur("undef");
return * ans;
}
gen undef(_IDNT_undef());
#else
const char string_euler_gamma[]="euler_gamma";
static const alias_ref_identificateur ref_euler_gamma={-1,0,0,string_euler_gamma,0,0};
const define_alias_gen(alias_cst_euler_gamma,_IDNT,0,&ref_euler_gamma);
const gen & cst_euler_gamma = * (gen *) & alias_cst_euler_gamma;
const char string_pi[]="pi";
static const alias_identificateur alias_identificateur_pi={0,0,string_pi,0,0};
const identificateur & _IDNT_pi(){
return *(const identificateur *) & alias_identificateur_pi;
}
const alias_ref_identificateur ref_pi={-1,0,0,string_pi,0,0};
const define_alias_gen(alias_cst_pi,_IDNT,0,&ref_pi);
const gen & cst_pi = * (gen *) & alias_cst_pi;
const char string_infinity[]="infinity";
static const alias_identificateur alias_identificateur_infinity={0,0,string_infinity,0,0};
const identificateur & _IDNT_infinity(){
return * (const identificateur *) &alias_identificateur_infinity;
}
const alias_ref_identificateur ref_infinity={-1,0,0,string_infinity,0,0};
const define_alias_gen(alias_unsigned_inf,_IDNT,0,&ref_infinity);
const gen & unsigned_inf = * (gen *) & alias_unsigned_inf;
const char string_undef[]="undef";
static const alias_identificateur alias_identificateur_undef={0,0,string_undef,0,0};
const identificateur & _IDNT_undef(){
return * (const identificateur *) &alias_identificateur_undef;
}
static const alias_ref_identificateur ref_undef={-1,0,0,string_undef,0,0};
const define_alias_gen(alias_undef,_IDNT,0,&ref_undef);
const gen & undef = * (gen *) & alias_undef;
#endif // GIAC_GENERIC_CONSTANTS
#if defined GIAC_HAS_STO_38 || defined NSPIRE || defined NSPIRE_NEWLIB
#if 0
static const alias_identificateur alias_identificateur_a38={0,0,"A",0,0};
const identificateur & a__IDNT=* (const identificateur *) &alias_identificateur_a38;
const alias_ref_identificateur ref_a38={-1,0,0,"A",0,0};
const define_alias_gen(alias_a38,_IDNT,0,&ref_a38);
// const gen & a__IDNT_e = * (gen *) & alias_a38;
static const alias_identificateur alias_identificateur_b38={0,0,"B",0,0};
const identificateur & b__IDNT=* (const identificateur *) &alias_identificateur_b38;
const alias_ref_identificateur ref_b38={-1,0,0,"B",0,0};
const define_alias_gen(alias_b38,_IDNT,0,&ref_b38);
// const gen & b__IDNT_e = * (gen *) & alias_b38;
static const alias_identificateur alias_identificateur_c38={0,0,"C",0,0};
const identificateur & c__IDNT=* (const identificateur *) &alias_identificateur_c38;
const alias_ref_identificateur ref_c38={-1,0,0,"C",0,0};
const define_alias_gen(alias_c38,_IDNT,0,&ref_c38);
// const gen & c__IDNT_e = * (gen *) & alias_c38;
static const alias_identificateur alias_identificateur_d38={0,0,"D",0,0};
const identificateur & d__IDNT=* (const identificateur *) &alias_identificateur_d38;
const alias_ref_identificateur ref_d38={-1,0,0,"D",0,0};
const define_alias_gen(alias_d38,_IDNT,0,&ref_d38);
// const gen & d__IDNT_e = * (gen *) & alias_d38;
static const alias_identificateur alias_identificateur_e38={0,0,"E",0,0};
const identificateur & e__IDNT=* (const identificateur *) &alias_identificateur_e38;
const alias_ref_identificateur ref_e38={-1,0,0,"E",0,0};
const define_alias_gen(alias_e38,_IDNT,0,&ref_e38);
// const gen & e__IDNT_e = * (gen *) & alias_e38;
static const alias_identificateur alias_identificateur_f38={0,0,"F",0,0};
const identificateur & f__IDNT=* (const identificateur *) &alias_identificateur_f38;
const alias_ref_identificateur ref_f38={-1,0,0,"F",0,0};
const define_alias_gen(alias_f38,_IDNT,0,&ref_f38);
// const gen & f__IDNT_e = * (gen *) & alias_f38;
static const alias_identificateur alias_identificateur_g38={0,0,"G",0,0};
const identificateur & g__IDNT=* (const identificateur *) &alias_identificateur_g38;
const alias_ref_identificateur ref_g38={-1,0,0,"G",0,0};
const define_alias_gen(alias_g38,_IDNT,0,&ref_g38);
// const gen & g__IDNT_e = * (gen *) & alias_g38;
static const alias_identificateur alias_identificateur_h38={0,0,"H",0,0};
const identificateur & h__IDNT=* (const identificateur *) &alias_identificateur_h38;
const alias_ref_identificateur ref_h38={-1,0,0,"H",0,0};
const define_alias_gen(alias_h38,_IDNT,0,&ref_h38);
// const gen & h__IDNT_e = * (gen *) & alias_h38;
static const alias_identificateur alias_identificateur_i38={0,0,"I",0,0};
const identificateur & i__IDNT=* (const identificateur *) &alias_identificateur_i38;
const alias_ref_identificateur ref_i38={-1,0,0,"I",0,0};
const define_alias_gen(alias_i38,_IDNT,0,&ref_i38);
// const gen & i__IDNT_e = * (gen *) & alias_i38;
static const alias_identificateur alias_identificateur_j38={0,0,"J",0,0};
const identificateur & j__IDNT=* (const identificateur *) &alias_identificateur_j38;
const alias_ref_identificateur ref_j38={-1,0,0,"J",0,0};
const define_alias_gen(alias_j38,_IDNT,0,&ref_j38);
// const gen & j__IDNT_e = * (gen *) & alias_j38;
static const alias_identificateur alias_identificateur_k38={0,0,"K",0,0};
const identificateur & k__IDNT=* (const identificateur *) &alias_identificateur_k38;
const alias_ref_identificateur ref_k38={-1,0,0,"K",0,0};
const define_alias_gen(alias_k38,_IDNT,0,&ref_k38);
// const gen & k__IDNT_e = * (gen *) & alias_k38;
static const alias_identificateur alias_identificateur_l38={0,0,"L",0,0};
const identificateur & l__IDNT=* (const identificateur *) &alias_identificateur_l38;
const alias_ref_identificateur ref_l38={-1,0,0,"L",0,0};
const define_alias_gen(alias_l38,_IDNT,0,&ref_l38);
// const gen & l__IDNT_e = * (gen *) & alias_l38;
static const alias_identificateur alias_identificateur_m38={0,0,"M",0,0};
const identificateur & m__IDNT=* (const identificateur *) &alias_identificateur_m38;
const alias_ref_identificateur ref_m38={-1,0,0,"M",0,0};
const define_alias_gen(alias_m38,_IDNT,0,&ref_m38);
// const gen & m__IDNT_e = * (gen *) & alias_m38;
static const alias_identificateur alias_identificateur_n38={0,0,"N",0,0};
const identificateur & n__IDNT=* (const identificateur *) &alias_identificateur_n38;
const alias_ref_identificateur ref_n38={-1,0,0,"N",0,0};
const define_alias_gen(alias_n38,_IDNT,0,&ref_n38);
// const gen & n__IDNT_e = * (gen *) & alias_n38;
static const alias_identificateur alias_identificateur_o38={0,0,"O",0,0};
const identificateur & o__IDNT=* (const identificateur *) &alias_identificateur_o38;
const alias_ref_identificateur ref_o38={-1,0,0,"O",0,0};
const define_alias_gen(alias_o38,_IDNT,0,&ref_o38);
// const gen & o__IDNT_e = * (gen *) & alias_o38;
static const alias_identificateur alias_identificateur_p38={0,0,"P",0,0};
const identificateur & p__IDNT=* (const identificateur *) &alias_identificateur_p38;
const alias_ref_identificateur ref_p38={-1,0,0,"P",0,0};
const define_alias_gen(alias_p38,_IDNT,0,&ref_p38);
// const gen & p__IDNT_e = * (gen *) & alias_p38;
static const alias_identificateur alias_identificateur_q38={0,0,"Q",0,0};
const identificateur & q__IDNT=* (const identificateur *) &alias_identificateur_q38;
const alias_ref_identificateur ref_q38={-1,0,0,"Q",0,0};
const define_alias_gen(alias_q38,_IDNT,0,&ref_q38);
// const gen & q__IDNT_e = * (gen *) & alias_q38;
static const alias_identificateur alias_identificateur_r38={0,0,"R",0,0};
const identificateur & r__IDNT=* (const identificateur *) &alias_identificateur_r38;
const alias_ref_identificateur ref_r38={-1,0,0,"R",0,0};
const define_alias_gen(alias_r38,_IDNT,0,&ref_r38);
// const gen & r__IDNT_e = * (gen *) & alias_r38;
static const alias_identificateur alias_identificateur_s38={0,0,"S",0,0};
const identificateur & s__IDNT=* (const identificateur *) &alias_identificateur_s38;
const alias_ref_identificateur ref_s38={-1,0,0,"S",0,0};
const define_alias_gen(alias_s38,_IDNT,0,&ref_s38);
// const gen & s__IDNT_e = * (gen *) & alias_s38;
static const alias_identificateur alias_identificateur_t38={0,0,"T",0,0};
const identificateur & t__IDNT=* (const identificateur *) &alias_identificateur_t38;
const alias_ref_identificateur ref_t38={-1,0,0,"T",0,0};
const define_alias_gen(alias_t38,_IDNT,0,&ref_t38);
// const gen & t__IDNT_e = * (gen *) & alias_t38;
static const alias_identificateur alias_identificateur_u38={0,0,"U",0,0};
const identificateur & u__IDNT=* (const identificateur *) &alias_identificateur_u38;
const alias_ref_identificateur ref_u38={-1,0,0,"U",0,0};
const define_alias_gen(alias_u38,_IDNT,0,&ref_u38);
// const gen & u__IDNT_e = * (gen *) & alias_u38;
static const alias_identificateur alias_identificateur_v38={0,0,"V",0,0};
const identificateur & v__IDNT=* (const identificateur *) &alias_identificateur_v38;
const alias_ref_identificateur ref_v38={-1,0,0,"V",0,0};
const define_alias_gen(alias_v38,_IDNT,0,&ref_v38);
// const gen & v__IDNT_e = * (gen *) & alias_v38;
static const alias_identificateur alias_identificateur_w38={0,0,"W",0,0};
const identificateur & w__IDNT=* (const identificateur *) &alias_identificateur_w38;
const alias_ref_identificateur ref_w38={-1,0,0,"W",0,0};
const define_alias_gen(alias_w38,_IDNT,0,&ref_w38);
// const gen & w__IDNT_e = * (gen *) & alias_w38;
static const alias_identificateur alias_identificateur_x38={0,0,"X",0,0};
const identificateur & x__IDNT=* (const identificateur *) &alias_identificateur_x38;
const alias_ref_identificateur ref_x38={-1,0,0,"X",0,0};
const define_alias_gen(alias_x38,_IDNT,0,&ref_x38);
// const gen & x__IDNT_e = * (gen *) & alias_x38;
static const alias_identificateur alias_identificateur_xx38={0,0,"x",0,0};
const identificateur & xx__IDNT=* (const identificateur *) &alias_identificateur_xx38;
const alias_ref_identificateur ref_xx38={-1,0,0,"x",0,0};
const define_alias_gen(alias_xx38,_IDNT,0,&ref_xx38);
// const gen & xx__IDNT_e = * (gen *) & alias_xx38;
static const alias_identificateur alias_identificateur_y38={0,0,"Y",0,0};
const identificateur & y__IDNT=* (const identificateur *) &alias_identificateur_y38;
const alias_ref_identificateur ref_y38={-1,0,0,"Y",0,0};
const define_alias_gen(alias_y38,_IDNT,0,&ref_y38);
// const gen & y__IDNT_e = * (gen *) & alias_y38;
static const alias_identificateur alias_identificateur_z38={0,0,"Z",0,0};
const identificateur & z__IDNT=* (const identificateur *) &alias_identificateur_z38;
const alias_ref_identificateur ref_z38={-1,0,0,"Z",0,0};
const define_alias_gen(alias_z38,_IDNT,0,&ref_z38);
// const gen & z__IDNT_e = * (gen *) & alias_z38;
#else
static const alias_identificateur alias_identificateur_a38={0,0,"a",0,0};
const identificateur & a__IDNT=* (const identificateur *) &alias_identificateur_a38;
const alias_ref_identificateur ref_a38={-1,0,0,"a",0,0};
const define_alias_gen(alias_a38,_IDNT,0,&ref_a38);
// const gen & a__IDNT_e = * (gen *) & alias_a38;
static const alias_identificateur alias_identificateur_b38={0,0,"b",0,0};
const identificateur & b__IDNT=* (const identificateur *) &alias_identificateur_b38;
const alias_ref_identificateur ref_b38={-1,0,0,"b",0,0};
const define_alias_gen(alias_b38,_IDNT,0,&ref_b38);
// const gen & b__IDNT_e = * (gen *) & alias_b38;
static const alias_identificateur alias_identificateur_c38={0,0,"c",0,0};
const identificateur & c__IDNT=* (const identificateur *) &alias_identificateur_c38;
const alias_ref_identificateur ref_c38={-1,0,0,"c",0,0};
const define_alias_gen(alias_c38,_IDNT,0,&ref_c38);
// const gen & c__IDNT_e = * (gen *) & alias_c38;
static const alias_identificateur alias_identificateur_d38={0,0,"d",0,0};
const identificateur & d__IDNT=* (const identificateur *) &alias_identificateur_d38;
const alias_ref_identificateur ref_d38={-1,0,0,"d",0,0};
const define_alias_gen(alias_d38,_IDNT,0,&ref_d38);
// const gen & d__IDNT_e = * (gen *) & alias_d38;
static const alias_identificateur alias_identificateur_e38={0,0,"e",0,0};
const identificateur & e__IDNT=* (const identificateur *) &alias_identificateur_e38;
const alias_ref_identificateur ref_e38={-1,0,0,"e",0,0};
const define_alias_gen(alias_e38,_IDNT,0,&ref_e38);
// const gen & e__IDNT_e = * (gen *) & alias_e38;
static const alias_identificateur alias_identificateur_f38={0,0,"f",0,0};
const identificateur & f__IDNT=* (const identificateur *) &alias_identificateur_f38;
const alias_ref_identificateur ref_f38={-1,0,0,"f",0,0};
const define_alias_gen(alias_f38,_IDNT,0,&ref_f38);
// const gen & f__IDNT_e = * (gen *) & alias_f38;
static const alias_identificateur alias_identificateur_g38={0,0,"g",0,0};
const identificateur & g__IDNT=* (const identificateur *) &alias_identificateur_g38;
const alias_ref_identificateur ref_g38={-1,0,0,"g",0,0};
const define_alias_gen(alias_g38,_IDNT,0,&ref_g38);
// const gen & g__IDNT_e = * (gen *) & alias_g38;
static const alias_identificateur alias_identificateur_h38={0,0,"h",0,0};
const identificateur & h__IDNT=* (const identificateur *) &alias_identificateur_h38;
const alias_ref_identificateur ref_h38={-1,0,0,"h",0,0};
const define_alias_gen(alias_h38,_IDNT,0,&ref_h38);
// const gen & h__IDNT_e = * (gen *) & alias_h38;
static const alias_identificateur alias_identificateur_i38={0,0,"i",0,0};
const identificateur & i__IDNT=* (const identificateur *) &alias_identificateur_i38;
const alias_ref_identificateur ref_i38={-1,0,0,"i",0,0};
const define_alias_gen(alias_i38,_IDNT,0,&ref_i38);
// const gen & i__IDNT_e = * (gen *) & alias_i38;
static const alias_identificateur alias_identificateur_j38={0,0,"j",0,0};
const identificateur & j__IDNT=* (const identificateur *) &alias_identificateur_j38;
const alias_ref_identificateur ref_j38={-1,0,0,"j",0,0};
const define_alias_gen(alias_j38,_IDNT,0,&ref_j38);
// const gen & j__IDNT_e = * (gen *) & alias_j38;
static const alias_identificateur alias_identificateur_k38={0,0,"k",0,0};
const identificateur & k__IDNT=* (const identificateur *) &alias_identificateur_k38;
const alias_ref_identificateur ref_k38={-1,0,0,"k",0,0};
const define_alias_gen(alias_k38,_IDNT,0,&ref_k38);
// const gen & k__IDNT_e = * (gen *) & alias_k38;
static const alias_identificateur alias_identificateur_l38={0,0,"l",0,0};
const identificateur & l__IDNT=* (const identificateur *) &alias_identificateur_l38;
const alias_ref_identificateur ref_l38={-1,0,0,"l",0,0};
const define_alias_gen(alias_l38,_IDNT,0,&ref_l38);
// const gen & l__IDNT_e = * (gen *) & alias_l38;
static const alias_identificateur alias_identificateur_m38={0,0,"m",0,0};
const identificateur & m__IDNT=* (const identificateur *) &alias_identificateur_m38;
const alias_ref_identificateur ref_m38={-1,0,0,"m",0,0};
const define_alias_gen(alias_m38,_IDNT,0,&ref_m38);
// const gen & m__IDNT_e = * (gen *) & alias_m38;
static const alias_identificateur alias_identificateur_n38={0,0,"n",0,0};
const identificateur & n__IDNT=* (const identificateur *) &alias_identificateur_n38;
const alias_ref_identificateur ref_n38={-1,0,0,"n",0,0};
const define_alias_gen(alias_n38,_IDNT,0,&ref_n38);
// const gen & n__IDNT_e = * (gen *) & alias_n38;
static const alias_identificateur alias_identificateur_o38={0,0,"o",0,0};
const identificateur & o__IDNT=* (const identificateur *) &alias_identificateur_o38;
const alias_ref_identificateur ref_o38={-1,0,0,"o",0,0};
const define_alias_gen(alias_o38,_IDNT,0,&ref_o38);
// const gen & o__IDNT_e = * (gen *) & alias_o38;
static const alias_identificateur alias_identificateur_p38={0,0,"p",0,0};
const identificateur & p__IDNT=* (const identificateur *) &alias_identificateur_p38;
const alias_ref_identificateur ref_p38={-1,0,0,"p",0,0};
const define_alias_gen(alias_p38,_IDNT,0,&ref_p38);
// const gen & p__IDNT_e = * (gen *) & alias_p38;
static const alias_identificateur alias_identificateur_q38={0,0,"q",0,0};
const identificateur & q__IDNT=* (const identificateur *) &alias_identificateur_q38;
const alias_ref_identificateur ref_q38={-1,0,0,"q",0,0};
const define_alias_gen(alias_q38,_IDNT,0,&ref_q38);
// const gen & q__IDNT_e = * (gen *) & alias_q38;
static const alias_identificateur alias_identificateur_r38={0,0,"r",0,0};
const identificateur & r__IDNT=* (const identificateur *) &alias_identificateur_r38;
const alias_ref_identificateur ref_r38={-1,0,0,"r",0,0};
const define_alias_gen(alias_r38,_IDNT,0,&ref_r38);
// const gen & r__IDNT_e = * (gen *) & alias_r38;
static const alias_identificateur alias_identificateur_s38={0,0,"s",0,0};
const identificateur & s__IDNT=* (const identificateur *) &alias_identificateur_s38;
const alias_ref_identificateur ref_s38={-1,0,0,"s",0,0};
const define_alias_gen(alias_s38,_IDNT,0,&ref_s38);
// const gen & s__IDNT_e = * (gen *) & alias_s38;
static const alias_identificateur alias_identificateur_t38={0,0,"t",0,0};
const identificateur & t__IDNT=* (const identificateur *) &alias_identificateur_t38;
const alias_ref_identificateur ref_t38={-1,0,0,"t",0,0};
const define_alias_gen(alias_t38,_IDNT,0,&ref_t38);
// const gen & t__IDNT_e = * (gen *) & alias_t38;
static const alias_identificateur alias_identificateur_u38={0,0,"u",0,0};
const identificateur & u__IDNT=* (const identificateur *) &alias_identificateur_u38;
const alias_ref_identificateur ref_u38={-1,0,0,"u",0,0};
const define_alias_gen(alias_u38,_IDNT,0,&ref_u38);
// const gen & u__IDNT_e = * (gen *) & alias_u38;
static const alias_identificateur alias_identificateur_v38={0,0,"v",0,0};
const identificateur & v__IDNT=* (const identificateur *) &alias_identificateur_v38;
const alias_ref_identificateur ref_v38={-1,0,0,"v",0,0};
const define_alias_gen(alias_v38,_IDNT,0,&ref_v38);
// const gen & v__IDNT_e = * (gen *) & alias_v38;
static const alias_identificateur alias_identificateur_w38={0,0,"w",0,0};
const identificateur & w__IDNT=* (const identificateur *) &alias_identificateur_w38;
const alias_ref_identificateur ref_w38={-1,0,0,"w",0,0};
const define_alias_gen(alias_w38,_IDNT,0,&ref_w38);
// const gen & w__IDNT_e = * (gen *) & alias_w38;
static const alias_identificateur alias_identificateur_x38={0,0,"x",0,0};
const identificateur & x__IDNT=* (const identificateur *) &alias_identificateur_x38;
const alias_ref_identificateur ref_x38={-1,0,0,"x",0,0};
const define_alias_gen(alias_x38,_IDNT,0,&ref_x38);
// const gen & x__IDNT_e = * (gen *) & alias_x38;
static const alias_identificateur alias_identificateur_xx38={0,0,"x",0,0};
const identificateur & xx__IDNT=* (const identificateur *) &alias_identificateur_xx38;
const alias_ref_identificateur ref_xx38={-1,0,0,"x",0,0};
const define_alias_gen(alias_xx38,_IDNT,0,&ref_xx38);
// const gen & x__IDNT_e = * (gen *) & alias_xx38;
static const alias_identificateur alias_identificateur_y38={0,0,"y",0,0};
const identificateur & y__IDNT=* (const identificateur *) &alias_identificateur_y38;
const alias_ref_identificateur ref_y38={-1,0,0,"y",0,0};
const define_alias_gen(alias_y38,_IDNT,0,&ref_y38);
// const gen & y__IDNT_e = * (gen *) & alias_y38;
static const alias_identificateur alias_identificateur_z38={0,0,"z",0,0};
const identificateur & z__IDNT=* (const identificateur *) &alias_identificateur_z38;
const alias_ref_identificateur ref_z38={-1,0,0,"z",0,0};
const define_alias_gen(alias_z38,_IDNT,0,&ref_z38);
// const gen & z__IDNT_e = * (gen *) & alias_z38;
#endif
static const alias_identificateur alias_identificateur_laplace_var={0,0," s",0,0};
const identificateur & laplace_var=* (const identificateur *) &alias_identificateur_laplace_var;
const alias_ref_identificateur ref_laplace_var={-1,0,0," s",0,0};
const define_alias_gen(alias_laplace_var,_IDNT,0,&ref_laplace_var);
const gen & laplace_var_e = * (gen *) & alias_laplace_var;
static const alias_identificateur alias_identificateur_theta38={0,0,"θ",0,0};
const identificateur & theta__IDNT=* (const identificateur *) &alias_identificateur_theta38;
const alias_ref_identificateur ref_theta38={-1,0,0,"θ",0,0};
const define_alias_gen(alias_theta38,_IDNT,0,&ref_theta38);
const gen & theta__IDNT_e = * (gen *) & alias_theta38;
static const alias_identificateur alias_identificateur_CST38={0,0,"CST",0,0};
const identificateur & CST__IDNT=* (const identificateur *) &alias_identificateur_CST38;
const alias_ref_identificateur ref_CST38={-1,0,0,"CST",0,0};
const define_alias_gen(alias_CST38,_IDNT,0,&ref_CST38);
const gen & CST__IDNT_e = * (gen *) & alias_CST38;
static const alias_identificateur alias_identificateur_at38={0,0,"at",0,0};
const identificateur & _IDNT_id_at=* (const identificateur *) &alias_identificateur_at38;
const alias_ref_identificateur ref_at38={-1,0,0,"at",0,0};
const define_alias_gen(alias_at38,_IDNT,0,&ref_at38);
const gen & at__IDNT_e = * (gen *) & alias_at38;
#ifdef CAS38_DISABLED
define_alias_gen(alias_vx38,_IDNT,0,&ref_x38);
#else
define_alias_gen(alias_vx38,_IDNT,0,&ref_xx38);
#endif
#ifdef NSPIRE
// gen & vx_var = * (gen *) & alias_vx38;
gen vx_var;
#else
gen vx_var(identificateur("x"));
#endif
/* model
static const alias_identificateur alias_identificateur_zzz38={0,0,"ZZZ",0,0};
const identificateur & zzz__IDNT=* (const identificateur *) &alias_identificateur_zzz38;
const alias_ref_identificateur ref_zzz38={-1,0,0,"ZZZ",0,0};
const define_alias_gen(alias_zzz38,_IDNT,0,&ref_zzz38);
const gen & zzz__IDNT_e = * (gen *) & alias_zzz38;
*/
#else // GIAC_HAS_STO_38
identificateur a__IDNT("a");
gen a__IDNT_e(a__IDNT);
identificateur b__IDNT("b");
gen b__IDNT_e(b__IDNT);
identificateur c__IDNT("c");
gen c__IDNT_e(c__IDNT);
identificateur d__IDNT("d");
gen d__IDNT_e(d__IDNT);
identificateur e__IDNT("e");
gen e__IDNT_e(e__IDNT);
identificateur f__IDNT("f");
gen f__IDNT_e(f__IDNT);
identificateur g__IDNT("g");
gen g__IDNT_e(g__IDNT);
identificateur h__IDNT("h");
gen h__IDNT_e(h__IDNT);
identificateur i__IDNT("i");
gen i__IDNT_e(i__IDNT);
identificateur j__IDNT("j");
gen j__IDNT_e(j__IDNT);
identificateur k__IDNT("k");
gen k__IDNT_e(k__IDNT);
identificateur l__IDNT("l");
gen l__IDNT_e(l__IDNT);
identificateur m__IDNT("m");
gen m__IDNT_e(m__IDNT);
identificateur n__IDNT("n");
gen n__IDNT_e(n__IDNT);
identificateur o__IDNT("o");
gen o__IDNT_e(o__IDNT);
identificateur p__IDNT("p");
gen p__IDNT_e(p__IDNT);
identificateur q__IDNT("q");
gen q__IDNT_e(q__IDNT);
identificateur r__IDNT("r");
gen r__IDNT_e(r__IDNT);
identificateur s__IDNT("s");
gen s__IDNT_e(s__IDNT);
identificateur t__IDNT("t");
gen t__IDNT_e(t__IDNT);
identificateur u__IDNT("u");
gen u__IDNT_e(u__IDNT);
identificateur v__IDNT("v");
gen v__IDNT_e(v__IDNT);
identificateur w__IDNT("w");
gen w__IDNT_e(w__IDNT);
identificateur x__IDNT("x");
gen x__IDNT_e(x__IDNT);
identificateur y__IDNT("y");
gen y__IDNT_e(y__IDNT);
identificateur z__IDNT("z");
gen z__IDNT_e(z__IDNT);
identificateur laplace_var(" s");
gen laplace_var_e(laplace_var);
identificateur theta__IDNT("θ");
gen theta__IDNT_e(theta__IDNT);
identificateur CST__IDNT("CST");
gen CST__IDNT_e(CST__IDNT);
identificateur _IDNT_id_at("id_at");
gen vx_var(x__IDNT_e);
#endif // GIAC_HAS_STO_38
const gen * const tab_one_letter_idnt[]={&a__IDNT_e,&b__IDNT_e,&c__IDNT_e,&d__IDNT_e,&e__IDNT_e,&f__IDNT_e,&g__IDNT_e,&h__IDNT_e,&i__IDNT_e,&j__IDNT_e,&k__IDNT_e,&l__IDNT_e,&m__IDNT_e,&n__IDNT_e,&o__IDNT_e,&p__IDNT_e,&q__IDNT_e,&r__IDNT_e,&s__IDNT_e,&t__IDNT_e,&u__IDNT_e,&v__IDNT_e,&w__IDNT_e,&x__IDNT_e,&y__IDNT_e,&z__IDNT_e};
identificateur::identificateur(){
int_string_shortint_bool * ptr = new int_string_shortint_bool;
ptr->i=1;
ptr->b=0;
ptr->s_dynalloc=true;
#if defined GIAC_HAS_STO_38 || defined NSPIRE
string tmp=string("_"+print_INT_(std_rand()));
#else
string tmp=string(" "+print_INT_(std_rand()));
#endif
int l=int(tmp.size());
char * c = new char[l+1];
strcpy(c,tmp.c_str());
ptr->s=c;
ref_count = &ptr->i ;
value = NULL;
quoted = &ptr->b ;
localvalue = 0;
id_name = ptr->s ;
}
identificateur::identificateur(const string & s){
bool b=strchr(s.c_str(),' ')?true:false;
int_string_shortint_bool * ptr = new int_string_shortint_bool;
ptr->i=1;
ptr->b=0;
ptr->s_dynalloc=true;
char * c = new char[s.size()+(b?3:1)];
#ifdef NSPIRE
if (b){
string s1=('`'+s+'`');
ptr->s=strcpy(c,s1.c_str());
}
else
ptr->s=strcpy(c,s.c_str());
#else
ptr->s=strcpy(c,b?('`'+s+'`').c_str():s.c_str());
#endif
#if defined GIAC_HAS_STO_38 || defined NSPIRE
for (;*c;++c){
if (*c==' ')
*c='_';
}
#endif
ref_count = &ptr->i ;
value = NULL;
quoted = &ptr->b ;
localvalue = 0;
id_name = ptr->s ;
}
identificateur::identificateur(const string & s,const gen & e){
bool b=strchr(s.c_str(),' ')?true:false;
int_string_shortint_bool * ptr = new int_string_shortint_bool;
ptr->i=1;
ptr->b=0;
ptr->s_dynalloc=true;
char * c = new char[s.size()+(b?3:1)];
#ifdef NSPIRE
if (b){
string s1=('`'+s+'`');
ptr->s=strcpy(c,s1.c_str());
}
else
ptr->s=strcpy(c,s.c_str());
#else
ptr->s=strcpy(c,b?('`'+s+'`').c_str():s.c_str());
#endif
/* #if defined GIAC_HAS_STO_38 || defined NSPIRE
for (;*c;++c){
if (*c==' ')
*c='_';
}
#endif */
ref_count = &ptr->i ;
quoted = &ptr->b ;
localvalue = 0;
id_name = ptr->s ;
value = new gen(e);
}
identificateur::identificateur(const char * s){
if (strchr(s,' ')){
ref_count=0;
string S(s);
#if defined GIAC_HAS_STO_38 || defined NSPIRE
for (unsigned i=0;i<S.size();++i){
if (S[i]==' '){
S[i]='_';
}
}
#endif
*this=identificateur(S);
return;
}
int_string_shortint_bool * ptr = new int_string_shortint_bool;
ptr->i=1;
ptr->b=0;
ptr->s=s;
ptr->s_dynalloc=false;
ref_count = &ptr->i ;
value = NULL;
quoted = &ptr->b ;
localvalue = 0;
id_name = ptr->s ;
}
#ifdef GIAC_HAS_STO_38
identificateur::identificateur(const char * s, bool StringIsNowYours){
if (strchr(s,' ')){
ref_count=0;
string S(s);
// #ifdef GIAC_HAS_STO_38
for (unsigned i=0;i<S.size();++i){
if (S[i]==' '){
S[i]='_';
}
}
// #endif
*this=identificateur(S);
return;
}
int_string_shortint_bool * ptr = new int_string_shortint_bool;
ptr->i=1;
ptr->b=0;
ptr->s=s;
ptr->s_dynalloc= StringIsNowYours;
ref_count = &ptr->i ;
value = NULL;
quoted = &ptr->b ;
localvalue = 0;
id_name = ptr->s ;
}
#endif
identificateur::identificateur(const char * s,const gen & e){
if (strchr(s,' ')){
ref_count=0;
*this=identificateur(string(s),e);
return;
}
int_string_shortint_bool * ptr = new int_string_shortint_bool;
ptr->i=1;
ptr->b=0;
ptr->s=s;
ptr->s_dynalloc=false;
ref_count = &ptr->i ;
quoted = &ptr->b ;
localvalue = 0;
id_name = ptr->s ;
value = new gen(e);
}
identificateur::identificateur(const identificateur & s){
ref_count=s.ref_count;
if (ref_count)
++(*ref_count);
value=s.value;
quoted=s.quoted;
localvalue=s.localvalue;
id_name=s.id_name;
}
identificateur::~identificateur(){
if (ref_count){
--(*ref_count);
if (!(*ref_count)){
int_string_shortint_bool * ptr = (int_string_shortint_bool *) ref_count;
if (ptr->s_dynalloc)
delete [] ptr->s;
delete ptr;
if (value)
delete value;
if (localvalue)
delete localvalue;
}
}
}
void identificateur::MakeCopyOfNameIfNotLocal() {
int_string_shortint_bool * ptr = (int_string_shortint_bool *) ref_count;
if (ptr->s_dynalloc) return;
id_name = ptr->s= strdup(ptr->s);
ptr->s_dynalloc= true;
}
identificateur & identificateur::operator =(const identificateur & s){
if (ref_count){
--(*ref_count);
if (!(*ref_count)){
int_string_shortint_bool * ptr = (int_string_shortint_bool *) ref_count;
if (ptr->s_dynalloc)
delete [] ptr->s;
delete ptr;
if (value)
delete value;
if (localvalue)
delete localvalue;
}
}
ref_count=s.ref_count;
if (ref_count)
++(*ref_count);
value=s.value;
quoted=s.quoted;
localvalue=s.localvalue;
id_name=s.id_name;
return *this;
}
gen globalize(const gen & g){
gen tmp(g);
switch (tmp.type){
case _IDNT:
tmp.subtype=_GLOBAL__EVAL;
break;
case _VECT:
tmp=apply(tmp,globalize);
break;
case _SYMB:
if (tmp._SYMBptr->sommet!=at_program)
tmp=symbolic(tmp._SYMBptr->sommet,globalize(tmp._SYMBptr->feuille));
break;
}
return tmp;
}
// make g identificateurs evaluated as global
gen global_eval(const gen & g,int level){
if (g.type<_IDNT)
return g;
bool save_local_eval=local_eval(context0);
local_eval(false,context0);
gen tmp;
#ifndef NO_STDEXCEPT
try {
#endif
tmp=g.eval(level,context0);
#ifndef NO_STDEXCEPT
}
catch (std::runtime_error & e){
cerr << e.what() << endl;
// eval_level(level,contextptr);
}
#endif
local_eval(save_local_eval,context0);
return globalize(tmp);
}
bool check_not_assume(const gen & not_evaled,gen & evaled, bool evalf_after,const context * contextptr);
// make g identificateurs evaluated as global
gen global_evalf(const gen & g,int level){
if (g.type<_IDNT)
return g;
bool save_local_eval=local_eval(context0);
local_eval(false,context0);
gen tmp;
#ifndef NO_STDEXCEPT
try {
#endif
tmp=g.eval(level,context0);
if (tmp.type==_IDNT){
gen evaled(tmp._IDNTptr->eval(level,tmp,context0));
if (check_not_assume(tmp,evaled,true,context0))
tmp=evaled;
}
#ifndef NO_STDEXCEPT
}
catch (std::runtime_error & e){
cerr << e.what() << endl;
// eval_level(level,contextptr);
}
#endif
local_eval(save_local_eval,context0);
return globalize(tmp);
}
gen _prod(const gen & args,GIAC_CONTEXT);
#if 0
static inline bool eval_38(int level,const gen & orig,gen & res,const char * s,GIAC_CONTEXT){
if (storcl_38 && storcl_38(res,0,s,undef,false,contextptr,NULL)){
return true;
}
return false;
size_t ss=strlen(s);
#ifdef GIAC_HAS_STO_38
if (
(ss>1 && s[0]=='G')
#ifndef CAS38_DISABLED
|| (ss==1 && s[0]>='a' && s[0]<='z')
#endif
){ // checking for a geometry global variables
if (contextptr){
sym_tab::const_iterator it=contextptr->globalcontextptr->tabptr->find(s);
if (it!=contextptr->globalcontextptr->tabptr->end()){
res=it->second;
return true;
}
}
res=orig;
return false;
}
#endif
if (calc_mode(contextptr)!=38 || !strcmp(s,string_pi) || !strcmp(s,string_euler_gamma) || !strcmp(s,string_infinity) || !strcmp(s,string_undef)){
res=orig;
return false;
}
if (ss<=1){
if (s[0]>'Z'){
res=orig;
return false;
}
res=0.0;
return true;
}
if (ss==2 && s[1]<='9') {
res=orig;
gen tmp,evaled;
switch(s[0]){
case 'C': case 'L':
res=gen(vecteur(0),_LIST__VECT);
break;
case 'E': case 'H': /* case 'S': */
return false;
case 'G': // FIXME: grob
return false;
case 'F': case 'R': case 'U': case 'X': case 'Y':
if (calc_mode(contextptr)==38)
res=gensizeerr(gettext("Function not defined"));
return true;
case 'M':
res=makevecteur(makevecteur(0));
break;
case 'V':
res=makevecteur(0);
break;
case 'Z':
res=0.0;
break;
case 'i':
res=(s[1]-'0')*cst_i;
break;
case 'e':
res=(s[1]-'0')*std::exp(1.0);
break;
default:
tmp=identificateur(string(1,s[0]));
if (tmp._IDNTptr->in_eval(1,tmp,evaled,contextptr))
res=(s[1]-'0')*evaled;
else
res=0.0;
}
return true;
}
char ch;
for (size_t i=0;i<ss;++i){
ch=s[i];
if ( (ch>'Z' && ch!='i' && ch!='e')|| ch<'0'){
res=orig;
return false;
}
}
// all chars are regular 38 characters, split as a product
vecteur args;
gen g;
for (size_t i=0;i<ss;++i){
ch=s[i];
if (ch=='C' || (ch>='E' && ch<='H') || ch=='L' || ch=='M' || ch=='R'
/* || ch=='S' */
|| ch=='U' || ch=='V' || (ch>='X' && ch<='Z')){
string name;
name += ch;
char c=0;
if (i<ss-1)
c=s[i+1];
if (c>='0' && c<='9'){
name += c;
++i;
}
g=identificateur(name);
g=g.eval(level,contextptr);
args.push_back(g);
}
else {
string coeff;
for (++i;i<ss;++i){
if (s[i]>32 && isalpha(s[i])){
--i;
break;
}
coeff += s[i];
}
if (coeff.empty())
g=1;
else
g=atof(coeff.c_str());
if (ch=='i')
g=g*cst_i;
else {
if (ch=='e')
g=std::exp(1.0)*g;
else {
coeff="";
coeff += ch;
gen tmp=identificateur(coeff),evaled;
if (tmp._IDNTptr->in_eval(1,tmp,evaled,contextptr))
g=g*evaled;
else
g=0.0;
}
}
args.push_back(g);
}
}
res=_prod(args,contextptr);
return true;
}
#endif
gen identificateur::eval(int level,const gen & orig,const context * contextptr) {
if (!ref_count)
return orig;
gen evaled;
// cerr << "idnt::eval " << *this << " " << level << endl;
if (level<=0){
if (level==0)
return orig;
// If 38 is there, let it look at the current state and decide if it needs to evaluate the name or if it needs to let the CAS do it
// This will depend on the order of priorities and the status of the requested variable (local/global...)
if (storcl_38 && abs_calc_mode(contextptr)==38 && storcl_38(evaled,NULL,id_name,undef,false,contextptr,NULL,false)) return evaled;
if (contextptr){
sym_tab::const_iterator it=contextptr->tabptr->find(id_name),itend=contextptr->tabptr->end();
if (it!=itend)
return it->second;
//if (abs_calc_mode(contextptr)==38){
// gen evaled;
// if (eval_38(level,orig,evaled,id_name,contextptr))
// return evaled;
//}
return orig;
}
else {
if (!localvalue || localvalue->empty())
return orig;
iterateur jtend=localvalue->end();
return (protection_level>(jtend-2)->val)?localvalue->back():orig;
}
}
--level;
if (in_eval(level,orig,evaled,contextptr))
return evaled;
else
return *this;
/*
int save_level=eval_level(contextptr);
eval_level(level,contextptr);
gen res=in_eval(level,contextptr);
eval_level(save_level,contextptr);
return res;
*/
}
// if globalize is true, use global value in eval
gen do_local_eval(const identificateur & i,int level,bool globalize) {
if (!i.localvalue)
return i;
gen res;
iterateur jtend=i.localvalue->end();
if (protection_level>(jtend-2)->val)
res=i.localvalue->back();
else {
for (iterateur jt=i.localvalue->begin();;){
if (jt==jtend)
break;
--jtend;
--jtend;
if (protection_level>jtend->val){
++jtend;
++jtend;
break;
}
}
i.localvalue->erase(jtend,i.localvalue->end());
if (!i.localvalue->empty())
res=i.localvalue->back();
}
return globalize?global_eval(res,level):res;
}
void printsymtab(sym_tab * ptr){
sym_tab::const_iterator it=ptr->begin(),itend=ptr->end();
for (;it!=itend;++it)
CERR << it->first << ":" << it->second << endl;
}
bool identificateur::in_eval(int level,const gen & orig,gen & evaled,const context * contextptr, bool No38Lookup) {
// if (!ref_count) return false; // does not work for cst ref identificateur
if (contextptr){ // Look for local variables...
// If 38 is there, let it look at variable priorities, but ONLY looking at local for the moment! We do not want to look as globals as they might need to be quoted...
if (storcl_38!=NULL && !No38Lookup && abs_calc_mode(contextptr)==38 && storcl_38(evaled,NULL,id_name,undef,false,contextptr, NULL, true)) return true;
const context * cur=contextptr;
for (;cur->previous;cur=cur->previous){
sym_tab::const_iterator it=cur->tabptr->find(id_name);
if (it!=cur->tabptr->end()){
if (!it->second.in_eval(level,evaled,contextptr->globalcontextptr))
evaled=it->second;
return true;
}
}
// now at global level
// check for quoted
if (cur->quoted_global_vars && !cur->quoted_global_vars->empty() && equalposcomp(*cur->quoted_global_vars,orig))
return false;
// If 38 is there, look again, but now it is allowed to look at local and globals!
if (storcl_38!=NULL && !No38Lookup && abs_calc_mode(contextptr)==38 && storcl_38(evaled,NULL,id_name,undef,false,contextptr, NULL, false)) return true;
// printsymtab(cur->tabptr);
sym_tab::const_iterator it=cur->tabptr->find(id_name);
if (it==cur->tabptr->end()){
//if (No38Lookup) return false;
//if (storcl_38 && abs_calc_mode(contextptr)==38)
// return eval_38(level,orig,evaled,id_name,contextptr);
return false;
}
else {
if (!it->second.in_eval(level,evaled,contextptr->globalcontextptr))
evaled=it->second;
return true;
}
//if (!No38Lookup && storcl_38){ // && abs_calc_mode(contextptr)==38)
// if (eval_38(level,orig,evaled,id_name,contextptr))
// return true;
//}
}
if (local_eval(contextptr) && localvalue && !localvalue->empty()){
evaled=do_local_eval(*this,level,true);
return true;
}
if (quoted && *quoted & 1)
return false;
if (current_folder_name.type==_IDNT && current_folder_name._IDNTptr->value && current_folder_name._IDNTptr->value->type==_VECT){
evaled=find_in_folder(*current_folder_name._IDNTptr->value->_VECTptr,orig);
return (evaled!=orig);
}
if (value){
evaled=value->eval(level,contextptr);
return true;
}
// look in current directory for a value
if ( secure_run || (!variables_are_files(contextptr))
#if !defined __MINGW_H && !defined NSPIRE
|| (access((name()+string(cas_suffixe)).c_str(),R_OK))
#endif
){
evaled=orig;
if (!local_eval(contextptr))
evaled.subtype=_GLOBAL__EVAL;
return true;
}
#ifndef NSPIRE
// set current value
ifstream inf((name()+string(cas_suffixe)).c_str());
evaled=read1arg_from_stream(inf,contextptr);
if (child_id)
return true;
value = new gen(evaled);
evaled=evaled.eval(level,contextptr);
#endif
return true;
}
void identificateur::push(int protection,const gen & e){
if (!localvalue)
localvalue=new vecteur;
localvalue->push_back(protection);
localvalue->push_back(e);
}
const char * identificateur::print(GIAC_CONTEXT) const{
if (!strcmp(id_name,string_pi)){
if (abs_calc_mode(contextptr)==38)
return "π";
switch (xcas_mode(contextptr)){
case 1:
return "Pi";
case 2:
return "PI";
default:
return string_pi;
}
}
if (
//calc_mode(contextptr)!=1 &&
abs_calc_mode(contextptr)==38 &&
!strcmp(id_name,string_infinity))
return "±∞";
// index != sqrt(-1) wich has different notations
if (xcas_mode(contextptr)==0){
if (strcmp(id_name,"i")==0)
return "i_i_";
}
else {
if (strcmp(id_name,"I")==0)
return "i_i_";
}
/*
if (!localvalue->empty())
return string("_") + *name ;
if (value)
return string("~") + *name ;
else
*/
return id_name ;
}
#ifdef NSPIRE
template<class T>
nio::ios_base<T> & operator << (nio::ios_base<T> & os,const identificateur & s) { return os << s.print(context0);}
#else
ostream & operator << (ostream & os,const identificateur & s) { return os << s.print(context0);}
#endif
int removecomments(const char * ss,char * ss2){
int j=0,k=0;
for (;ss[j];j++){
if (ss[j]=='#'){
ss2[k]=char(0); // end ss2 string
break;
}
if (ss[j]>31){ // supress control chars
ss2[k]=ss[j];
k++;
}
}
return k;
}
void identificateur::unassign(){
if (value){
delete(value);
value = NULL;
}
}
#ifndef NO_NAMESPACE_GIAC
} // namespace giac
#endif // ndef NO_NAMESPACE_GIAC