~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/dtc/dtc-lexer.l

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/dtc/dtc-lexer.l (Version linux-6.12-rc7) and /scripts/dtc/dtc-lexer.l (Version linux-4.19.323)


  1 /* SPDX-License-Identifier: GPL-2.0-or-later * << 
  2 /*                                                  1 /*
  3  * (C) Copyright David Gibson <dwg@au1.ibm.com>      2  * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation.  2005.
                                                   >>   3  *
                                                   >>   4  *
                                                   >>   5  * This program is free software; you can redistribute it and/or
                                                   >>   6  * modify it under the terms of the GNU General Public License as
                                                   >>   7  * published by the Free Software Foundation; either version 2 of the
                                                   >>   8  * License, or (at your option) any later version.
                                                   >>   9  *
                                                   >>  10  *  This program is distributed in the hope that it will be useful,
                                                   >>  11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
                                                   >>  12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                                                   >>  13  *  General Public License for more details.
                                                   >>  14  *
                                                   >>  15  *  You should have received a copy of the GNU General Public License
                                                   >>  16  *  along with this program; if not, write to the Free Software
                                                   >>  17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
                                                   >>  18  *                                                                   USA
  4  */                                                19  */
  5                                                    20 
  6 %option noyywrap nounput noinput never-interac     21 %option noyywrap nounput noinput never-interactive
  7                                                    22 
  8 %x BYTESTRING                                      23 %x BYTESTRING
  9 %x PROPNODENAME                                    24 %x PROPNODENAME
 10 %s V1                                              25 %s V1
 11                                                    26 
 12 PROPNODECHAR    [a-zA-Z0-9,._+*#?@-]               27 PROPNODECHAR    [a-zA-Z0-9,._+*#?@-]
 13 PATHCHAR        ({PROPNODECHAR}|[/])               28 PATHCHAR        ({PROPNODECHAR}|[/])
 14 LABEL           [a-zA-Z_][a-zA-Z0-9_]*             29 LABEL           [a-zA-Z_][a-zA-Z0-9_]*
 15 STRING          \"([^\\"]|\\.)*\"                  30 STRING          \"([^\\"]|\\.)*\"
 16 CHAR_LITERAL    '([^']|\\')*'                      31 CHAR_LITERAL    '([^']|\\')*'
 17 WS              [[:space:]]                        32 WS              [[:space:]]
 18 COMMENT         "/*"([^*]|\*+[^*/])*\*+"/"         33 COMMENT         "/*"([^*]|\*+[^*/])*\*+"/"
 19 LINECOMMENT     "//".*\n                           34 LINECOMMENT     "//".*\n
 20                                                    35 
 21 %{                                                 36 %{
 22 #include "dtc.h"                                   37 #include "dtc.h"
 23 #include "srcpos.h"                                38 #include "srcpos.h"
 24 #include "dtc-parser.tab.h"                        39 #include "dtc-parser.tab.h"
 25                                                    40 
 26 extern bool treesource_error;                      41 extern bool treesource_error;
 27                                                    42 
 28 /* CAUTION: this will stop working if we ever      43 /* CAUTION: this will stop working if we ever use yyless() or yyunput() */
 29 #define YY_USER_ACTION \                           44 #define YY_USER_ACTION \
 30         { \                                        45         { \
 31                 srcpos_update(&yylloc, yytext,     46                 srcpos_update(&yylloc, yytext, yyleng); \
 32         }                                          47         }
 33                                                    48 
 34 /*#define LEXDEBUG      1*/                        49 /*#define LEXDEBUG      1*/
 35                                                    50 
 36 #ifdef LEXDEBUG                                    51 #ifdef LEXDEBUG
 37 #define DPRINT(fmt, ...)        fprintf(stderr     52 #define DPRINT(fmt, ...)        fprintf(stderr, fmt, ##__VA_ARGS__)
 38 #else                                              53 #else
 39 #define DPRINT(fmt, ...)        do { } while (     54 #define DPRINT(fmt, ...)        do { } while (0)
 40 #endif                                             55 #endif
 41                                                    56 
 42 static int dts_version = 1;                        57 static int dts_version = 1;
 43                                                    58 
 44 #define BEGIN_DEFAULT()         DPRINT("<V1>\n     59 #define BEGIN_DEFAULT()         DPRINT("<V1>\n"); \
 45                                 BEGIN(V1); \       60                                 BEGIN(V1); \
 46                                                    61 
 47 static void push_input_file(const char *filena     62 static void push_input_file(const char *filename);
 48 static bool pop_input_file(void);                  63 static bool pop_input_file(void);
 49 static void PRINTF(1, 2) lexical_error(const c     64 static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
 50                                                    65 
 51 %}                                                 66 %}
 52                                                    67 
 53 %%                                                 68 %%
 54 <*>"/include/"{WS}*{STRING} {                      69 <*>"/include/"{WS}*{STRING} {
 55                         char *name = strchr(yy     70                         char *name = strchr(yytext, '\"') + 1;
 56                         yytext[yyleng-1] = '\0     71                         yytext[yyleng-1] = '\0';
 57                         push_input_file(name);     72                         push_input_file(name);
 58                 }                                  73                 }
 59                                                    74 
 60 <*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t] !!  75 <*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? {
 61                         char *line, *fnstart,      76                         char *line, *fnstart, *fnend;
 62                         struct data fn;            77                         struct data fn;
 63                         /* skip text before li     78                         /* skip text before line # */
 64                         line = yytext;             79                         line = yytext;
 65                         while (!isdigit((unsig     80                         while (!isdigit((unsigned char)*line))
 66                                 line++;            81                                 line++;
 67                                                    82 
 68                         /* regexp ensures that     83                         /* regexp ensures that first and list "
 69                          * in the whole yytext     84                          * in the whole yytext are those at
 70                          * beginning and end o     85                          * beginning and end of the filename string */
 71                         fnstart = memchr(yytex     86                         fnstart = memchr(yytext, '"', yyleng);
 72                         for (fnend = yytext +      87                         for (fnend = yytext + yyleng - 1;
 73                              *fnend != '"'; fn     88                              *fnend != '"'; fnend--)
 74                                 ;                  89                                 ;
 75                         assert(fnstart && fnen     90                         assert(fnstart && fnend && (fnend > fnstart));
 76                                                    91 
 77                         fn = data_copy_escape_     92                         fn = data_copy_escape_string(fnstart + 1,
 78                                                    93                                                      fnend - fnstart - 1);
 79                                                    94 
 80                         /* Don't allow nuls in     95                         /* Don't allow nuls in filenames */
 81                         if (memchr(fn.val, '\0     96                         if (memchr(fn.val, '\0', fn.len - 1))
 82                                 lexical_error(     97                                 lexical_error("nul in line number directive");
 83                                                    98 
 84                         /* -1 since #line is t     99                         /* -1 since #line is the number of the next line */
 85                         srcpos_set_line(xstrdu    100                         srcpos_set_line(xstrdup(fn.val), atoi(line) - 1);
 86                         data_free(fn);            101                         data_free(fn);
 87                 }                                 102                 }
 88                                                   103 
 89 <*><<EOF>>              {                         104 <*><<EOF>>              {
 90                         if (!pop_input_file())    105                         if (!pop_input_file()) {
 91                                 yyterminate();    106                                 yyterminate();
 92                         }                         107                         }
 93                 }                                 108                 }
 94                                                   109 
 95 <*>{STRING}     {                                 110 <*>{STRING}     {
 96                         DPRINT("String: %s\n",    111                         DPRINT("String: %s\n", yytext);
 97                         yylval.data = data_cop    112                         yylval.data = data_copy_escape_string(yytext+1,
 98                                         yyleng    113                                         yyleng-2);
 99                         return DT_STRING;         114                         return DT_STRING;
100                 }                                 115                 }
101                                                   116 
102 <*>"/dts-v1/"   {                                 117 <*>"/dts-v1/"   {
103                         DPRINT("Keyword: /dts-    118                         DPRINT("Keyword: /dts-v1/\n");
104                         dts_version = 1;          119                         dts_version = 1;
105                         BEGIN_DEFAULT();          120                         BEGIN_DEFAULT();
106                         return DT_V1;             121                         return DT_V1;
107                 }                                 122                 }
108                                                   123 
109 <*>"/plugin/"   {                                 124 <*>"/plugin/"   {
110                         DPRINT("Keyword: /plug    125                         DPRINT("Keyword: /plugin/\n");
111                         return DT_PLUGIN;         126                         return DT_PLUGIN;
112                 }                                 127                 }
113                                                   128 
114 <*>"/memreserve/"       {                         129 <*>"/memreserve/"       {
115                         DPRINT("Keyword: /memr    130                         DPRINT("Keyword: /memreserve/\n");
116                         BEGIN_DEFAULT();          131                         BEGIN_DEFAULT();
117                         return DT_MEMRESERVE;     132                         return DT_MEMRESERVE;
118                 }                                 133                 }
119                                                   134 
120 <*>"/bits/"     {                                 135 <*>"/bits/"     {
121                         DPRINT("Keyword: /bits    136                         DPRINT("Keyword: /bits/\n");
122                         BEGIN_DEFAULT();          137                         BEGIN_DEFAULT();
123                         return DT_BITS;           138                         return DT_BITS;
124                 }                                 139                 }
125                                                   140 
126 <*>"/delete-property/"  {                         141 <*>"/delete-property/"  {
127                         DPRINT("Keyword: /dele    142                         DPRINT("Keyword: /delete-property/\n");
128                         DPRINT("<PROPNODENAME>    143                         DPRINT("<PROPNODENAME>\n");
129                         BEGIN(PROPNODENAME);      144                         BEGIN(PROPNODENAME);
130                         return DT_DEL_PROP;       145                         return DT_DEL_PROP;
131                 }                                 146                 }
132                                                   147 
133 <*>"/delete-node/"      {                         148 <*>"/delete-node/"      {
134                         DPRINT("Keyword: /dele    149                         DPRINT("Keyword: /delete-node/\n");
135                         DPRINT("<PROPNODENAME>    150                         DPRINT("<PROPNODENAME>\n");
136                         BEGIN(PROPNODENAME);      151                         BEGIN(PROPNODENAME);
137                         return DT_DEL_NODE;       152                         return DT_DEL_NODE;
138                 }                                 153                 }
139                                                   154 
140 <*>"/omit-if-no-ref/"   {                         155 <*>"/omit-if-no-ref/"   {
141                         DPRINT("Keyword: /omit    156                         DPRINT("Keyword: /omit-if-no-ref/\n");
142                         DPRINT("<PROPNODENAME>    157                         DPRINT("<PROPNODENAME>\n");
143                         BEGIN(PROPNODENAME);      158                         BEGIN(PROPNODENAME);
144                         return DT_OMIT_NO_REF;    159                         return DT_OMIT_NO_REF;
145                 }                                 160                 }
146                                                   161 
147 <*>{LABEL}:     {                                 162 <*>{LABEL}:     {
148                         DPRINT("Label: %s\n",     163                         DPRINT("Label: %s\n", yytext);
149                         yylval.labelref = xstr    164                         yylval.labelref = xstrdup(yytext);
150                         yylval.labelref[yyleng    165                         yylval.labelref[yyleng-1] = '\0';
151                         return DT_LABEL;          166                         return DT_LABEL;
152                 }                                 167                 }
153                                                   168 
154 <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)?    169 <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
155                         char *e;                  170                         char *e;
156                         DPRINT("Integer Litera    171                         DPRINT("Integer Literal: '%s'\n", yytext);
157                                                   172 
158                         errno = 0;                173                         errno = 0;
159                         yylval.integer = strto    174                         yylval.integer = strtoull(yytext, &e, 0);
160                                                   175 
161                         if (*e && e[strspn(e,     176                         if (*e && e[strspn(e, "UL")]) {
162                                 lexical_error(    177                                 lexical_error("Bad integer literal '%s'",
163                                                   178                                               yytext);
164                         }                         179                         }
165                                                   180 
166                         if (errno == ERANGE)      181                         if (errno == ERANGE)
167                                 lexical_error(    182                                 lexical_error("Integer literal '%s' out of range",
168                                                   183                                               yytext);
169                         else                      184                         else
170                                 /* ERANGE is t    185                                 /* ERANGE is the only strtoull error triggerable
171                                  *  by strings    186                                  *  by strings matching the pattern */
172                                 assert(errno =    187                                 assert(errno == 0);
173                         return DT_LITERAL;        188                         return DT_LITERAL;
174                 }                                 189                 }
175                                                   190 
176 <*>{CHAR_LITERAL}       {                         191 <*>{CHAR_LITERAL}       {
177                         struct data d;            192                         struct data d;
178                         DPRINT("Character lite    193                         DPRINT("Character literal: %s\n", yytext);
179                                                   194 
180                         d = data_copy_escape_s    195                         d = data_copy_escape_string(yytext+1, yyleng-2);
181                         if (d.len == 1) {         196                         if (d.len == 1) {
182                                 lexical_error(    197                                 lexical_error("Empty character literal");
183                                 yylval.integer    198                                 yylval.integer = 0;
184                         } else {                  199                         } else {
185                                 yylval.integer    200                                 yylval.integer = (unsigned char)d.val[0];
186                                                   201 
187                                 if (d.len > 2)    202                                 if (d.len > 2)
188                                         lexica    203                                         lexical_error("Character literal has %d"
189                                                   204                                                       " characters instead of 1",
190                                                   205                                                       d.len - 1);
191                         }                         206                         }
192                                                   207 
193                         data_free(d);             208                         data_free(d);
194                         return DT_CHAR_LITERAL    209                         return DT_CHAR_LITERAL;
195                 }                                 210                 }
196                                                   211 
197 <*>\&{LABEL}    {       /* label reference */     212 <*>\&{LABEL}    {       /* label reference */
198                         DPRINT("Ref: %s\n", yy    213                         DPRINT("Ref: %s\n", yytext+1);
199                         yylval.labelref = xstr    214                         yylval.labelref = xstrdup(yytext+1);
200                         return DT_LABEL_REF;   !! 215                         return DT_REF;
201                 }                                 216                 }
202                                                   217 
203 <*>"&{"{PATHCHAR}*\}    {       /* new-style p !! 218 <*>"&{/"{PATHCHAR}*\}   {       /* new-style path reference */
204                         yytext[yyleng-1] = '\0    219                         yytext[yyleng-1] = '\0';
205                         DPRINT("Ref: %s\n", yy    220                         DPRINT("Ref: %s\n", yytext+2);
206                         yylval.labelref = xstr    221                         yylval.labelref = xstrdup(yytext+2);
207                         return DT_PATH_REF;    !! 222                         return DT_REF;
208                 }                                 223                 }
209                                                   224 
210 <BYTESTRING>[0-9a-fA-F]{2} {                      225 <BYTESTRING>[0-9a-fA-F]{2} {
211                         yylval.byte = strtol(y    226                         yylval.byte = strtol(yytext, NULL, 16);
212                         DPRINT("Byte: %02x\n",    227                         DPRINT("Byte: %02x\n", (int)yylval.byte);
213                         return DT_BYTE;           228                         return DT_BYTE;
214                 }                                 229                 }
215                                                   230 
216 <BYTESTRING>"]" {                                 231 <BYTESTRING>"]" {
217                         DPRINT("/BYTESTRING\n"    232                         DPRINT("/BYTESTRING\n");
218                         BEGIN_DEFAULT();          233                         BEGIN_DEFAULT();
219                         return ']';               234                         return ']';
220                 }                                 235                 }
221                                                   236 
222 <PROPNODENAME>\\?{PROPNODECHAR}+ {                237 <PROPNODENAME>\\?{PROPNODECHAR}+ {
223                         DPRINT("PropNodeName:     238                         DPRINT("PropNodeName: %s\n", yytext);
224                         yylval.propnodename =     239                         yylval.propnodename = xstrdup((yytext[0] == '\\') ?
225                                                   240                                                         yytext + 1 : yytext);
226                         BEGIN_DEFAULT();          241                         BEGIN_DEFAULT();
227                         return DT_PROPNODENAME    242                         return DT_PROPNODENAME;
228                 }                                 243                 }
229                                                   244 
230 "/incbin/"      {                                 245 "/incbin/"      {
231                         DPRINT("Binary Include    246                         DPRINT("Binary Include\n");
232                         return DT_INCBIN;         247                         return DT_INCBIN;
233                 }                                 248                 }
234                                                   249 
235 <*>{WS}+        /* eat whitespace */              250 <*>{WS}+        /* eat whitespace */
236 <*>{COMMENT}+   /* eat C-style comments */        251 <*>{COMMENT}+   /* eat C-style comments */
237 <*>{LINECOMMENT}+ /* eat C++-style comments */    252 <*>{LINECOMMENT}+ /* eat C++-style comments */
238                                                   253 
239 <*>"<<"         { return DT_LSHIFT; };            254 <*>"<<"         { return DT_LSHIFT; };
240 <*>">>"         { return DT_RSHIFT; };            255 <*>">>"         { return DT_RSHIFT; };
241 <*>"<="         { return DT_LE; };                256 <*>"<="         { return DT_LE; };
242 <*>">="         { return DT_GE; };                257 <*>">="         { return DT_GE; };
243 <*>"=="         { return DT_EQ; };                258 <*>"=="         { return DT_EQ; };
244 <*>"!="         { return DT_NE; };                259 <*>"!="         { return DT_NE; };
245 <*>"&&"         { return DT_AND; };               260 <*>"&&"         { return DT_AND; };
246 <*>"||"         { return DT_OR; };                261 <*>"||"         { return DT_OR; };
247                                                   262 
248 <*>.            {                                 263 <*>.            {
249                         DPRINT("Char: %c (\\x%    264                         DPRINT("Char: %c (\\x%02x)\n", yytext[0],
250                                 (unsigned)yyte    265                                 (unsigned)yytext[0]);
251                         if (yytext[0] == '[')     266                         if (yytext[0] == '[') {
252                                 DPRINT("<BYTES    267                                 DPRINT("<BYTESTRING>\n");
253                                 BEGIN(BYTESTRI    268                                 BEGIN(BYTESTRING);
254                         }                         269                         }
255                         if ((yytext[0] == '{')    270                         if ((yytext[0] == '{')
256                             || (yytext[0] == '    271                             || (yytext[0] == ';')) {
257                                 DPRINT("<PROPN    272                                 DPRINT("<PROPNODENAME>\n");
258                                 BEGIN(PROPNODE    273                                 BEGIN(PROPNODENAME);
259                         }                         274                         }
260                         return yytext[0];         275                         return yytext[0];
261                 }                                 276                 }
262                                                   277 
263 %%                                                278 %%
264                                                   279 
265 static void push_input_file(const char *filena    280 static void push_input_file(const char *filename)
266 {                                                 281 {
267         assert(filename);                         282         assert(filename);
268                                                   283 
269         srcfile_push(filename);                   284         srcfile_push(filename);
270                                                   285 
271         yyin = current_srcfile->f;                286         yyin = current_srcfile->f;
272                                                   287 
273         yypush_buffer_state(yy_create_buffer(y    288         yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
274 }                                                 289 }
275                                                   290 
276                                                   291 
277 static bool pop_input_file(void)                  292 static bool pop_input_file(void)
278 {                                                 293 {
279         if (srcfile_pop() == 0)                   294         if (srcfile_pop() == 0)
280                 return false;                     295                 return false;
281                                                   296 
282         yypop_buffer_state();                     297         yypop_buffer_state();
283         yyin = current_srcfile->f;                298         yyin = current_srcfile->f;
284                                                   299 
285         return true;                              300         return true;
286 }                                                 301 }
287                                                   302 
288 static void lexical_error(const char *fmt, ...    303 static void lexical_error(const char *fmt, ...)
289 {                                                 304 {
290         va_list ap;                               305         va_list ap;
291                                                   306 
292         va_start(ap, fmt);                        307         va_start(ap, fmt);
293         srcpos_verror(&yylloc, "Lexical error"    308         srcpos_verror(&yylloc, "Lexical error", fmt, ap);
294         va_end(ap);                               309         va_end(ap);
295                                                   310 
296         treesource_error = true;                  311         treesource_error = true;
297 }                                                 312 }
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php