comparison src/ex_eval.c @ 24:8ff7fd162d3c v7.0016

updated for version 7.0016
author vimboss
date Mon, 13 Sep 2004 20:26:32 +0000
parents cc049b00ee70
children 125e80798a85
comparison
equal deleted inserted replaced
23:3f44e9abe4ec 24:8ff7fd162d3c
1818 do_throw(cstack); 1818 do_throw(cstack);
1819 } 1819 }
1820 } 1820 }
1821 1821
1822 /* 1822 /*
1823 * Function to be called before a failed command invokes a sequence of
1824 * autocommands for cleanup. (Failure means here that a call to emsg() has
1825 * been made, an interrupt occurred, or there is an uncaught exception from a
1826 * previous autocommand execution of the same command.) This function works a
1827 * bit like ex_finally() except that there was not actually an extra try block
1828 * around the part that failed and an error or interrupt has not (yet) been
1829 * converted to an exception. This function saves the
1830 * error/interrupt/exception state and prepares for the call to do_cmdline()
1831 * that is going to be made for the cleanup autocommand execution.
1832 *
1833 * Stores the pending error/interrupt/exception state in the cleanup_T
1834 * structure pointed to by "csp", which has to be passed as an argument to
1835 * leave_cleanup() after the autocommand execution has finished.
1836 */
1837 void
1838 enter_cleanup(csp)
1839 cleanup_T *csp;
1840 {
1841 int pending = CSTP_NONE;
1842
1843 /*
1844 * Postpone did_emsg, got_int, did_throw. The pending values will be
1845 * restored by leave_cleanup() except if there was an aborting error,
1846 * interrupt, or uncaught exception after this function ends.
1847 */
1848 if (did_emsg || got_int || did_throw || need_rethrow)
1849 {
1850 csp->pending = (did_emsg ? CSTP_ERROR : 0)
1851 | (got_int ? CSTP_INTERRUPT : 0)
1852 | (did_throw ? CSTP_THROW : 0)
1853 | (need_rethrow ? CSTP_THROW : 0);
1854
1855 /* If we are currently throwing an exception (did_throw), save it as
1856 * well. On an error not yet converted to an exception, update
1857 * "force_abort" and reset "cause_abort" (as do_errthrow() would do).
1858 * This is needed for the do_cmdline() call that is going to be made
1859 * for autocommand execution. We need not save *msg_list because
1860 * there is an extra instance for every call of do_cmdline(), anyway.
1861 */
1862 if (did_throw || need_rethrow)
1863 csp->exception = current_exception;
1864 else
1865 {
1866 csp->exception = NULL;
1867 if (did_emsg)
1868 {
1869 force_abort |= cause_abort;
1870 cause_abort = FALSE;
1871 }
1872 }
1873 did_emsg = got_int = did_throw = need_rethrow = FALSE;
1874
1875 /* Report if required by the 'verbose' option or when debugging. */
1876 report_make_pending(pending, csp->exception);
1877 }
1878 else
1879 {
1880 csp->pending = CSTP_NONE;
1881 csp->exception = NULL;
1882 }
1883 }
1884
1885 /*
1886 * Function to be called after a failed command invoked a sequence of
1887 * autocommands for cleanup. It is a bit like ex_endtry() except that there
1888 * was not actually an extra try block around the part that failed and an
1889 * error or interrupt had not (yet) been converted to an exception when the
1890 * cleanup autocommand sequence was invoked. This function has to be called
1891 * with the address of the cleanup_T structure filled by enter_cleanup() as an
1892 * argument; it restores the error/interrupt/exception state saved by that
1893 * function - except there was an aborting error, an interrupt or an uncaught
1894 * exception during execution of the cleanup autocommands. In the latter
1895 * case, the saved error/interrupt/ exception state is discarded.
1896 */
1897 void
1898 leave_cleanup(csp)
1899 cleanup_T *csp;
1900 {
1901 int pending = csp->pending;
1902
1903 if (pending == CSTP_NONE) /* nothing to do */
1904 return;
1905
1906 /* If there was an aborting error, an interrupt, or an uncaught exception
1907 * after the corresponding call to enter_cleanup(), discard what has been
1908 * made pending by it. Report this to the user if required by the
1909 * 'verbose' option or when debugging. */
1910 if (aborting() || need_rethrow)
1911 {
1912 if (pending & CSTP_THROW)
1913 /* Cancel the pending exception (includes report). */
1914 discard_exception((except_T *)csp->exception, FALSE);
1915 else
1916 report_discard_pending(pending, NULL);
1917
1918 /* If an error was about to be converted to an exception when
1919 * enter_cleanup() was called, free the message list. */
1920 free_msglist(*msg_list);
1921 *msg_list = NULL;
1922 }
1923
1924 /*
1925 * If there was no new error, interrupt, or throw between the calls
1926 * to enter_cleanup() and leave_cleanup(), restore the pending
1927 * error/interrupt/exception state.
1928 */
1929 else
1930 {
1931 /*
1932 * If there was an exception being thrown when enter_cleanup() was
1933 * called, we need to rethrow it. Make it the exception currently
1934 * being thrown.
1935 */
1936 if (pending & CSTP_THROW)
1937 current_exception = csp->exception;
1938
1939 /*
1940 * If an error was about to be converted to an exception when
1941 * enter_cleanup() was called, let "cause_abort" take the part of
1942 * "force_abort" (as done by cause_errthrow()).
1943 */
1944 else if (pending & CSTP_ERROR)
1945 {
1946 cause_abort = force_abort;
1947 force_abort = FALSE;
1948 }
1949
1950 /*
1951 * Restore the pending values of did_emsg, got_int, and did_throw.
1952 */
1953 if (pending & CSTP_ERROR)
1954 did_emsg = TRUE;
1955 if (pending & CSTP_INTERRUPT)
1956 got_int = TRUE;
1957 if (pending & CSTP_THROW)
1958 need_rethrow = TRUE; /* did_throw will be set by do_one_cmd() */
1959
1960 /* Report if required by the 'verbose' option or when debugging. */
1961 report_resume_pending(pending,
1962 (pending & CSTP_THROW) ? (void *)current_exception : NULL);
1963 }
1964 }
1965
1966
1967 /*
1823 * Make conditionals inactive and discard what's pending in finally clauses 1968 * Make conditionals inactive and discard what's pending in finally clauses
1824 * until the conditional type searched for or a try conditional not in its 1969 * until the conditional type searched for or a try conditional not in its
1825 * finally clause is reached. If this is in an active catch clause, finish the 1970 * finally clause is reached. If this is in an active catch clause, finish the
1826 * caught exception. Return the cstack index where the search stopped. Values 1971 * caught exception. Return the cstack index where the search stopped. Values
1827 * used for "searched_cond" are CSF_WHILE or CSF_TRY or 0, the latter meaning 1972 * used for "searched_cond" are CSF_WHILE or CSF_TRY or 0, the latter meaning