Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc.
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; /* = NULL */
0022 extern struct srcfile_state *current_srcfile; /* = NULL */
0023 
0024 /**
0025  * Open a source file.
0026  *
0027  * If the source file is a relative pathname, then it is searched for in the
0028  * current directory (the directory of the last source file read) and after
0029  * that in the search path.
0030  *
0031  * We work through the search path in order from the first path specified to
0032  * the last.
0033  *
0034  * If the file is not found, then this function does not return, but calls
0035  * die().
0036  *
0037  * @param fname     Filename to search
0038  * @param fullnamep If non-NULL, it is set to the allocated filename of the
0039  *          file that was opened. The caller is then responsible
0040  *          for freeing the pointer.
0041  * @return pointer to opened FILE
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  * Add a new directory to the search path for input files
0050  *
0051  * The new path is added at the end of the list.
0052  *
0053  * @param dirname   Directory to add
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 /* SRCPOS_H */