# 1 "main.c" # 1 "include/stdio.h" 1 # 123 "include/stdio.h" 3 # 10 "main.c" 2
Unified · Split
| @@ -2895,8 +2895,9 @@ void preprocess_new() · 2894 unmodified lines | ||
| 2895 | 2895 | static int tcc_preprocess(TCCState *s1) |
| 2896 | 2896 | { |
| 2897 | 2897 | Sym *define_start; |
| 2898 | − BufferedFile *file_ref; | |
| 2899 | − int token_seen, line_ref; | |
| 2898 | + BufferedFile *file_ref, **iptr, **iptr_new; | |
| 2899 | + int token_seen, line_ref, d; | |
| 2900 | + const char *s; | |
| 2900 | 2901 | |
| 2901 | 2902 | preprocess_init(s1); |
| 2902 | 2903 | define_start = define_stack; |
| @@ -2908,24 +2909,38 @@ static int tcc_preprocess(TCCState *s1) · 5 unmodified lines | ||
| 2908 | 2909 | line_ref = 0; |
| 2909 | 2910 | file_ref = NULL; |
| 2910 | 2911 | |
| 2912 | + iptr = s1->include_stack_ptr; | |
| 2911 | 2913 | for (;;) { |
| 2912 | 2914 | next(); |
| 2913 | 2915 | if (tok == TOK_EOF) { |
| 2914 | 2916 | break; |
| 2917 | + } else if (file != file_ref) { | |
| 2918 | + goto print_line; | |
| 2915 | 2919 | } else if (tok == TOK_LINEFEED) { |
| 2916 | 2920 | if (!token_seen) |
| 2917 | 2921 | continue; |
| 2918 | 2922 | ++line_ref; |
| 2919 | 2923 | token_seen = 0; |
| 2920 | 2924 | } else if (!token_seen) { |
| 2921 | − int d = file->line_num - line_ref; | |
| 2922 | − if (file != file_ref || d < 0 || d >= 8) | |
| 2923 | − fprintf(s1->outfile, "# %d \"%s\"\n", file->line_num, file->filename); | |
| 2924 | − else | |
| 2925 | + d = file->line_num - line_ref; | |
| 2926 | + if (file != file_ref || d < 0 || d >= 8) { | |
| 2927 | +print_line: | |
| 2928 | + iptr_new = s1->include_stack_ptr; | |
| 2929 | + s = iptr_new > iptr ? " 1" | |
| 2930 | + : iptr_new < iptr ? " 2" | |
| 2931 | + : iptr_new > s1->include_stack ? " 3" | |
| 2932 | + : "" | |
| 2933 | + ; | |
| 2934 | + iptr = iptr_new; | |
| 2935 | + fprintf(s1->outfile, "# %d \"%s\"%s\n", file->line_num, file->filename, s); | |
| 2936 | + } else { | |
| 2925 | 2937 | while (d) |
| 2926 | 2938 | fputs("\n", s1->outfile), --d; |
| 2939 | + } | |
| 2927 | 2940 | line_ref = (file_ref = file)->line_num; |
| 2928 | − token_seen = 1; | |
| 2941 | + token_seen = tok != TOK_LINEFEED; | |
| 2942 | + if (!token_seen) | |
| 2943 | + continue; | |
| 2929 | 2944 | } |
| 2930 | 2945 | fputs(get_tok_str(tok, &tokc), s1->outfile); |
| 2931 | 2946 | } |