0001
0002
0003
0004
0005
0006 #ifndef SRCPOS_H
0007 #define SRCPOS_H
0008
0009 #include <stdio.h>
0010 #include <stdbool.h>
0011 #include "util.h"
0012
0013 struct srcfile_state {
0014 FILE *f;
0015 char *name;
0016 char *dir;
0017 int lineno, colno;
0018 struct srcfile_state *prev;
0019 };
0020
0021 extern FILE *depfile;
0022 extern struct srcfile_state *current_srcfile;
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 FILE *srcfile_relative_open(const char *fname, char **fullnamep);
0044
0045 void srcfile_push(const char *fname);
0046 bool srcfile_pop(void);
0047
0048
0049
0050
0051
0052
0053
0054
0055 void srcfile_add_search_path(const char *dirname);
0056
0057 struct srcpos {
0058 int first_line;
0059 int first_column;
0060 int last_line;
0061 int last_column;
0062 struct srcfile_state *file;
0063 struct srcpos *next;
0064 };
0065
0066 #define YYLTYPE struct srcpos
0067
0068 #define YYLLOC_DEFAULT(Current, Rhs, N) \
0069 do { \
0070 if (N) { \
0071 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
0072 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
0073 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
0074 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
0075 (Current).file = YYRHSLOC(Rhs, N).file; \
0076 } else { \
0077 (Current).first_line = (Current).last_line = \
0078 YYRHSLOC(Rhs, 0).last_line; \
0079 (Current).first_column = (Current).last_column = \
0080 YYRHSLOC(Rhs, 0).last_column; \
0081 (Current).file = YYRHSLOC (Rhs, 0).file; \
0082 } \
0083 (Current).next = NULL; \
0084 } while (0)
0085
0086
0087 extern void srcpos_update(struct srcpos *pos, const char *text, int len);
0088 extern struct srcpos *srcpos_copy(struct srcpos *pos);
0089 extern struct srcpos *srcpos_extend(struct srcpos *new_srcpos,
0090 struct srcpos *old_srcpos);
0091 extern char *srcpos_string(struct srcpos *pos);
0092 extern char *srcpos_string_first(struct srcpos *pos, int level);
0093 extern char *srcpos_string_last(struct srcpos *pos, int level);
0094
0095
0096 extern void PRINTF(3, 0) srcpos_verror(struct srcpos *pos, const char *prefix,
0097 const char *fmt, va_list va);
0098 extern void PRINTF(3, 4) srcpos_error(struct srcpos *pos, const char *prefix,
0099 const char *fmt, ...);
0100
0101 extern void srcpos_set_line(char *f, int l);
0102
0103 #endif