~jrheinlaender/imath/master2

« back to all changes in this revision

Viewing changes to src/smathparser.yxx

  • Committer: jrheinlaender
  • Date: 2020-11-13 19:24:06 UTC
  • Revision ID: git-v1:fd8d6cec241e59a79622d27e6bccc4c13c06ca85
Fix bug that left line_options undefined, leading to spurious crashes

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
  line = nullptr;
67
67
  // Set the current options to the global options from the iFormula
68
68
  current_options = global_options;
 
69
  line_options = nullptr;
69
70
  // Must the current line be auto-formatted?
70
71
  must_autoformat = false;
71
72
  // Are we inside an include file (or a nested include file)?
481
482
          std::vector<OUString> formulaParts = {OUS8(rawtext.substr(@4.begin.column-1, @4.end.column-@4.begin.column))}; // not GETARG because it trims the string
482
483
          formula.lines.push_back(std::make_shared<iFormulaNodeText>(&compiler.unitmgr, current_options, std::move(*$2), std::move(formulaParts), std::move(*$4)));
483
484
          line = formula.lines.back();
 
485
                  line_options = nullptr;
484
486
          delete($2); delete($4);
485
487
       } comment end
486
488
       | input usertext { // user-defined text on a line by itself. The end removes 3 shift/reduce conflicts
487
489
          std::vector<OUString> formulaParts = {GETARG(@2)};
488
490
          formula.lines.push_back(std::make_shared<iFormulaNodeText>(&compiler.unitmgr, current_options, optionmap(), std::move(formulaParts), std::move(*$2)));
489
491
          line = formula.lines.back();
 
492
                  line_options = nullptr;
490
493
          delete($2);
491
494
        } comment end
492
495
             | input expr comment end { /* all the work is done in expr */ }
496
499
           std::vector<OUString> formulaParts = {OUS8(*$2)};
497
500
           formula.lines.push_back(std::make_shared<iFormulaNodeComment>(current_options, std::move(formulaParts)));
498
501
           line = formula.lines.back();
 
502
                  line_options = nullptr;
499
503
         }
500
504
         delete($2);
501
505
       } end
505
509
           std::vector<OUString> formulaParts = {OU("{"), GETARG(@4), OU("}")};
506
510
           formula.lines.push_back(std::make_shared<iFormulaNodeStmReadfile>(current_options, std::move(formulaParts)));
507
511
           line = formula.lines.back();
 
512
                   line_options = nullptr;
508
513
         }
509
514
         ++include_level;
510
515
               locationstack.push(yyla.location);
547
552
       | input end { // Empty line
548
553
          formula.lines.push_back(std::make_shared<iFormulaNodeEmptyLine>(current_options));
549
554
          line = formula.lines.back();
 
555
                  line_options = nullptr;
550
556
       }
551
557
;
552
558
 
584
590
              // propagate the options and units to a new line
585
591
              if (line != nullptr)
586
592
                current_options = line->getGlobalOptions();
 
593
                                line_options = nullptr;
587
594
                                                        // Reset internal options to global value
588
595
                                                        cln::cl_inhibit_floating_point_underflow = (current_options->at(o_underflow).value.boolean);
589
596
                                                        MSG_INFO(3, "Inhibit floating point underflow exception: " << (current_options->at(o_underflow).value.boolean ? "true" : "false") << endline);
599
606
 
600
607
              if (line != nullptr)
601
608
                current_options = line->getGlobalOptions();
 
609
                                line_options = nullptr;
602
610
                                                        // Reset internal options to global value
603
611
                                                        cln::cl_inhibit_floating_point_underflow = (current_options->at(o_underflow).value.boolean);
604
612
                                                        MSG_INFO(3, "Inhibit floating point underflow exception: " << (current_options->at(o_underflow).value.boolean ? "true" : "false") << endline);
615
623
 
616
624
              if (line != nullptr)
617
625
                current_options = line->getGlobalOptions();
 
626
                                line_options = nullptr;
618
627
                                                        // Reset internal options to global value
619
628
                                                        cln::cl_inhibit_floating_point_underflow = (current_options->at(o_underflow).value.boolean);
620
629
                                                        MSG_INFO(3, "Inhibit floating point underflow exception: " << (current_options->at(o_underflow).value.boolean ? "true" : "false") << endline);
657
666
             std::vector<OUString> formulaParts = {GETARG(@2)};
658
667
             formula.lines.push_back(std::make_shared<iFormulaNodeStmOptions>(current_options, std::move(formulaParts)));
659
668
             line = formula.lines.back();
 
669
                         line_options = nullptr;
660
670
           }
661
671
 
662
672
           formula.cacheable = false;
667
677
             std::vector<OUString> formulaParts = {GETARG(@2)};
668
678
             formula.lines.push_back(std::make_shared<iFormulaNodeStmNamespace>(current_options, OU("BEGIN"), std::move(formulaParts)));
669
679
             line = formula.lines.back();
 
680
                         line_options = nullptr;
670
681
           }
671
682
           compiler.begin_namespace(*$2);
672
683
           delete $2;
676
687
             std::vector<OUString> formulaParts = {GETARG(@2)};
677
688
             formula.lines.push_back(std::make_shared<iFormulaNodeStmNamespace>(current_options, OU("END"), std::move(formulaParts)));
678
689
             line = formula.lines.back();
 
690
                         line_options = nullptr;
679
691
           }
680
692
           compiler.end_namespace(*$2);
681
693
           delete $2;
687
699
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU(","), GETARG(@5), OU(","), GETARG(@7), OU("}")};
688
700
             formula.lines.push_back(std::make_shared<iFormulaNodeStmFunction>(current_options, std::move(formulaParts)));
689
701
             line = formula.lines.back();
 
702
                         line_options = nullptr;
690
703
           }
691
704
           exvector args({*$7});
692
705
           compiler.register_function(ex_to<symbol>(*$5).get_name(), args, $3);
698
711
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU(","), GETARG(@5), OU(","), GETARG(@7), OU("}")};
699
712
             formula.lines.push_back(std::make_shared<iFormulaNodeStmFunction>(current_options, std::move(formulaParts)));
700
713
             line = formula.lines.back();
 
714
                         line_options = nullptr;
701
715
           }
702
716
           compiler.register_function(ex_to<symbol>(*$5).get_name(), *$7, $3);
703
717
           formula.cacheable = false;
708
722
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU(","), GETARG(@5), OU(","), GETARG(@7), OU(","), GETARG(@9), OU("}")};
709
723
             formula.lines.push_back(std::make_shared<iFormulaNodeStmFunction>(current_options, std::move(formulaParts)));
710
724
             line = formula.lines.back();
 
725
                         line_options = nullptr;
711
726
           }
712
727
           exvector args({*$9});
713
728
           compiler.register_function(ex_to<symbol>(*$7).get_name(), args, $3, *$5);
719
734
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU(","), GETARG(@5), OU(","), GETARG(@7), OU(","), GETARG(@9), OU("}")};
720
735
             formula.lines.push_back(std::make_shared<iFormulaNodeStmFunction>(current_options, std::move(formulaParts)));
721
736
             line = formula.lines.back();
 
737
                         line_options = nullptr;
722
738
           }
723
739
           compiler.register_function(ex_to<symbol>(*$7).get_name(), *$9, $3, *$5);
724
740
           formula.cacheable = false;
729
745
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU(","), GETARG(@5), OU("="), GETARG(@7), OU("}")};
730
746
             formula.lines.push_back(std::make_shared<iFormulaNodeStmUnitdef>(current_options, std::move(formulaParts)));
731
747
             line = formula.lines.back();
 
748
                         line_options = nullptr;
732
749
           }
733
750
           std::string name = *$5;
734
751
           if (name[0] == '%')
744
761
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU(","), GETARG(@5), OU("="), GETARG(@7), OU("}")};
745
762
             formula.lines.push_back(std::make_shared<iFormulaNodeStmUnitdef>(current_options, std::move(formulaParts)));
746
763
             line = formula.lines.back();
 
764
                         line_options = nullptr;
747
765
           }
748
766
           std::string name = *$5;
749
767
           if (name[0] == '%')
762
780
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU("="), GETARG(@5), OU("}")};
763
781
             formula.lines.push_back(std::make_shared<iFormulaNodeStmPrefixdef>(current_options, std::move(formulaParts)));
764
782
             line = formula.lines.back();
 
783
                         line_options = nullptr;
765
784
           }
766
785
 
767
786
           std::string name = *$3;
783
802
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU("="), GETARG(@5), OU("}")};
784
803
             formula.lines.push_back(std::make_shared<iFormulaNodeStmPrefixdef>(current_options, std::move(formulaParts)));
785
804
             line = formula.lines.back();
 
805
                         line_options = nullptr;
786
806
           }
787
807
 
788
808
           if (!is_a<numeric>(*$5))
797
817
             std::vector<OUString> formulaParts = {GETARG(@2)};
798
818
             formula.lines.push_back(std::make_shared<iFormulaNodeStmVectordef>(current_options, std::move(formulaParts)));
799
819
             line = formula.lines.back();
 
820
                         line_options = nullptr;
800
821
           }
801
822
           formula.cacheable = false;
802
823
           delete($2);
806
827
             std::vector<OUString> formulaParts = {GETARG(@2)};
807
828
             formula.lines.push_back(std::make_shared<iFormulaNodeStmMatrixdef>(current_options, std::move(formulaParts)));
808
829
             line = formula.lines.back();
 
830
                         line_options = nullptr;
809
831
           }
810
832
           formula.cacheable = false;
811
833
           delete($2);
815
837
             std::vector<OUString> formulaParts = {GETARG(@2)};
816
838
             formula.lines.push_back(std::make_shared<iFormulaNodeStmRealvardef>(current_options, std::move(formulaParts)));
817
839
             line = formula.lines.back();
 
840
                         line_options = nullptr;
818
841
           }
819
842
           formula.cacheable = false;
820
843
           delete($2);
824
847
             std::vector<OUString> formulaParts = {GETARG(@2)};
825
848
             formula.lines.push_back(std::make_shared<iFormulaNodeStmPosvardef>(current_options, std::move(formulaParts)));
826
849
             line = formula.lines.back();
 
850
                         line_options = nullptr;
827
851
           }
828
852
           formula.cacheable = false;
829
853
           delete($2);
832
856
           if (include_level == 0) {
833
857
             formula.lines.push_back(std::make_shared<iFormulaNodeStmClearall>(current_options));
834
858
             line = formula.lines.back();
 
859
                         line_options = nullptr;
835
860
           }
836
861
           formula.cacheable = false;
837
862
           compiler.clear();
841
866
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU("}")};
842
867
             formula.lines.push_back(std::make_shared<iFormulaNodeStmDelete>(current_options, std::move(formulaParts)));
843
868
             line = formula.lines.back();
 
869
                         line_options = nullptr;
844
870
           }
845
871
           for (const auto& i : *$3)
846
872
             compiler.deleq(i);
852
878
             std::vector<OUString> formulaParts = {GETARG(@2)};
853
879
             formula.lines.push_back(std::make_shared<iFormulaNodeStmUpdate>(current_options, std::move(formulaParts)));
854
880
             line = formula.lines.back();
 
881
                         line_options = nullptr;
855
882
           }
856
883
           formula.getParent()->insertUpdate(formula.getName(), OUS8(*$2));
857
884
           formula.cacheable = false;
868
895
               check_vector(expression(*$9 / *$11).evalm(), @9), expression()
869
896
             ));
870
897
             line = formula.lines.back();
 
898
                         line_options = nullptr;
871
899
           }
872
900
           delete($3); delete($5); delete($7); delete($9); delete($11); delete($15);
873
901
         }
882
910
               matrix(), subs(ex($11->rhs()) / ex(*$13), ex_to<extsymbol>(*$5) == ex_to<extsymbol>(*$5) * *$9)
883
911
             ));
884
912
             line = formula.lines.back();
 
913
                         line_options = nullptr;
885
914
           }
886
915
           delete($3); delete($5); delete($7); delete($9); delete($11); delete($13);  delete($17);
887
916
         }
896
925
               matrix(), subs(*$11 / *$13, ex_to<extsymbol>(*$5) == ex_to<extsymbol>(*$5) * *$9)
897
926
             ));
898
927
             line = formula.lines.back();
 
928
                         line_options = nullptr;
899
929
           }
900
930
           delete($3); delete($5); delete($7); delete($9); delete($11); delete($13);  delete($17);
901
931
         }
904
934
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU(","), GETARG(@5), OU(","), GETARG(@7), OU("}")};
905
935
             formula.lines.push_back(std::make_shared<iFormulaNodeStmTablecell>(current_options, std::move(formulaParts)));
906
936
             line = formula.lines.back();
 
937
                         line_options = nullptr;
907
938
           }
908
939
 
909
940
                                         if (!is_a<stringex>(*$3))
946
977
             std::vector<OUString> formulaParts = {OU("{"), GETARG(@3), OU(","), GETARG(@5), OU(","), GETARG(@7), OU(","), GETARG(@9), OU("}")};
947
978
             formula.lines.push_back(std::make_shared<iFormulaNodeStmCalccell>(current_options, std::move(formulaParts)));
948
979
             line = formula.lines.back();
 
980
                         line_options = nullptr;
949
981
           }
950
982
                                         if (!is_a<stringex>(*$3) || !is_a<stringex>(*$5) || !is_a<stringex>(*$7))
951
983
                                                        throw std::runtime_error("File name, table name and cell reference must be a string");
976
1008
            std::move(formulaParts), OU(""),
977
1009
            *$4, $3));
978
1010
          line = formula.lines.back();
 
1011
                  line_options = nullptr;
979
1012
          line->force_autoformat(must_autoformat);
980
1013
        }
981
1014
        formula.cacheable = false;
990
1023
            std::move(formulaParts), OUS8(compiler.exlabel_ns(*$1)),
991
1024
            *$5, $4));
992
1025
          line = formula.lines.back();
 
1026
                  line_options = nullptr;
993
1027
          line->force_autoformat(must_autoformat);
994
1028
        }
995
1029
        formula.cacheable = false;
1014
1048
            algebraic, false
1015
1049
          ));
1016
1050
          line = formula.lines.back();
 
1051
                  line_options = nullptr;
1017
1052
                                        line->force_autoformat(must_autoformat);
1018
1053
        }
1019
1054
                                formula.cacheable = false;
1034
1069
            algebraic, true
1035
1070
          ));
1036
1071
          line = formula.lines.back();
 
1072
                  line_options = nullptr;
1037
1073
                                        line->force_autoformat(must_autoformat);
1038
1074
        }
1039
1075
                                formula.cacheable = false;
1058
1094
            compiler.find_variable_values(definition)
1059
1095
          ));
1060
1096
          line = formula.lines.back();
 
1097
                  line_options = nullptr;
1061
1098
                                        line->force_autoformat(must_autoformat);
1062
1099
        }
1063
1100
                                formula.cacheable = false;
1073
1110
            std::move(formulaParts), OUS8(nslabel),
1074
1111
            *$5, $4));
1075
1112
          line = formula.lines.back();
 
1113
                  line_options = nullptr;
1076
1114
          line->force_autoformat(must_autoformat);
1077
1115
        }
1078
1116
        must_autoformat = false;
1094
1132
            std::move(formulaParts), OUS8(nslabel),
1095
1133
            *$5, $4));
1096
1134
          line = formula.lines.back();
 
1135
                  line_options = nullptr;
1097
1136
          line->force_autoformat(must_autoformat);
1098
1137
        }
1099
1138
        must_autoformat = false;
1121
1160
            std::move(formulaParts), OUS8(nslabel),
1122
1161
            *result, $4));
1123
1162
          line = formula.lines.back();
 
1163
                  line_options = nullptr;
1124
1164
          line->force_autoformat(must_autoformat);
1125
1165
        }
1126
1166
        must_autoformat = false;
1150
1190
            std::move(formulaParts),OUS8(nslabel),
1151
1191
            *result, $4));
1152
1192
          line = formula.lines.back();
 
1193
                  line_options = nullptr;
1153
1194
          line->force_autoformat(must_autoformat);
1154
1195
        }
1155
1196
        must_autoformat = false;
1175
1216
            std::move(formulaParts), OUS8(nslabel),
1176
1217
            *result, $4));
1177
1218
          line = formula.lines.back();
 
1219
                  line_options = nullptr;
1178
1220
        }
1179
1221
 
1180
1222
        if (!compiler.is_label(nslabel))
1196
1238
            std::move(formulaParts), OUS8(nslabel),
1197
1239
            expression(result), $4));
1198
1240
          line = formula.lines.back();
 
1241
                  line_options = nullptr;
1199
1242
        }
1200
1243
 
1201
1244
        if (!compiler.is_label(nslabel))