Mercurial > emacs
comparison lib-src/etags.c @ 4051:73aa16fc728d
(consider_token): was `==', now is `='.
(consider_token): DEFUNs now treated like funcs in ctags mode.
(LEVEL_OK_FOR_FUNCDEF): removed.
(C_entries): optimized the test that used LEVEL_OK_FOR_FUNCDEF.
(C_entries): removed a piece of useless code.
(C_entries): making typedef tags is delayed until a semicolon
is met. This handles "typedef int X, Y, Z;" correctly.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 09 Jul 1993 18:56:47 +0000 |
parents | e5e5b3634dd0 |
children | 9535e8ffb209 |
comparison
equal
deleted
inserted
replaced
4050:0439eaf6f94a | 4051:73aa16fc728d |
---|---|
1378 { | 1378 { |
1379 snone, /* nothing seen yet */ | 1379 snone, /* nothing seen yet */ |
1380 skeyseen, /* struct-like keyword seen */ | 1380 skeyseen, /* struct-like keyword seen */ |
1381 stagseen, /* struct-like tag seen */ | 1381 stagseen, /* struct-like tag seen */ |
1382 scolonseen, /* colon seen after struct-like tag */ | 1382 scolonseen, /* colon seen after struct-like tag */ |
1383 sinbody /* in class body: recognize member func defs */ | 1383 sinbody /* in struct body: recognize member func defs*/ |
1384 } STRUCTST; | 1384 } STRUCTST; |
1385 STRUCTST structdef; | 1385 STRUCTST structdef; |
1386 /* | 1386 /* |
1387 * When structdef is stagseen, scolonseen, or sinbody, structtag is the | 1387 * When structdef is stagseen, scolonseen, or sinbody, structtag is the |
1388 * struct tag, and structkey is the preceding struct-like keyword. | 1388 * struct tag, and structkey is the preceding struct-like keyword. |
1417 * C_entries () | 1417 * C_entries () |
1418 * This routine finds functions, typedefs, #define's and | 1418 * This routine finds functions, typedefs, #define's and |
1419 * struct/union/enum definitions in C syntax and adds them | 1419 * struct/union/enum definitions in C syntax and adds them |
1420 * to the list. | 1420 * to the list. |
1421 */ | 1421 */ |
1422 | |
1423 /* | |
1424 * LEVEL_OK_FOR_FUNCDEF allows C++ function definition within class body. | |
1425 * Currently typdef and structdef stuff (typedefs and struct | |
1426 * definitions) are only noticed when level==0, but that may change. | |
1427 */ | |
1428 #define LEVEL_OK_FOR_FUNCDEF() \ | |
1429 (level==0 || (cplpl && level==1 && structdef==sinbody)) | |
1430 | 1422 |
1431 #define curlb (lbs[curndx].lb) | 1423 #define curlb (lbs[curndx].lb) |
1432 #define othlb (lbs[1-curndx].lb) | 1424 #define othlb (lbs[1-curndx].lb) |
1433 #define newlb (lbs[newndx].lb) | 1425 #define newlb (lbs[newndx].lb) |
1434 #define curlinepos (lbs[curndx].linepos) | 1426 #define curlinepos (lbs[curndx].linepos) |
1465 int curndx, newndx; /* indices for current and new lb */ | 1457 int curndx, newndx; /* indices for current and new lb */ |
1466 TOKEN tok; /* latest token read for funcdef & structdef */ | 1458 TOKEN tok; /* latest token read for funcdef & structdef */ |
1467 char tokb[BUFSIZ]; /* latest token name for funcdef & structdef */ | 1459 char tokb[BUFSIZ]; /* latest token name for funcdef & structdef */ |
1468 register int tokoff; /* offset in line of start of latest token */ | 1460 register int tokoff; /* offset in line of start of latest token */ |
1469 register int toklen; /* length of latest token */ | 1461 register int toklen; /* length of latest token */ |
1470 int level; /* current curly brace level */ | 1462 int cblev; /* current curly brace level */ |
1471 logical incomm, inquote, inchar, quotednl, midtoken; | 1463 logical incomm, inquote, inchar, quotednl, midtoken; |
1472 logical cplpl; | 1464 logical cplpl; |
1473 | 1465 |
1474 curndx = newndx = 0; | 1466 curndx = newndx = 0; |
1475 lineno = 0; | 1467 lineno = 0; |
1478 *lp = 0; | 1470 *lp = 0; |
1479 | 1471 |
1480 definedef = dnone; funcdef = fnone; typdef= tnone; structdef= snone; | 1472 definedef = dnone; funcdef = fnone; typdef= tnone; structdef= snone; |
1481 next_token_is_func = yacc_rules = FALSE; | 1473 next_token_is_func = yacc_rules = FALSE; |
1482 midtoken = inquote = inchar = incomm = quotednl = FALSE; | 1474 midtoken = inquote = inchar = incomm = quotednl = FALSE; |
1483 level = 0; | 1475 cblev = 0; |
1484 cplpl = c_ext & C_PLPL; | 1476 cplpl = c_ext & C_PLPL; |
1485 | 1477 |
1486 C_create_stabs (); | 1478 C_create_stabs (); |
1487 | 1479 |
1488 while (!feof (inf)) | 1480 while (!feof (inf)) |
1571 lp++; | 1563 lp++; |
1572 definedef = dnone; funcdef = fnone; | 1564 definedef = dnone; funcdef = fnone; |
1573 typdef= tnone; structdef= snone; | 1565 typdef= tnone; structdef= snone; |
1574 next_token_is_func = FALSE; | 1566 next_token_is_func = FALSE; |
1575 midtoken = inquote = inchar = incomm = quotednl = FALSE; | 1567 midtoken = inquote = inchar = incomm = quotednl = FALSE; |
1576 level = 0; | 1568 cblev = 0; |
1577 yacc_rules = !yacc_rules; | 1569 yacc_rules = !yacc_rules; |
1578 continue; | 1570 continue; |
1579 } | 1571 } |
1580 case '#': | 1572 case '#': |
1581 if (lp == newlb.buffer + 1 && definedef == dnone) | 1573 if (lp == newlb.buffer + 1 && definedef == dnone) |
1582 definedef = dsharpseen; | 1574 definedef = dsharpseen; |
1583 continue; | 1575 continue; |
1584 } /* switch (c) */ | 1576 } /* switch (c) */ |
1585 | 1577 |
1586 | 1578 |
1587 if (LEVEL_OK_FOR_FUNCDEF () | 1579 /* Consider token only if some complicated conditions are satisfied. */ |
1580 if (((cblev == 0 && structdef != scolonseen) | |
1581 || (cblev == 1 && cplpl && structdef == sinbody)) | |
1588 && definedef != dignorerest | 1582 && definedef != dignorerest |
1589 && structdef != scolonseen | |
1590 && funcdef != finlist) | 1583 && funcdef != finlist) |
1591 { | 1584 { |
1592 if (midtoken) | 1585 if (midtoken) |
1593 { | 1586 { |
1594 if (endtoken (c)) | 1587 if (endtoken (c)) |
1610 tok.p = newlb.buffer + tokoff; | 1603 tok.p = newlb.buffer + tokoff; |
1611 tok.len = toklen; | 1604 tok.len = toklen; |
1612 tok.rewritten = FALSE; | 1605 tok.rewritten = FALSE; |
1613 if (yacc_rules | 1606 if (yacc_rules |
1614 || consider_token (c, lp, &tok, | 1607 || consider_token (c, lp, &tok, |
1615 c_ext, level, &is_func)) | 1608 c_ext, cblev, &is_func)) |
1616 { | 1609 { |
1617 if (structdef == sinbody | 1610 if (structdef == sinbody |
1618 && definedef == dnone && is_func) | 1611 && definedef == dnone && is_func) |
1619 { /* function defined in C++ class body */ | 1612 { /* function defined in C++ class body */ |
1620 sprintf (tokb, "%s::%.*s", | 1613 sprintf (tokb, "%s::%.*s", |
1626 else | 1619 else |
1627 { | 1620 { |
1628 sprintf (tokb, "%.*s", tok.len, tok.p); | 1621 sprintf (tokb, "%.*s", tok.len, tok.p); |
1629 } | 1622 } |
1630 | 1623 |
1631 if (funcdef == ftagseen || structdef == stagseen) | 1624 if (funcdef == ftagseen |
1625 || structdef == stagseen | |
1626 || typdef == tend) | |
1632 { | 1627 { |
1633 if (newndx == curndx) | 1628 if (newndx == curndx) |
1634 curndx = 1 - curndx; /* switch line buffers */ | 1629 curndx = 1 - curndx; /* switch line buffers */ |
1635 } | 1630 } |
1636 else | 1631 else |
1681 MAKE_TAG_FROM_OTH_LB (FALSE); | 1676 MAKE_TAG_FROM_OTH_LB (FALSE); |
1682 funcdef == fnone; | 1677 funcdef == fnone; |
1683 } | 1678 } |
1684 break; | 1679 break; |
1685 case ';': | 1680 case ';': |
1681 if (cblev == 0 && typdef == tend) | |
1682 { | |
1683 typdef = tnone; | |
1684 MAKE_TAG_FROM_OTH_LB (FALSE); | |
1685 } | |
1686 funcdef = fnone; | 1686 funcdef = fnone; |
1687 /* FALLTHRU */ | 1687 /* FALLTHRU */ |
1688 case ',': | 1688 case ',': |
1689 if (funcdef != finlist) | |
1690 funcdef = fnone; | |
1691 if (level == 0 && typdef == tend) | |
1692 typdef = tnone; | |
1693 /* FALLTHRU */ | 1689 /* FALLTHRU */ |
1694 case '[': | 1690 case '[': |
1695 if (funcdef != finlist) | 1691 if (funcdef != finlist) |
1696 funcdef = fnone; | 1692 funcdef = fnone; |
1697 if (structdef == stagseen) | 1693 if (structdef == stagseen) |
1726 case scolonseen: /* named struct */ | 1722 case scolonseen: /* named struct */ |
1727 structdef = sinbody; | 1723 structdef = sinbody; |
1728 MAKE_TAG_FROM_OTH_LB (FALSE); | 1724 MAKE_TAG_FROM_OTH_LB (FALSE); |
1729 break; | 1725 break; |
1730 } | 1726 } |
1731 level++; | 1727 cblev++; |
1732 /* FALLTHRU */ | 1728 /* FALLTHRU */ |
1733 case '*': | 1729 case '*': |
1734 if (funcdef == flistseen) | 1730 if (funcdef == flistseen) |
1735 { | 1731 { |
1736 MAKE_TAG_FROM_OTH_LB (TRUE); | 1732 MAKE_TAG_FROM_OTH_LB (TRUE); |
1737 funcdef = fnone; | 1733 funcdef = fnone; |
1738 } | 1734 } |
1739 break; | 1735 break; |
1740 case '}': | 1736 case '}': |
1741 if (!noindentypedefs && lp == newlb.buffer + 1) | 1737 if (!noindentypedefs && lp == newlb.buffer + 1) |
1742 level = 0; /* reset level if first column */ | 1738 cblev = 0; /* reset curly brace level if first column */ |
1743 else if (level > 0) | 1739 else if (cblev > 0) |
1744 level--; | 1740 cblev--; |
1745 if (level == 0) | 1741 if (cblev == 0) |
1746 { | 1742 { |
1747 if (typdef == tinbody) | 1743 if (typdef == tinbody) |
1748 typdef = tend; | 1744 typdef = tend; |
1749 structdef = snone; | 1745 structdef = snone; |
1750 (void) strcpy (structtag, "<error 2>"); | 1746 (void) strcpy (structtag, "<error 2>"); |
1783 * typdef IN OUT | 1779 * typdef IN OUT |
1784 * next_token_is_func IN OUT | 1780 * next_token_is_func IN OUT |
1785 */ | 1781 */ |
1786 | 1782 |
1787 logical | 1783 logical |
1788 consider_token (c, lp, tokp, c_ext, level, is_func) | 1784 consider_token (c, lp, tokp, c_ext, cblev, is_func) |
1789 register char c; /* IN: first char after the token */ | 1785 register char c; /* IN: first char after the token */ |
1790 register char *lp; /* IN: lp points to 2nd char after the token */ | 1786 register char *lp; /* IN: lp points to 2nd char after the token */ |
1791 register TOKEN *tokp; /* IN */ | 1787 register TOKEN *tokp; /* IN: token pointer */ |
1792 int c_ext; /* IN */ | 1788 int c_ext; /* IN: C extensions mask */ |
1793 int level; /* IN */ | 1789 int cblev; /* IN: curly brace level */ |
1794 logical *is_func; /* OUT */ | 1790 logical *is_func; /* OUT */ |
1795 { | 1791 { |
1796 logical firsttok; /* TRUE if have seen first token in ()'s */ | 1792 logical firsttok; /* TRUE if have seen first token in ()'s */ |
1797 Stab_entry *tokse = stab_find (get_C_stab (c_ext), tokp->p, tokp->len); | 1793 Stab_entry *tokse = stab_find (get_C_stab (c_ext), tokp->p, tokp->len); |
1798 enum sym_type toktype = stab_type (tokse); | 1794 enum sym_type toktype = stab_type (tokse); |
1869 } | 1865 } |
1870 return (TRUE); | 1866 return (TRUE); |
1871 } | 1867 } |
1872 | 1868 |
1873 /* | 1869 /* |
1874 * This structdef business is currently only invoked when level==0. | 1870 * This structdef business is currently only invoked when cblev==0. |
1875 * It should be recursively invoked whatever the level, and a stack of | 1871 * It should be recursively invoked whatever the curly brace level, |
1876 * states kept, to allow for definitions of structs within structs. | 1872 * and a stack of states kept, to allow for definitions of structs |
1873 * within structs. | |
1877 * | 1874 * |
1878 * This structdef business is NOT invoked when we are ctags and the | 1875 * This structdef business is NOT invoked when we are ctags and the |
1879 * file is plain C. This is because a struct tag may have the same | 1876 * file is plain C. This is because a struct tag may have the same |
1880 * name as another tag, and this loses with ctags. | 1877 * name as another tag, and this loses with ctags. |
1881 * | 1878 * |
1887 switch (toktype) | 1884 switch (toktype) |
1888 { | 1885 { |
1889 case st_C_struct: | 1886 case st_C_struct: |
1890 case st_C_enum: | 1887 case st_C_enum: |
1891 if (typdef == ttypedseen | 1888 if (typdef == ttypedseen |
1892 || (typedefs_and_cplusplus && level == 0 && structdef == snone)) | 1889 || (typedefs_and_cplusplus && cblev == 0 && structdef == snone)) |
1893 { | 1890 { |
1894 structdef = skeyseen; | 1891 structdef = skeyseen; |
1895 structkey = tokse; | 1892 structkey = tokse; |
1896 } | 1893 } |
1897 return (FALSE); | 1894 return (FALSE); |
1936 } | 1933 } |
1937 } | 1934 } |
1938 if (next_token_is_func) | 1935 if (next_token_is_func) |
1939 { | 1936 { |
1940 next_token_is_func = FALSE; | 1937 next_token_is_func = FALSE; |
1938 *is_func = TRUE; | |
1941 return (TRUE); | 1939 return (TRUE); |
1942 } | 1940 } |
1943 | 1941 |
1944 /* A function? */ | 1942 /* A function? */ |
1945 switch (toktype) | 1943 switch (toktype) |
1946 { | 1944 { |
1947 case st_C_typespec: | 1945 case st_C_typespec: |
1948 funcdef == fnone; /* should be useless */ | 1946 funcdef = fnone; /* should be useless */ |
1949 return (FALSE); | 1947 return (FALSE); |
1950 default: | 1948 default: |
1951 funcdef = ftagseen; | 1949 funcdef = ftagseen; |
1952 *is_func = TRUE; | 1950 *is_func = TRUE; |
1953 return (TRUE); | 1951 return (TRUE); |
2404 continue; | 2402 continue; |
2405 c = cp[0]; | 2403 c = cp[0]; |
2406 cp[0] = 0; | 2404 cp[0] = 0; |
2407 (void) strcpy (nambuf, dbp); | 2405 (void) strcpy (nambuf, dbp); |
2408 cp[0] = c; | 2406 cp[0] = c; |
2409 pfnote (nambuf, TRUE, FALSE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno); | 2407 pfnote (nambuf, TRUE, FALSE, lb.buffer, |
2408 cp - lb.buffer + 1, lineno, linecharno); | |
2410 pfcnt++; | 2409 pfcnt++; |
2411 } | 2410 } |
2412 | 2411 |
2413 /* | 2412 /* |
2414 * Scheme tag functions | 2413 * Scheme tag functions |