| @@ -1056,7 +1056,7 @@ static int macro_is_equal(const int *a, const int *b) · 1055 unmodified lines |
| 1056 | ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg) | 1056 | ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg) |
| 1057 | { | 1057 | { |
| 1058 | Sym *s; | 1058 | Sym *s; |
| 1059 | CSym *def; | 1059 | CSym *def; |
| 1060 | s = define_find(v); | 1060 | s = define_find(v); |
| 1061 | if (s && !macro_is_equal(s->d, str)) | 1061 | if (s && !macro_is_equal(s->d, str)) |
| 1062 | tcc_warning("%s redefined", get_tok_str(v, NULL)); | 1062 | tcc_warning("%s redefined", get_tok_str(v, NULL)); |
| @@ -1064,19 +1064,19 @@ ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg) · 1 unmodified line |
| 1064 | s->d = str; | 1064 | s->d = str; |
| 1065 | s->next = first_arg; | 1065 | s->next = first_arg; |
| 1066 | def = &table_ident[v - TOK_IDENT]->sym_define; | 1066 | def = &table_ident[v - TOK_IDENT]->sym_define; |
| 1067 | def->data[def->off] = s; | 1067 | def->data[def->off] = s; |
| 1068 | } | 1068 | } |
| 1069 | | 1069 | |
| 1070 | /* undefined a define symbol. Its name is just set to zero */ | 1070 | /* undefined a define symbol. Its name is just set to zero */ |
| 1071 | ST_FUNC void define_undef(Sym *s) | 1071 | ST_FUNC void define_undef(Sym *s) |
| 1072 | { | 1072 | { |
| 1073 | int v; | 1073 | int v; |
| 1074 | CSym *def; | 1074 | CSym *def; |
| 1075 | v = s->v - TOK_IDENT; | 1075 | v = s->v - TOK_IDENT; |
| 1076 | if ((unsigned)v < (unsigned)(tok_ident - TOK_IDENT)){ | 1076 | if ((unsigned)v < (unsigned)(tok_ident - TOK_IDENT)){ |
| 1077 | def = &table_ident[v]->sym_define; | 1077 | def = &table_ident[v]->sym_define; |
| 1078 | def->data[def->off] = NULL; | 1078 | def->data[def->off] = NULL; |
| 1079 | } | 1079 | } |
| 1080 | } | 1080 | } |
| 1081 | | 1081 | |
| 1082 | ST_INLN Sym *define_find(int v) | 1082 | ST_INLN Sym *define_find(int v) |
| @@ -1085,7 +1085,7 @@ ST_INLN Sym *define_find(int v) · 2 unmodified lines |
| 1085 | v -= TOK_IDENT; | 1085 | v -= TOK_IDENT; |
| 1086 | if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT)) | 1086 | if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT)) |
| 1087 | return NULL; | 1087 | return NULL; |
| 1088 | def = &table_ident[v]->sym_define; | 1088 | def = &table_ident[v]->sym_define; |
| 1089 | return def->data[def->off]; | 1089 | return def->data[def->off]; |
| 1090 | } | 1090 | } |
| 1091 | | 1091 | |
| @@ -1094,7 +1094,7 @@ ST_FUNC void free_defines(Sym *b) · 2 unmodified lines |
| 1094 | { | 1094 | { |
| 1095 | Sym *top, *tmp; | 1095 | Sym *top, *tmp; |
| 1096 | int v; | 1096 | int v; |
| 1097 | CSym *def; | 1097 | CSym *def; |
| 1098 | | 1098 | |
| 1099 | top = define_stack; | 1099 | top = define_stack; |
| 1100 | while (top != b) { | 1100 | while (top != b) { |
| @@ -1104,12 +1104,12 @@ ST_FUNC void free_defines(Sym *b) · 3 unmodified lines |
| 1104 | tok_str_free(top->d); | 1104 | tok_str_free(top->d); |
| 1105 | v = top->v - TOK_IDENT; | 1105 | v = top->v - TOK_IDENT; |
| 1106 | if ((unsigned)v < (unsigned)(tok_ident - TOK_IDENT)){ | 1106 | if ((unsigned)v < (unsigned)(tok_ident - TOK_IDENT)){ |
| 1107 | def = &table_ident[v]->sym_define; | 1107 | def = &table_ident[v]->sym_define; |
| 1108 | if(def->off) | 1108 | if(def->off) |
| 1109 | def->off = 0; | 1109 | def->off = 0; |
| 1110 | if(def->data[0]) | 1110 | if(def->data[0]) |
| 1111 | def->data[0] = NULL; | 1111 | def->data[0] = NULL; |
| 1112 | } | 1112 | } |
| 1113 | sym_free(top); | 1113 | sym_free(top); |
| 1114 | top = tmp; | 1114 | top = tmp; |
| 1115 | } | 1115 | } |
| @@ -1398,8 +1398,8 @@ read_name: · 282 unmodified lines |
| 1398 | } else | 1398 | } else |
| 1399 | inp(); | 1399 | inp(); |
| 1400 | } | 1400 | } |
| 1401 | if (ch != c) | 1401 | if (ch != c) |
| 1402 | goto include_syntax; | 1402 | goto include_syntax; |
| 1403 | *p = '\0'; | 1403 | *p = '\0'; |
| 1404 | minp(); | 1404 | minp(); |
| 1405 | #if 0 | 1405 | #if 0 |
| @@ -1438,8 +1438,8 @@ read_name: · 32 unmodified lines |
| 1438 | c = '>'; | 1438 | c = '>'; |
| 1439 | } | 1439 | } |
| 1440 | } | 1440 | } |
| 1441 | if(!buf[0]) | 1441 | if(!buf[0]) |
| 1442 | tcc_error(" empty filename in #include"); | 1442 | tcc_error(" empty filename in #include"); |
| 1443 | | 1443 | |
| 1444 | if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE) | 1444 | if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE) |
| 1445 | tcc_error("#include recursion too deep"); | 1445 | tcc_error("#include recursion too deep"); |
| @@ -1588,9 +1588,9 @@ skip: · 142 unmodified lines |
| 1588 | file->ifndef_macro = 0; | 1588 | file->ifndef_macro = 0; |
| 1589 | tok_flags |= TOK_FLAG_ENDIF; | 1589 | tok_flags |= TOK_FLAG_ENDIF; |
| 1590 | } | 1590 | } |
| 1591 | next_nomacro(); | 1591 | next_nomacro(); |
| 1592 | if (tok != TOK_LINEFEED) | 1592 | if (tok != TOK_LINEFEED) |
| 1593 | tcc_warning("Ignoring: %s", get_tok_str(tok, &tokc)); | 1593 | tcc_warning("Ignoring: %s", get_tok_str(tok, &tokc)); |
| 1594 | break; | 1594 | break; |
| 1595 | case TOK_LINE: | 1595 | case TOK_LINE: |
| 1596 | next(); | 1596 | next(); |
| @@ -1626,144 +1626,144 @@ skip: · 29 unmodified lines |
| 1626 | tcc_warning("#warning %s", buf); | 1626 | tcc_warning("#warning %s", buf); |
| 1627 | break; | 1627 | break; |
| 1628 | case TOK_PRAGMA: | 1628 | case TOK_PRAGMA: |
| 1629 | next(); | 1629 | next(); |
| 1630 | if (tok == TOK_pack && parse_flags & PARSE_FLAG_PACK) { | 1630 | if (tok == TOK_pack && parse_flags & PARSE_FLAG_PACK) { |
| 1631 | /* | 1631 | /* |
| 1632 | This may be: | 1632 | This may be: |
| 1633 | #pragma pack(1) // set | 1633 | #pragma pack(1) // set |
| 1634 | #pragma pack() // reset to default | 1634 | #pragma pack() // reset to default |
| 1635 | #pragma pack(push,1) // push & set | 1635 | #pragma pack(push,1) // push & set |
| 1636 | #pragma pack(pop) // restore previous | 1636 | #pragma pack(pop) // restore previous |
| 1637 | */ | 1637 | */ |
| 1638 | next(); | 1638 | next(); |
| 1639 | skip('('); | 1639 | skip('('); |
| 1640 | if (tok == TOK_ASM_pop) { | 1640 | if (tok == TOK_ASM_pop) { |
| 1641 | next(); | 1641 | next(); |
| 1642 | if (s1->pack_stack_ptr <= s1->pack_stack) { | 1642 | if (s1->pack_stack_ptr <= s1->pack_stack) { |
| 1643 | stk_error: | 1643 | stk_error: |
| 1644 | tcc_error("out of pack stack"); | 1644 | tcc_error("out of pack stack"); |
| 1645 | } | 1645 | } |
| 1646 | s1->pack_stack_ptr--; | 1646 | s1->pack_stack_ptr--; |
| 1647 | } else { | 1647 | } else { |
| 1648 | int val = 0; | 1648 | int val = 0; |
| 1649 | if (tok != ')') { | 1649 | if (tok != ')') { |
| 1650 | if (tok == TOK_ASM_push) { | 1650 | if (tok == TOK_ASM_push) { |
| 1651 | next(); | 1651 | next(); |
| 1652 | s1->pack_stack_ptr++; | 1652 | s1->pack_stack_ptr++; |
| 1653 | if (s1->pack_stack_ptr >= s1->pack_stack + PACK_STACK_SIZE) | 1653 | if (s1->pack_stack_ptr >= s1->pack_stack + PACK_STACK_SIZE) |
| 1654 | goto stk_error; | 1654 | goto stk_error; |
| 1655 | skip(','); | 1655 | skip(','); |
| 1656 | } | 1656 | } |
| 1657 | if (tok != TOK_CINT) { | 1657 | if (tok != TOK_CINT) { |
| 1658 | pack_error: | 1658 | pack_error: |
| 1659 | tcc_error("invalid pack pragma"); | 1659 | tcc_error("invalid pack pragma"); |
| 1660 | } | 1660 | } |
| 1661 | val = tokc.i; | 1661 | val = tokc.i; |
| 1662 | if (val < 1 || val > 16) | 1662 | if (val < 1 || val > 16) |
| 1663 | goto pack_error; | 1663 | goto pack_error; |
| 1664 | if (val < 1 || val > 16) | 1664 | if (val < 1 || val > 16) |
| 1665 | tcc_error("Value must be greater than 1 is less than or equal to 16"); | 1665 | tcc_error("Value must be greater than 1 is less than or equal to 16"); |
| 1666 | if ((val & (val - 1)) != 0) | 1666 | if ((val & (val - 1)) != 0) |
| 1667 | tcc_error("Value must be a power of 2 curtain"); | 1667 | tcc_error("Value must be a power of 2 curtain"); |
| 1668 | next(); | 1668 | next(); |
| 1669 | } | 1669 | } |
| 1670 | *s1->pack_stack_ptr = val; | 1670 | *s1->pack_stack_ptr = val; |
| 1671 | skip(')'); | 1671 | skip(')'); |
| 1672 | } | 1672 | } |
| 1673 | }else if (tok == TOK_PUSH_MACRO || tok == TOK_POP_MACRO) { | 1673 | }else if (tok == TOK_PUSH_MACRO || tok == TOK_POP_MACRO) { |
| 1674 | TokenSym *ts; | 1674 | TokenSym *ts; |
| 1675 | CSym *def; | 1675 | CSym *def; |
| 1676 | uint8_t *p1; | 1676 | uint8_t *p1; |
| 1677 | int len, t; | 1677 | int len, t; |
| 1678 | t = tok; | 1678 | t = tok; |
| 1679 | ch = file->buf_ptr[0]; | 1679 | ch = file->buf_ptr[0]; |
| 1680 | skip_spaces(); | 1680 | skip_spaces(); |
| 1681 | if (ch != '(') | 1681 | if (ch != '(') |
| 1682 | goto macro_xxx_syntax; | 1682 | goto macro_xxx_syntax; |
| 1683 | /* XXX: incorrect if comments : use next_nomacro with a special mode */ | 1683 | /* XXX: incorrect if comments : use next_nomacro with a special mode */ |
| 1684 | inp(); | 1684 | inp(); |
| 1685 | skip_spaces(); | 1685 | skip_spaces(); |
| 1686 | if (ch == '\"'){ | 1686 | if (ch == '\"'){ |
| 1687 | inp(); | 1687 | inp(); |
| 1688 | p = buf; | 1688 | p = buf; |
| 1689 | while (ch != '\"' && ch != '\n' && ch != CH_EOF) { | 1689 | while (ch != '\"' && ch != '\n' && ch != CH_EOF) { |
| 1690 | if ((p - buf) < sizeof(buf) - 1) | 1690 | if ((p - buf) < sizeof(buf) - 1) |
| 1691 | *p++ = ch; | 1691 | *p++ = ch; |
| 1692 | if (ch == CH_EOB) { | 1692 | if (ch == CH_EOB) { |
| 1693 | --p; | 1693 | --p; |
| 1694 | handle_stray(); | 1694 | handle_stray(); |
| 1695 | }else | 1695 | }else |
| 1696 | inp(); | 1696 | inp(); |
| 1697 | } | 1697 | } |
| 1698 | if(ch != '\"') | 1698 | if(ch != '\"') |
| 1699 | goto macro_xxx_syntax; | 1699 | goto macro_xxx_syntax; |
| 1700 | *p = '\0'; | 1700 | *p = '\0'; |
| 1701 | minp(); | 1701 | minp(); |
| 1702 | next(); | 1702 | next(); |
| 1703 | }else{ | 1703 | }else{ |
| 1704 | /* computed #pragma macro_xxx for #define xxx */ | 1704 | /* computed #pragma macro_xxx for #define xxx */ |
| 1705 | next(); | 1705 | next(); |
| 1706 | buf[0] = '\0'; | 1706 | buf[0] = '\0'; |
| 1707 | while (tok != ')') { | 1707 | while (tok != ')') { |
| 1708 | if (tok != TOK_STR) { | 1708 | if (tok != TOK_STR) { |
| 1709 | macro_xxx_syntax: | 1709 | macro_xxx_syntax: |
| 1710 | tcc_error("'macro_xxx' expects (\"NAME\")"); | 1710 | tcc_error("'macro_xxx' expects (\"NAME\")"); |
| 1711 | } | 1711 | } |
| 1712 | pstrcat(buf, sizeof(buf), (char *)tokc.cstr->data); | 1712 | pstrcat(buf, sizeof(buf), (char *)tokc.cstr->data); |
| 1713 | next(); | 1713 | next(); |
| 1714 | } | 1714 | } |
| 1715 | } | 1715 | } |
| 1716 | skip (')'); | 1716 | skip (')'); |
| 1717 | if(!buf[0]) | 1717 | if(!buf[0]) |
| 1718 | tcc_error(" empty string in #pragma"); | 1718 | tcc_error(" empty string in #pragma"); |
| 1719 | /* find TokenSym */ | 1719 | /* find TokenSym */ |
| 1720 | p = buf; | 1720 | p = buf; |
| 1721 | while (is_space(*p)) | 1721 | while (is_space(*p)) |
| 1722 | p++; | 1722 | p++; |
| 1723 | p1 = p; | 1723 | p1 = p; |
| 1724 | for(;;){ | 1724 | for(;;){ |
| 1725 | if (!isidnum_table[p[0] - CH_EOF]) | 1725 | if (!isidnum_table[p[0] - CH_EOF]) |
| 1726 | break; | 1726 | break; |
| 1727 | ++p; | 1727 | ++p; |
| 1728 | } | 1728 | } |
| 1729 | len = p - p1; | 1729 | len = p - p1; |
| 1730 | while (is_space(*p)) | 1730 | while (is_space(*p)) |
| 1731 | p++; | 1731 | p++; |
| 1732 | if(!p) //'\0' | 1732 | if(!p) //'\0' |
| 1733 | tcc_error("unrecognized string: %s", buf); | 1733 | tcc_error("unrecognized string: %s", buf); |
| 1734 | ts = tok_alloc(p1, len); | 1734 | ts = tok_alloc(p1, len); |
| 1735 | if(ts){ | 1735 | if(ts){ |
| 1736 | def = &ts->sym_define; | 1736 | def = &ts->sym_define; |
| 1737 | if(t == TOK_PUSH_MACRO){ | 1737 | if(t == TOK_PUSH_MACRO){ |
| 1738 | void *tmp = def->data[def->off]; | 1738 | void *tmp = def->data[def->off]; |
| 1739 | if(tmp){ | 1739 | if(tmp){ |
| 1740 | def->off++; | 1740 | def->off++; |
| 1741 | if(def->off >= def->size){ | 1741 | if(def->off >= def->size){ |
| 1742 | int size = def->size; | 1742 | int size = def->size; |
| 1743 | size *= 2; | 1743 | size *= 2; |
| 1744 | if (size >= MACRO_STACK_SIZE) | 1744 | if (size >= MACRO_STACK_SIZE) |
| 1745 | tcc_error("stack full"); | 1745 | tcc_error("stack full"); |
| 1746 | def->data = tcc_realloc(def->data, size*sizeof(Sym**)); | 1746 | def->data = tcc_realloc(def->data, size*sizeof(Sym**)); |
| 1747 | def->size = size; | 1747 | def->size = size; |
| 1748 | } | 1748 | } |
| 1749 | def->data[def->off] = tmp; | 1749 | def->data[def->off] = tmp; |
| 1750 | } | 1750 | } |
| 1751 | }else{ | 1751 | }else{ |
| 1752 | if(def->off){ | 1752 | if(def->off){ |
| 1753 | --def->off; | 1753 | --def->off; |
| 1754 | }else{ | 1754 | }else{ |
| 1755 | tcc_warning("stack empty"); | 1755 | tcc_warning("stack empty"); |
| 1756 | } | 1756 | } |
| 1757 | } | 1757 | } |
| 1758 | } | 1758 | } |
| 1759 | }else{ | 1759 | }else{ |
| 1760 | fputs("#pragma ", s1->ppfp); | 1760 | fputs("#pragma ", s1->ppfp); |
| 1761 | while (tok != TOK_LINEFEED){ | 1761 | while (tok != TOK_LINEFEED){ |
| 1762 | fputs(get_tok_str(tok, &tokc), s1->ppfp); | 1762 | fputs(get_tok_str(tok, &tokc), s1->ppfp); |
| 1763 | next(); | 1763 | next(); |
| 1764 | } | 1764 | } |
| 1765 | goto the_end; | 1765 | goto the_end; |
| 1766 | } | 1766 | } |
| 1767 | break; | 1767 | break; |
| 1768 | default: | 1768 | default: |
| 1769 | if (tok == TOK_LINEFEED || tok == '!' || tok == TOK_PPNUM) { | 1769 | if (tok == TOK_LINEFEED || tok == '!' || tok == TOK_PPNUM) { |
| @@ -3245,8 +3245,8 @@ ST_FUNC int tcc_preprocess(TCCState *s1) · 1475 unmodified lines |
| 3245 | line_ref = 0; | 3245 | line_ref = 0; |
| 3246 | file_ref = NULL; | 3246 | file_ref = NULL; |
| 3247 | iptr = s1->include_stack_ptr; | 3247 | iptr = s1->include_stack_ptr; |
| 3248 | tok = TOK_LINEFEED; /* print line */ | 3248 | tok = TOK_LINEFEED; /* print line */ |
| 3249 | goto print_line; | 3249 | goto print_line; |
| 3250 | for (;;) { | 3250 | for (;;) { |
| 3251 | next(); | 3251 | next(); |
| 3252 | if (tok == TOK_EOF) { | 3252 | if (tok == TOK_EOF) { |