srcpos.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  17. * USA
  18. */
  19. /*
  20. * Augment the standard YYLTYPE with a filenum index into an
  21. * array of all opened filenames.
  22. */
  23. #include <stdio.h>
  24. struct dtc_file {
  25. char *dir;
  26. const char *name;
  27. FILE *file;
  28. };
  29. #if ! defined(YYLTYPE) && ! defined(YYLTYPE_IS_DECLARED)
  30. typedef struct YYLTYPE {
  31. int first_line;
  32. int first_column;
  33. int last_line;
  34. int last_column;
  35. struct dtc_file *file;
  36. } YYLTYPE;
  37. #define YYLTYPE_IS_DECLARED 1
  38. #define YYLTYPE_IS_TRIVIAL 1
  39. #endif
  40. /* Cater to old parser templates. */
  41. #ifndef YYID
  42. #define YYID(n) (n)
  43. #endif
  44. #define YYLLOC_DEFAULT(Current, Rhs, N) \
  45. do \
  46. if (YYID (N)) \
  47. { \
  48. (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
  49. (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
  50. (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
  51. (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
  52. (Current).file = YYRHSLOC (Rhs, N).file; \
  53. } \
  54. else \
  55. { \
  56. (Current).first_line = (Current).last_line = \
  57. YYRHSLOC (Rhs, 0).last_line; \
  58. (Current).first_column = (Current).last_column = \
  59. YYRHSLOC (Rhs, 0).last_column; \
  60. (Current).file = YYRHSLOC (Rhs, 0).file; \
  61. } \
  62. while (YYID (0))
  63. extern void yyerror(char const *);
  64. extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2)));
  65. extern struct dtc_file *srcpos_file;
  66. struct search_path {
  67. const char *dir; /* NULL for current directory */
  68. struct search_path *prev, *next;
  69. };
  70. extern struct dtc_file *dtc_open_file(const char *fname,
  71. const struct search_path *search);
  72. extern void dtc_close_file(struct dtc_file *file);