VirtualBox

Changeset 3457 in kBuild for trunk/src/kash/parser.c


Ignore:
Timestamp:
Sep 14, 2020 5:34:28 PM (5 years ago)
Author:
bird
Message:

kash: New parser allocator for non-forked-mode.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/parser.c

    r3456 r3457  
    133133        union node *ret;
    134134        int t;
     135
    135136        TRACE2((psh, "parsecmd(%d)\n", interact));
    136 
     137#ifdef KASH_SEPARATE_PARSER_ALLOCATOR
     138        pstackpush(psh);
     139#endif
    137140        psh->tokpushback = 0;
    138141        psh->doprompt = interact;
     
    17851788}
    17861789
     1790static union node *copyparsetreeint(shinstance *psh, union node *src);
     1791
    17871792/*
    1788  * Helper to copyparsetree.
     1793 * Helper to copyparsetreeint.
    17891794 */
    17901795static struct nodelist *
     
    17991804                        *ppnext = dst;
    18001805                        ppnext = &dst->next;
    1801                         dst->n = copyparsetree(psh, src->n);
     1806                        dst->n = copyparsetreeint(psh, src->n);
    18021807                        src = src->next;
    18031808                }
     
    18111816 * Note! This could probably be generated from nodelist.
    18121817 */
    1813 union node *
    1814 copyparsetree(shinstance *psh, union node *src)
     1818static union node *
     1819copyparsetreeint(shinstance *psh, union node *src)
    18151820{
    18161821        /** @todo Try avoid recursion for one of the sub-nodes, esp. when there
     
    18271832                                ret = pstallocnode(psh, sizeof(src->nbinary));
    18281833                                ret->nbinary.type = type;
    1829                                 ret->nbinary.ch1  = copyparsetree(psh, src->nbinary.ch1);
    1830                                 ret->nbinary.ch2  = copyparsetree(psh, src->nbinary.ch2);
     1834                                ret->nbinary.ch1  = copyparsetreeint(psh, src->nbinary.ch1);
     1835                                ret->nbinary.ch2  = copyparsetreeint(psh, src->nbinary.ch2);
    18311836                                break;
    18321837
     
    18351840                                ret->ncmd.type     = NCMD;
    18361841                                ret->ncmd.backgnd  = src->ncmd.backgnd;
    1837                                 ret->ncmd.args     = copyparsetree(psh, src->ncmd.args);
    1838                                 ret->ncmd.redirect = copyparsetree(psh, src->ncmd.redirect);
     1842                                ret->ncmd.args     = copyparsetreeint(psh, src->ncmd.args);
     1843                                ret->ncmd.redirect = copyparsetreeint(psh, src->ncmd.redirect);
    18391844                                break;
    18401845
     
    18511856                                ret = pstallocnode(psh, sizeof(src->nredir));
    18521857                                ret->nredir.type     = type;
    1853                                 ret->nredir.n        = copyparsetree(psh, src->nredir.n);
    1854                                 ret->nredir.redirect = copyparsetree(psh, src->nredir.redirect);
     1858                                ret->nredir.n        = copyparsetreeint(psh, src->nredir.n);
     1859                                ret->nredir.redirect = copyparsetreeint(psh, src->nredir.redirect);
    18551860                                break;
    18561861
     
    18581863                                ret = pstallocnode(psh, sizeof(src->nif));
    18591864                                ret->nif.type        = NIF;
    1860                                 ret->nif.test        = copyparsetree(psh, src->nif.test);
    1861                                 ret->nif.ifpart      = copyparsetree(psh, src->nif.ifpart);
    1862                                 ret->nif.elsepart    = copyparsetree(psh, src->nif.elsepart);
     1865                                ret->nif.test        = copyparsetreeint(psh, src->nif.test);
     1866                                ret->nif.ifpart      = copyparsetreeint(psh, src->nif.ifpart);
     1867                                ret->nif.elsepart    = copyparsetreeint(psh, src->nif.elsepart);
    18631868                                break;
    18641869
     
    18661871                                ret = pstallocnode(psh, sizeof(src->nfor));
    18671872                                ret->nfor.type       = NFOR;
    1868                                 ret->nfor.args       = copyparsetree(psh, src->nfor.args);
    1869                                 ret->nfor.body       = copyparsetree(psh, src->nfor.body);
     1873                                ret->nfor.args       = copyparsetreeint(psh, src->nfor.args);
     1874                                ret->nfor.body       = copyparsetreeint(psh, src->nfor.body);
    18701875                                ret->nfor.var        = pstsavestr(psh, src->nfor.var);
    18711876                                break;
     
    18741879                                ret = pstallocnode(psh, sizeof(src->ncase));
    18751880                                ret->ncase.type      = NCASE;
    1876                                 ret->ncase.expr      = copyparsetree(psh, src->ncase.expr);
    1877                                 ret->ncase.cases     = copyparsetree(psh, src->ncase.cases);
     1881                                ret->ncase.expr      = copyparsetreeint(psh, src->ncase.expr);
     1882                                ret->ncase.cases     = copyparsetreeint(psh, src->ncase.cases);
    18781883                                break;
    18791884
     
    18811886                                ret = pstallocnode(psh, sizeof(src->nclist));
    18821887                                ret->nclist.type     = NCLIST;
    1883                                 ret->nclist.next     = copyparsetree(psh, src->nclist.next);
    1884                                 ret->nclist.pattern  = copyparsetree(psh, src->nclist.pattern);
    1885                                 ret->nclist.body     = copyparsetree(psh, src->nclist.body);
     1888                                ret->nclist.next     = copyparsetreeint(psh, src->nclist.next);
     1889                                ret->nclist.pattern  = copyparsetreeint(psh, src->nclist.pattern);
     1890                                ret->nclist.body     = copyparsetreeint(psh, src->nclist.body);
    18861891                                break;
    18871892
     
    18901895                                ret = pstallocnode(psh, sizeof(src->narg));
    18911896                                ret->narg.type       = type;
    1892                                 ret->narg.next       = copyparsetree(psh, src->narg.next);
     1897                                ret->narg.next       = copyparsetreeint(psh, src->narg.next);
    18931898                                ret->narg.text       = pstsavestr(psh, src->narg.text);
    18941899                                ret->narg.backquote  = copynodelist(psh, src->narg.backquote);
     
    19031908                                ret->nfile.type      = type;
    19041909                                ret->nfile.fd        = src->nfile.fd;
    1905                                 ret->nfile.next      = copyparsetree(psh, src->nfile.next);
    1906                                 ret->nfile.fname     = copyparsetree(psh, src->nfile.fname);
     1910                                ret->nfile.next      = copyparsetreeint(psh, src->nfile.next);
     1911                                ret->nfile.fname     = copyparsetreeint(psh, src->nfile.fname);
    19071912                                break;
    19081913
     
    19121917                                ret->ndup.type       = type;
    19131918                                ret->ndup.fd         = src->ndup.fd;
    1914                                 ret->ndup.next       = copyparsetree(psh, src->ndup.next);
     1919                                ret->ndup.next       = copyparsetreeint(psh, src->ndup.next);
    19151920                                ret->ndup.dupfd      = src->ndup.dupfd;
    1916                                 ret->ndup.vname      = copyparsetree(psh, src->ndup.vname);
     1921                                ret->ndup.vname      = copyparsetreeint(psh, src->ndup.vname);
    19171922                                break;
    19181923
     
    19221927                                ret->nhere.type      = type;
    19231928                                ret->nhere.fd        = src->nhere.fd;
    1924                                 ret->nhere.next      = copyparsetree(psh, src->nhere.next);
    1925                                 ret->nhere.doc       = copyparsetree(psh, src->nhere.doc);
     1929                                ret->nhere.next      = copyparsetreeint(psh, src->nhere.next);
     1930                                ret->nhere.doc       = copyparsetreeint(psh, src->nhere.doc);
    19261931                                break;
    19271932
     
    19291934                                ret = pstallocnode(psh, sizeof(src->nnot));
    19301935                                ret->nnot.type      = NNOT;
    1931                                 ret->nnot.com       = copyparsetree(psh, src->nnot.com);
     1936                                ret->nnot.com       = copyparsetreeint(psh, src->nnot.com);
    19321937                                break;
    19331938
     
    19421947}
    19431948
     1949union node *copyparsetree(shinstance *psh, union node *src)
     1950{
     1951#ifdef KASH_SEPARATE_PARSER_ALLOCATOR
     1952        pstackpush(psh);
     1953#endif
     1954        return copyparsetreeint(psh, src);
     1955}
     1956
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette