1*53ee8cc1Swenshuai.xi /* 2*53ee8cc1Swenshuai.xi * Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc. 3*53ee8cc1Swenshuai.xi * 4*53ee8cc1Swenshuai.xi * This program is free software; you can redistribute it and/or 5*53ee8cc1Swenshuai.xi * modify it under the terms of the GNU General Public License as 6*53ee8cc1Swenshuai.xi * published by the Free Software Foundation; either version 2 of the 7*53ee8cc1Swenshuai.xi * License, or (at your option) any later version. 8*53ee8cc1Swenshuai.xi * 9*53ee8cc1Swenshuai.xi * This program is distributed in the hope that it will be useful, 10*53ee8cc1Swenshuai.xi * but WITHOUT ANY WARRANTY; without even the implied warranty of 11*53ee8cc1Swenshuai.xi * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12*53ee8cc1Swenshuai.xi * General Public License for more details. 13*53ee8cc1Swenshuai.xi * 14*53ee8cc1Swenshuai.xi * You should have received a copy of the GNU General Public License 15*53ee8cc1Swenshuai.xi * along with this program; if not, write to the Free Software 16*53ee8cc1Swenshuai.xi * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 17*53ee8cc1Swenshuai.xi * USA 18*53ee8cc1Swenshuai.xi */ 19*53ee8cc1Swenshuai.xi 20*53ee8cc1Swenshuai.xi #ifndef _SRCPOS_H_ 21*53ee8cc1Swenshuai.xi #define _SRCPOS_H_ 22*53ee8cc1Swenshuai.xi 23*53ee8cc1Swenshuai.xi #include <stdio.h> 24*53ee8cc1Swenshuai.xi 25*53ee8cc1Swenshuai.xi struct srcfile_state { 26*53ee8cc1Swenshuai.xi FILE *f; 27*53ee8cc1Swenshuai.xi char *name; 28*53ee8cc1Swenshuai.xi char *dir; 29*53ee8cc1Swenshuai.xi int lineno, colno; 30*53ee8cc1Swenshuai.xi struct srcfile_state *prev; 31*53ee8cc1Swenshuai.xi }; 32*53ee8cc1Swenshuai.xi 33*53ee8cc1Swenshuai.xi extern struct srcfile_state *current_srcfile; /* = NULL */ 34*53ee8cc1Swenshuai.xi 35*53ee8cc1Swenshuai.xi FILE *srcfile_relative_open(const char *fname, char **fullnamep); 36*53ee8cc1Swenshuai.xi void srcfile_push(const char *fname); 37*53ee8cc1Swenshuai.xi int srcfile_pop(void); 38*53ee8cc1Swenshuai.xi 39*53ee8cc1Swenshuai.xi struct srcpos { 40*53ee8cc1Swenshuai.xi int first_line; 41*53ee8cc1Swenshuai.xi int first_column; 42*53ee8cc1Swenshuai.xi int last_line; 43*53ee8cc1Swenshuai.xi int last_column; 44*53ee8cc1Swenshuai.xi struct srcfile_state *file; 45*53ee8cc1Swenshuai.xi }; 46*53ee8cc1Swenshuai.xi 47*53ee8cc1Swenshuai.xi #define YYLTYPE struct srcpos 48*53ee8cc1Swenshuai.xi 49*53ee8cc1Swenshuai.xi #define YYLLOC_DEFAULT(Current, Rhs, N) \ 50*53ee8cc1Swenshuai.xi do { \ 51*53ee8cc1Swenshuai.xi if (N) { \ 52*53ee8cc1Swenshuai.xi (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \ 53*53ee8cc1Swenshuai.xi (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \ 54*53ee8cc1Swenshuai.xi (Current).last_line = YYRHSLOC(Rhs, N).last_line; \ 55*53ee8cc1Swenshuai.xi (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ 56*53ee8cc1Swenshuai.xi (Current).file = YYRHSLOC(Rhs, N).file; \ 57*53ee8cc1Swenshuai.xi } else { \ 58*53ee8cc1Swenshuai.xi (Current).first_line = (Current).last_line = \ 59*53ee8cc1Swenshuai.xi YYRHSLOC(Rhs, 0).last_line; \ 60*53ee8cc1Swenshuai.xi (Current).first_column = (Current).last_column = \ 61*53ee8cc1Swenshuai.xi YYRHSLOC(Rhs, 0).last_column; \ 62*53ee8cc1Swenshuai.xi (Current).file = YYRHSLOC (Rhs, 0).file; \ 63*53ee8cc1Swenshuai.xi } \ 64*53ee8cc1Swenshuai.xi } while (0) 65*53ee8cc1Swenshuai.xi 66*53ee8cc1Swenshuai.xi 67*53ee8cc1Swenshuai.xi /* 68*53ee8cc1Swenshuai.xi * Fictional source position used for IR nodes that are 69*53ee8cc1Swenshuai.xi * created without otherwise knowing a true source position. 70*53ee8cc1Swenshuai.xi * For example,constant definitions from the command line. 71*53ee8cc1Swenshuai.xi */ 72*53ee8cc1Swenshuai.xi extern struct srcpos srcpos_empty; 73*53ee8cc1Swenshuai.xi 74*53ee8cc1Swenshuai.xi extern void srcpos_update(struct srcpos *pos, const char *text, int len); 75*53ee8cc1Swenshuai.xi extern struct srcpos *srcpos_copy(struct srcpos *pos); 76*53ee8cc1Swenshuai.xi extern char *srcpos_string(struct srcpos *pos); 77*53ee8cc1Swenshuai.xi extern void srcpos_dump(struct srcpos *pos); 78*53ee8cc1Swenshuai.xi 79*53ee8cc1Swenshuai.xi extern void srcpos_verror(struct srcpos *pos, char const *, va_list va) 80*53ee8cc1Swenshuai.xi __attribute__((format(printf, 2, 0))); 81*53ee8cc1Swenshuai.xi extern void srcpos_error(struct srcpos *pos, char const *, ...) 82*53ee8cc1Swenshuai.xi __attribute__((format(printf, 2, 3))); 83*53ee8cc1Swenshuai.xi extern void srcpos_warn(struct srcpos *pos, char const *, ...) 84*53ee8cc1Swenshuai.xi __attribute__((format(printf, 2, 3))); 85*53ee8cc1Swenshuai.xi 86*53ee8cc1Swenshuai.xi #endif /* _SRCPOS_H_ */ 87