comparison dmd/lexer.c @ 846:bc982f1ad106

Merged DMD 1.037 frontend
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sat, 13 Dec 2008 13:15:31 +0100
parents 661384d6a936
children aa953cc960b6
comparison
equal deleted inserted replaced
845:d128381e086e 846:bc982f1ad106
2654 * Append to previous one for this token. 2654 * Append to previous one for this token.
2655 */ 2655 */
2656 2656
2657 void Lexer::getDocComment(Token *t, unsigned lineComment) 2657 void Lexer::getDocComment(Token *t, unsigned lineComment)
2658 { 2658 {
2659 OutBuffer buf; 2659 /* ct tells us which kind of comment it is: '/', '*', or '+'
2660 */
2660 unsigned char ct = t->ptr[2]; 2661 unsigned char ct = t->ptr[2];
2662
2663 /* Start of comment text skips over / * *, / + +, or / / /
2664 */
2661 unsigned char *q = t->ptr + 3; // start of comment text 2665 unsigned char *q = t->ptr + 3; // start of comment text
2662 int linestart = 0;
2663 2666
2664 unsigned char *qend = p; 2667 unsigned char *qend = p;
2665 if (ct == '*' || ct == '+') 2668 if (ct == '*' || ct == '+')
2666 qend -= 2; 2669 qend -= 2;
2667 2670
2681 { 2684 {
2682 if (qend[-1] != ct) 2685 if (qend[-1] != ct)
2683 break; 2686 break;
2684 } 2687 }
2685 } 2688 }
2689
2690 /* Comment is now [q .. qend].
2691 * Canonicalize it into buf[].
2692 */
2693 OutBuffer buf;
2694 int linestart = 0;
2686 2695
2687 for (; q < qend; q++) 2696 for (; q < qend; q++)
2688 { 2697 {
2689 unsigned char c = *q; 2698 unsigned char c = *q;
2690 2699
2758 else 2767 else
2759 *dc = (unsigned char *)buf.extractData(); 2768 *dc = (unsigned char *)buf.extractData();
2760 } 2769 }
2761 2770
2762 /******************************************** 2771 /********************************************
2763 * Combine two document comments into one. 2772 * Combine two document comments into one,
2773 * separated by a newline.
2764 */ 2774 */
2765 2775
2766 unsigned char *Lexer::combineComments(unsigned char *c1, unsigned char *c2) 2776 unsigned char *Lexer::combineComments(unsigned char *c1, unsigned char *c2)
2767 { 2777 {
2778 //printf("Lexer::combineComments('%s', '%s')\n", c1, c2);
2779
2768 unsigned char *c = c2; 2780 unsigned char *c = c2;
2769 2781
2770 if (c1) 2782 if (c1)
2771 { c = c1; 2783 { c = c1;
2772 if (c2) 2784 if (c2)
2773 { size_t len1 = strlen((char *)c1); 2785 { size_t len1 = strlen((char *)c1);
2774 size_t len2 = strlen((char *)c2); 2786 size_t len2 = strlen((char *)c2);
2775 2787
2776 c = (unsigned char *)mem.malloc(len1 + 1 + len2 + 1); 2788 c = (unsigned char *)mem.malloc(len1 + 1 + len2 + 1);
2777 memcpy(c, c1, len1); 2789 memcpy(c, c1, len1);
2778 c[len1] = '\n'; 2790 if (len1 && c1[len1 - 1] != '\n')
2779 memcpy(c + len1 + 1, c2, len2); 2791 { c[len1] = '\n';
2780 c[len1 + 1 + len2] = 0; 2792 len1++;
2793 }
2794 memcpy(c + len1, c2, len2);
2795 c[len1 + len2] = 0;
2781 } 2796 }
2782 } 2797 }
2783 return c; 2798 return c;
2784 } 2799 }
2785 2800
2949 { "__traits", TOKtraits }, 2964 { "__traits", TOKtraits },
2950 { "__overloadset", TOKoverloadset }, 2965 { "__overloadset", TOKoverloadset },
2951 { "__FILE__", TOKfile }, 2966 { "__FILE__", TOKfile },
2952 { "__LINE__", TOKline }, 2967 { "__LINE__", TOKline },
2953 { "shared", TOKshared }, 2968 { "shared", TOKshared },
2969 { "immutable", TOKimmutable },
2954 #endif 2970 #endif
2955 }; 2971 };
2956 2972
2957 int Token::isKeyword() 2973 int Token::isKeyword()
2958 { 2974 {