00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CU_LOCATION_H
00019 #define CU_LOCATION_H
00020
00021 #include <cu/fwd.h>
00022 #include <cu/debug.h>
00023 #include <limits.h>
00024
00025 CU_BEGIN_DECLARATIONS
00026
00027
00028
00029
00030
00031
00032
00033
00034 struct cu_locorigin
00035 {
00036 cu_str_t path;
00037 int tabstop;
00038 };
00039
00040
00041
00042 void cu_locorigin_init(cu_locorigin_t origin, cu_str_t path, int tabstop);
00043
00044
00045
00046 cu_locorigin_t cu_locorigin_new(cu_str_t path, int tabstop);
00047
00048
00049
00050 int cu_locorigin_cmp(cu_locorigin_t origin0, cu_locorigin_t origin1);
00051
00052
00053 CU_SINLINE cu_str_t cu_locorigin_path(cu_locorigin_t origin)
00054 { return origin->path; }
00055
00056
00057 CU_SINLINE int cu_locorigin_tabstop(cu_locorigin_t origin)
00058 { return origin->tabstop; }
00059
00060
00061
00062
00063
00064
00065
00066
00067 struct cu_locbound
00068 {
00069 cu_locorigin_t origin;
00070 int line;
00071 short col;
00072 };
00073
00074
00075 void cu_locbound_init(cu_locbound_t bound, cu_locorigin_t origin,
00076 int line, int column);
00077
00078
00079
00080 void cu_locbound_init_file(cu_locbound_t bound, cu_str_t path,
00081 int line, int column);
00082
00083
00084 void cu_locbound_init_copy(cu_locbound_t bound, cu_locbound_t bound0);
00085
00086
00087
00088 cu_locbound_t cu_locbound_new(cu_locorigin_t origin,
00089 int line, int column);
00090
00091
00092
00093
00094 cu_locbound_t cu_locbound_new_file(cu_str_t path, int line, int column);
00095
00096
00097 cu_locbound_t cu_locbound_new_copy(cu_locbound_t bound0);
00098
00099
00100
00101
00102 int cu_locbound_cmp(cu_locbound_t bound0, cu_locbound_t bound1);
00103
00104
00105 CU_SINLINE cu_locorigin_t cu_locbound_origin(cu_locbound_t bound)
00106 { return bound->origin; }
00107
00108
00109 CU_SINLINE cu_str_t cu_locbound_path(cu_locbound_t bound)
00110 { return bound->origin->path; }
00111
00112
00113 CU_SINLINE int cu_locbound_line(cu_locbound_t bound)
00114 { return bound->line; }
00115
00116
00117 CU_SINLINE int cu_locbound_column(cu_locbound_t bound)
00118 { return bound->col; }
00119
00120
00121 CU_SINLINE void cu_locbound_skip(cu_locbound_t bound, int n)
00122 {
00123 cu_debug_assert(bound->col >= 0);
00124 bound->col += n;
00125 }
00126
00127
00128 CU_SINLINE void cu_locbound_skip_1(cu_locbound_t bound)
00129 { cu_locbound_skip(bound, 1); }
00130
00131
00132 void cu_locbound_put_tab(cu_locbound_t bound);
00133
00134
00135 void cu_locbound_put_newline(cu_locbound_t bound);
00136
00137
00138
00139 void cu_locbound_put_char(cu_locbound_t bound, char ch);
00140
00141
00142
00143
00144
00145
00146
00147 struct cu_location
00148 {
00149 cu_locorigin_t origin;
00150 int lbline, ubline;
00151 short lbcol, ubcol;
00152 cu_location_t chain_tail;
00153 };
00154
00155
00156 void cu_location_init(cu_location_t loc, cu_locorigin_t origin,
00157 int lbline, int lbcol, int ubline, int ubcol);
00158
00159
00160 void cu_location_init_copy(cu_location_t loc, cu_location_t loc0);
00161
00162
00163
00164 void cu_location_init_range(cu_location_t loc,
00165 cu_locbound_t lbound, cu_locbound_t ubound);
00166
00167
00168
00169 void cu_location_init_cover(cu_location_t loc,
00170 cu_location_t loc0, cu_location_t loc1);
00171
00172
00173 void cu_location_init_point(cu_location_t loc, cu_locbound_t bound);
00174
00175
00176 void cu_location_init_point_lb(cu_location_t loc, cu_location_t loc0);
00177
00178
00179 void cu_location_init_point_ub(cu_location_t loc, cu_location_t loc0);
00180
00181
00182 cu_location_t cu_location_new(cu_locorigin_t origin,
00183 int lbline, int lbcol, int ubline, int ubcol);
00184
00185
00186 cu_location_t cu_location_new_copy(cu_location_t loc0);
00187
00188
00189
00190 cu_location_t cu_location_new_range(cu_locbound_t lbound, cu_locbound_t ubound);
00191
00192
00193
00194 cu_location_t cu_location_new_cover(cu_location_t loc0, cu_location_t loc1);
00195
00196
00197 cu_location_t cu_location_new_point(cu_locbound_t bound);
00198
00199
00200 cu_location_t cu_location_new_point_lb(cu_location_t loc0);
00201
00202
00203 cu_location_t cu_location_new_point_ub(cu_location_t loc0);
00204
00205
00206 CU_SINLINE cu_locorigin_t cu_location_origin(cu_location_t loc)
00207 { return loc->origin; }
00208
00209
00210
00211 CU_SINLINE int cu_location_origin_cmp(cu_location_t loc0, cu_location_t loc1)
00212 { return cu_locorigin_cmp(loc0->origin, loc1->origin); }
00213
00214
00215
00216
00217 int cu_location_cmp(cu_location_t loc0, cu_location_t loc1);
00218
00219
00220 CU_SINLINE cu_str_t cu_location_path(cu_location_t loc)
00221 { return cu_locorigin_path(loc->origin); }
00222
00223
00224
00225 CU_SINLINE int cu_location_height(cu_location_t loc)
00226 { return loc->ubline - loc->lbline; }
00227
00228
00229
00230 CU_SINLINE int cu_location_length(cu_location_t loc)
00231 { return loc->lbline != loc->ubline? INT_MAX : loc->ubcol - loc->lbcol; }
00232
00233
00234 cu_locbound_t cu_location_lbound(cu_location_t loc);
00235
00236
00237 cu_locbound_t cu_location_ubound(cu_location_t loc);
00238
00239
00240 CU_SINLINE int cu_location_lb_line(cu_location_t loc) { return loc->lbline; }
00241
00242
00243 CU_SINLINE int cu_location_lb_column(cu_location_t loc) { return loc->lbcol; }
00244
00245
00246 CU_SINLINE int cu_location_ub_line(cu_location_t loc) { return loc->ubline; }
00247
00248
00249 CU_SINLINE int cu_location_ub_column(cu_location_t loc) { return loc->ubcol; }
00250
00251
00252 void cu_location_fprint(cu_location_t loc, FILE *file);
00253
00254
00255
00256 CU_END_DECLARATIONS
00257
00258 #endif