dtc: Cleanup YYLTYPE and YYLLOC_DEFAULT declarations

This patch makes some small cleanups to the declaration of YYLTYPE,
YYLLOC_DEFAULT and related things.

	- We used to use undocumented magic #defines for bison,
          YYLTYPE_IS_DECLARED and YYLTYPE_IS_TRIVIAL.  This may not be
          portable across bison versions.  Instead define YYLTYPE as a
          macro in terms of struct srcpos, as the info pages suggest.

	- Our kernel-derived coding style discourages typedefed
          structures.  So use 'struct srcpos' instead of 'srcpos'
          throughout'.

	- Indent the YYLLOC_DEFAULT macro according to our coding
          style (it was in GNU indent style, since it was taken from
          the example in the bison info).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
David Gibson 2009-12-08 14:24:42 +11:00 committed by Jon Loeliger
parent e1fee329e2
commit c6225f86fd
2 changed files with 37 additions and 55 deletions

View File

@ -119,7 +119,7 @@ int srcfile_pop(void)
* The empty source position. * The empty source position.
*/ */


srcpos srcpos_empty = { struct srcpos srcpos_empty = {
.first_line = 0, .first_line = 0,
.first_column = 0, .first_column = 0,
.last_line = 0, .last_line = 0,
@ -129,7 +129,7 @@ srcpos srcpos_empty = {


#define TAB_SIZE 8 #define TAB_SIZE 8


void srcpos_update(srcpos *pos, const char *text, int len) void srcpos_update(struct srcpos *pos, const char *text, int len)
{ {
int i; int i;


@ -153,13 +153,13 @@ void srcpos_update(srcpos *pos, const char *text, int len)
pos->last_column = current_srcfile->colno; pos->last_column = current_srcfile->colno;
} }


srcpos * struct srcpos *
srcpos_copy(srcpos *pos) srcpos_copy(struct srcpos *pos)
{ {
srcpos *pos_new; struct srcpos *pos_new;


pos_new = xmalloc(sizeof(srcpos)); pos_new = xmalloc(sizeof(struct srcpos));
memcpy(pos_new, pos, sizeof(srcpos)); memcpy(pos_new, pos, sizeof(struct srcpos));


return pos_new; return pos_new;
} }
@ -167,7 +167,7 @@ srcpos_copy(srcpos *pos)




void void
srcpos_dump(srcpos *pos) srcpos_dump(struct srcpos *pos)
{ {
printf("file : \"%s\"\n", printf("file : \"%s\"\n",
pos->file ? (char *) pos->file : "<no file>"); pos->file ? (char *) pos->file : "<no file>");
@ -180,7 +180,7 @@ srcpos_dump(srcpos *pos)




char * char *
srcpos_string(srcpos *pos) srcpos_string(struct srcpos *pos)
{ {
const char *fname = "<no-file>"; const char *fname = "<no-file>";
char *pos_str; char *pos_str;
@ -210,7 +210,7 @@ srcpos_string(srcpos *pos)




void void
srcpos_error(srcpos *pos, char const *fmt, ...) srcpos_error(struct srcpos *pos, char const *fmt, ...)
{ {
const char *srcstr; const char *srcstr;
va_list va; va_list va;
@ -227,7 +227,7 @@ srcpos_error(srcpos *pos, char const *fmt, ...)




void void
srcpos_warn(srcpos *pos, char const *fmt, ...) srcpos_warn(struct srcpos *pos, char const *fmt, ...)
{ {
const char *srcstr; const char *srcstr;
va_list va; va_list va;

View File

@ -20,11 +20,6 @@
#ifndef _SRCPOS_H_ #ifndef _SRCPOS_H_
#define _SRCPOS_H_ #define _SRCPOS_H_


/*
* Augment the standard YYLTYPE with a filenum index into an
* array of all opened filenames.
*/

#include <stdio.h> #include <stdio.h>


struct srcfile_state { struct srcfile_state {
@ -41,62 +36,49 @@ FILE *srcfile_relative_open(const char *fname, char **fullnamep);
void srcfile_push(const char *fname); void srcfile_push(const char *fname);
int srcfile_pop(void); int srcfile_pop(void);


#if ! defined(YYLTYPE) && ! defined(YYLTYPE_IS_DECLARED) struct srcpos {
typedef struct YYLTYPE {
int first_line; int first_line;
int first_column; int first_column;
int last_line; int last_line;
int last_column; int last_column;
struct srcfile_state *file; struct srcfile_state *file;
} YYLTYPE; };


#define YYLTYPE_IS_DECLARED 1 #define YYLTYPE struct srcpos
#define YYLTYPE_IS_TRIVIAL 1
#endif


/* Cater to old parser templates. */ #define YYLLOC_DEFAULT(Current, Rhs, N) \
#ifndef YYID do { \
#define YYID(n) (n) if (N) { \
#endif (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; \
} \
} while (0)


#define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (YYID (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; \
} \
while (YYID (0))


typedef YYLTYPE srcpos;


/* /*
* Fictional source position used for IR nodes that are * Fictional source position used for IR nodes that are
* created without otherwise knowing a true source position. * created without otherwise knowing a true source position.
* For example,constant definitions from the command line. * For example,constant definitions from the command line.
*/ */
extern srcpos srcpos_empty; extern struct srcpos srcpos_empty;


extern void srcpos_update(srcpos *pos, const char *text, int len); extern void srcpos_update(struct srcpos *pos, const char *text, int len);
extern srcpos *srcpos_copy(srcpos *pos); extern struct srcpos *srcpos_copy(struct srcpos *pos);
extern char *srcpos_string(srcpos *pos); extern char *srcpos_string(struct srcpos *pos);
extern void srcpos_dump(srcpos *pos); extern void srcpos_dump(struct srcpos *pos);


extern void srcpos_error(srcpos *pos, char const *, ...) extern void srcpos_error(struct srcpos *pos, char const *, ...)
__attribute__((format(printf, 2, 3))); __attribute__((format(printf, 2, 3)));
extern void srcpos_warn(srcpos *pos, char const *, ...) extern void srcpos_warn(struct srcpos *pos, char const *, ...)
__attribute__((format(printf, 2, 3))); __attribute__((format(printf, 2, 3)));


#endif /* _SRCPOS_H_ */ #endif /* _SRCPOS_H_ */