2019-06-20 23:19:38 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2007-03-23 21:18:41 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc.
|
|
|
|
*/
|
|
|
|
|
2017-10-18 07:59:43 +02:00
|
|
|
#ifndef SRCPOS_H
|
|
|
|
#define SRCPOS_H
|
2008-09-12 20:39:49 +02:00
|
|
|
|
2008-01-04 00:43:31 +01:00
|
|
|
#include <stdio.h>
|
2013-10-28 11:06:53 +01:00
|
|
|
#include <stdbool.h>
|
2017-03-06 02:06:15 +01:00
|
|
|
#include "util.h"
|
2008-01-04 00:43:31 +01:00
|
|
|
|
2009-12-08 04:24:42 +01:00
|
|
|
struct srcfile_state {
|
|
|
|
FILE *f;
|
|
|
|
char *name;
|
2008-01-11 20:14:57 +01:00
|
|
|
char *dir;
|
2009-12-08 04:24:42 +01:00
|
|
|
int lineno, colno;
|
2009-12-08 04:24:42 +01:00
|
|
|
struct srcfile_state *prev;
|
2008-01-04 00:43:31 +01:00
|
|
|
};
|
|
|
|
|
2012-01-12 19:31:00 +01:00
|
|
|
extern FILE *depfile; /* = NULL */
|
2009-12-08 04:24:42 +01:00
|
|
|
extern struct srcfile_state *current_srcfile; /* = NULL */
|
|
|
|
|
2012-03-15 04:04:13 +01:00
|
|
|
/**
|
|
|
|
* Open a source file.
|
|
|
|
*
|
|
|
|
* If the source file is a relative pathname, then it is searched for in the
|
|
|
|
* current directory (the directory of the last source file read) and after
|
|
|
|
* that in the search path.
|
|
|
|
*
|
|
|
|
* We work through the search path in order from the first path specified to
|
|
|
|
* the last.
|
|
|
|
*
|
|
|
|
* If the file is not found, then this function does not return, but calls
|
|
|
|
* die().
|
|
|
|
*
|
|
|
|
* @param fname Filename to search
|
|
|
|
* @param fullnamep If non-NULL, it is set to the allocated filename of the
|
|
|
|
* file that was opened. The caller is then responsible
|
|
|
|
* for freeing the pointer.
|
|
|
|
* @return pointer to opened FILE
|
|
|
|
*/
|
2009-12-08 04:24:42 +01:00
|
|
|
FILE *srcfile_relative_open(const char *fname, char **fullnamep);
|
2012-03-15 04:04:13 +01:00
|
|
|
|
2009-12-08 04:24:42 +01:00
|
|
|
void srcfile_push(const char *fname);
|
2013-10-28 11:06:53 +01:00
|
|
|
bool srcfile_pop(void);
|
2009-12-08 04:24:42 +01:00
|
|
|
|
2012-03-15 04:04:13 +01:00
|
|
|
/**
|
|
|
|
* Add a new directory to the search path for input files
|
|
|
|
*
|
|
|
|
* The new path is added at the end of the list.
|
|
|
|
*
|
|
|
|
* @param dirname Directory to add
|
|
|
|
*/
|
|
|
|
void srcfile_add_search_path(const char *dirname);
|
|
|
|
|
2009-12-08 04:24:42 +01:00
|
|
|
struct srcpos {
|
2007-03-23 21:18:41 +01:00
|
|
|
int first_line;
|
|
|
|
int first_column;
|
|
|
|
int last_line;
|
|
|
|
int last_column;
|
2009-12-08 04:24:42 +01:00
|
|
|
struct srcfile_state *file;
|
annotations: add positions
Extend the parser to record positions, in build_node,
build_node_delete, and build_property.
srcpos structures are added to the property and node types, and to the
parameter lists of the above functions that construct these types.
Nodes and properties that are created by the compiler rather than from
parsing source code have NULL as the srcpos value.
merge_nodes, defined in livetree.c, uses srcpos_extend to combine
multiple positions, resulting in a list of positions. srcpos_extend
is defined in srcpos.c. New elements are added at the end. This
requires the srcpos type, define in srcpos.h, to be a list structure
with a next field. This next field is initialized to NULL in
srcpos.h, in the macro YYLLOC_DEFAULT invoked implicitly by the
generated parser code.
Another change to srcpos.c is to make srcpos_copy always do a full
copy, including a copy of the file substructure. This is required
because when dtc is used on the output of cpp, the successive detected
file names overwrite the file name in the file structure. The next
field does not need to be deep copied, because it is always NULL when
srcpos_copy is called; an assert checks for this. File names are only
updated in uncopied position structures.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:29:59 +01:00
|
|
|
struct srcpos *next;
|
2009-12-08 04:24:42 +01:00
|
|
|
};
|
2007-03-23 21:18:41 +01:00
|
|
|
|
2009-12-08 04:24:42 +01:00
|
|
|
#define YYLTYPE struct srcpos
|
|
|
|
|
|
|
|
#define YYLLOC_DEFAULT(Current, Rhs, N) \
|
|
|
|
do { \
|
|
|
|
if (N) { \
|
|
|
|
(Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
|
|
|
|
(Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
|
|
|
|
(Current).last_line = YYRHSLOC(Rhs, N).last_line; \
|
|
|
|
(Current).last_column = YYRHSLOC (Rhs, N).last_column; \
|
|
|
|
(Current).file = YYRHSLOC(Rhs, N).file; \
|
|
|
|
} else { \
|
|
|
|
(Current).first_line = (Current).last_line = \
|
|
|
|
YYRHSLOC(Rhs, 0).last_line; \
|
|
|
|
(Current).first_column = (Current).last_column = \
|
|
|
|
YYRHSLOC(Rhs, 0).last_column; \
|
|
|
|
(Current).file = YYRHSLOC (Rhs, 0).file; \
|
|
|
|
} \
|
annotations: add positions
Extend the parser to record positions, in build_node,
build_node_delete, and build_property.
srcpos structures are added to the property and node types, and to the
parameter lists of the above functions that construct these types.
Nodes and properties that are created by the compiler rather than from
parsing source code have NULL as the srcpos value.
merge_nodes, defined in livetree.c, uses srcpos_extend to combine
multiple positions, resulting in a list of positions. srcpos_extend
is defined in srcpos.c. New elements are added at the end. This
requires the srcpos type, define in srcpos.h, to be a list structure
with a next field. This next field is initialized to NULL in
srcpos.h, in the macro YYLLOC_DEFAULT invoked implicitly by the
generated parser code.
Another change to srcpos.c is to make srcpos_copy always do a full
copy, including a copy of the file substructure. This is required
because when dtc is used on the output of cpp, the successive detected
file names overwrite the file name in the file structure. The next
field does not need to be deep copied, because it is always NULL when
srcpos_copy is called; an assert checks for this. File names are only
updated in uncopied position structures.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:29:59 +01:00
|
|
|
(Current).next = NULL; \
|
2009-12-08 04:24:42 +01:00
|
|
|
} while (0)
|
2007-03-23 21:18:41 +01:00
|
|
|
|
|
|
|
|
2009-12-08 04:24:42 +01:00
|
|
|
extern void srcpos_update(struct srcpos *pos, const char *text, int len);
|
|
|
|
extern struct srcpos *srcpos_copy(struct srcpos *pos);
|
annotations: add positions
Extend the parser to record positions, in build_node,
build_node_delete, and build_property.
srcpos structures are added to the property and node types, and to the
parameter lists of the above functions that construct these types.
Nodes and properties that are created by the compiler rather than from
parsing source code have NULL as the srcpos value.
merge_nodes, defined in livetree.c, uses srcpos_extend to combine
multiple positions, resulting in a list of positions. srcpos_extend
is defined in srcpos.c. New elements are added at the end. This
requires the srcpos type, define in srcpos.h, to be a list structure
with a next field. This next field is initialized to NULL in
srcpos.h, in the macro YYLLOC_DEFAULT invoked implicitly by the
generated parser code.
Another change to srcpos.c is to make srcpos_copy always do a full
copy, including a copy of the file substructure. This is required
because when dtc is used on the output of cpp, the successive detected
file names overwrite the file name in the file structure. The next
field does not need to be deep copied, because it is always NULL when
srcpos_copy is called; an assert checks for this. File names are only
updated in uncopied position structures.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:29:59 +01:00
|
|
|
extern struct srcpos *srcpos_extend(struct srcpos *new_srcpos,
|
|
|
|
struct srcpos *old_srcpos);
|
2009-12-08 04:24:42 +01:00
|
|
|
extern char *srcpos_string(struct srcpos *pos);
|
annotations: add the annotation functionality
Provide the new command-line option:
--annotate (abbreviated -T)
--annotate provides one or more filenames and line numbers indicating
the origin of a given line. The filename is expressed relative the the
filename provided on the command line. Nothing is printed for overlays,
etc.
-T can be repeated giving more verbose annotations. These consist of
one or more tuples of: filename, starting line, starting column, ending
line ending column. The full path is given for the file name.
Overlays, etc are annotated with <no-file>:<no-line>.
The verbose annotations may be too verbose for normal use.
There are numerous changes in srcpos.c to provide the relative filenames
(variables initial_path, initial_pathlen and initial_cpp, new functions
set_initial_path and shorten_to_initial_path, and changes in
srcfile_push and srcpos_set_line). The change in srcpos_set_line takes
care of the case where cpp is used as a preprocessor. In that case the
initial file name is not the one provided on the command line but the
one found at the beginnning of the cpp output.
shorten_to_initial_path only returns a string if it has some shortening
to do. Otherwise it returns NULL and relies on the caller to use the
initial string. This simplifies memory management, by making clear to
the caller whether a new string is allocated.
The new functions srcpos_string_comment, srcpos_string_first, and
srcpos_string_last print the annotations. srcpos_string_comment is
recursive to print a list of source file positions.
Various changes are sprinkled throughout treesource.c to print the
annotations.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-16 17:30:00 +01:00
|
|
|
extern char *srcpos_string_first(struct srcpos *pos, int level);
|
|
|
|
extern char *srcpos_string_last(struct srcpos *pos, int level);
|
|
|
|
|
2008-09-12 20:39:49 +02:00
|
|
|
|
2017-03-06 02:06:15 +01:00
|
|
|
extern void PRINTF(3, 0) srcpos_verror(struct srcpos *pos, const char *prefix,
|
|
|
|
const char *fmt, va_list va);
|
|
|
|
extern void PRINTF(3, 4) srcpos_error(struct srcpos *pos, const char *prefix,
|
|
|
|
const char *fmt, ...);
|
2008-09-12 20:39:49 +02:00
|
|
|
|
2012-09-28 01:11:05 +02:00
|
|
|
extern void srcpos_set_line(char *f, int l);
|
|
|
|
|
2017-10-18 07:59:43 +02:00
|
|
|
#endif /* SRCPOS_H */
|