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 %locations << 6 << 7 %{ 20 %{ 8 #include <stdio.h> 21 #include <stdio.h> 9 #include <inttypes.h> 22 #include <inttypes.h> 10 23 11 #include "dtc.h" 24 #include "dtc.h" 12 #include "srcpos.h" 25 #include "srcpos.h" 13 26 14 extern int yylex(void); 27 extern int yylex(void); 15 extern void yyerror(char const *s); 28 extern void yyerror(char const *s); 16 #define ERROR(loc, ...) \ 29 #define ERROR(loc, ...) \ 17 do { \ 30 do { \ 18 srcpos_error((loc), "Error", _ 31 srcpos_error((loc), "Error", __VA_ARGS__); \ 19 treesource_error = true; \ 32 treesource_error = true; \ 20 } while (0) 33 } while (0) 21 34 22 #define YYERROR_CALL(msg) yyerror(msg) << 23 << 24 extern struct dt_info *parser_output; 35 extern struct dt_info *parser_output; 25 extern bool treesource_error; 36 extern bool treesource_error; 26 << 27 static bool is_ref_relative(const char *ref) << 28 { << 29 return ref[0] != '/' && strchr(&ref[1] << 30 } << 31 << 32 %} 37 %} 33 38 34 %union { 39 %union { 35 char *propnodename; 40 char *propnodename; 36 char *labelref; 41 char *labelref; 37 uint8_t byte; 42 uint8_t byte; 38 struct data data; 43 struct data data; 39 44 40 struct { 45 struct { 41 struct data data; 46 struct data data; 42 int bits; 47 int bits; 43 } array; 48 } array; 44 49 45 struct property *prop; 50 struct property *prop; 46 struct property *proplist; 51 struct property *proplist; 47 struct node *node; 52 struct node *node; 48 struct node *nodelist; 53 struct node *nodelist; 49 struct reserve_info *re; 54 struct reserve_info *re; 50 uint64_t integer; 55 uint64_t integer; 51 unsigned int flags; 56 unsigned int flags; 52 } 57 } 53 58 54 %token DT_V1 59 %token DT_V1 55 %token DT_PLUGIN 60 %token DT_PLUGIN 56 %token DT_MEMRESERVE 61 %token DT_MEMRESERVE 57 %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ D 62 %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR 58 %token DT_BITS 63 %token DT_BITS 59 %token DT_DEL_PROP 64 %token DT_DEL_PROP 60 %token DT_DEL_NODE 65 %token DT_DEL_NODE 61 %token DT_OMIT_NO_REF << 62 %token <propnodename> DT_PROPNODENAME 66 %token <propnodename> DT_PROPNODENAME 63 %token <integer> DT_LITERAL 67 %token <integer> DT_LITERAL 64 %token <integer> DT_CHAR_LITERAL 68 %token <integer> DT_CHAR_LITERAL 65 %token <byte> DT_BYTE 69 %token <byte> DT_BYTE 66 %token <data> DT_STRING 70 %token <data> DT_STRING 67 %token <labelref> DT_LABEL 71 %token <labelref> DT_LABEL 68 %token <labelref> DT_LABEL_REF !! 72 %token <labelref> DT_REF 69 %token <labelref> DT_PATH_REF << 70 %token DT_INCBIN 73 %token DT_INCBIN 71 74 72 %type <data> propdata 75 %type <data> propdata 73 %type <data> propdataprefix 76 %type <data> propdataprefix 74 %type <flags> header 77 %type <flags> header 75 %type <flags> headers 78 %type <flags> headers 76 %type <re> memreserve 79 %type <re> memreserve 77 %type <re> memreserves 80 %type <re> memreserves 78 %type <array> arrayprefix 81 %type <array> arrayprefix 79 %type <data> bytestring 82 %type <data> bytestring 80 %type <prop> propdef 83 %type <prop> propdef 81 %type <proplist> proplist 84 %type <proplist> proplist 82 %type <labelref> dt_ref << 83 85 84 %type <node> devicetree 86 %type <node> devicetree 85 %type <node> nodedef 87 %type <node> nodedef 86 %type <node> subnode 88 %type <node> subnode 87 %type <nodelist> subnodes 89 %type <nodelist> subnodes 88 90 89 %type <integer> integer_prim 91 %type <integer> integer_prim 90 %type <integer> integer_unary 92 %type <integer> integer_unary 91 %type <integer> integer_mul 93 %type <integer> integer_mul 92 %type <integer> integer_add 94 %type <integer> integer_add 93 %type <integer> integer_shift 95 %type <integer> integer_shift 94 %type <integer> integer_rela 96 %type <integer> integer_rela 95 %type <integer> integer_eq 97 %type <integer> integer_eq 96 %type <integer> integer_bitand 98 %type <integer> integer_bitand 97 %type <integer> integer_bitxor 99 %type <integer> integer_bitxor 98 %type <integer> integer_bitor 100 %type <integer> integer_bitor 99 %type <integer> integer_and 101 %type <integer> integer_and 100 %type <integer> integer_or 102 %type <integer> integer_or 101 %type <integer> integer_trinary 103 %type <integer> integer_trinary 102 %type <integer> integer_expr 104 %type <integer> integer_expr 103 105 104 %% 106 %% 105 107 106 sourcefile: 108 sourcefile: 107 headers memreserves devicetree 109 headers memreserves devicetree 108 { 110 { 109 parser_output = build_ 111 parser_output = build_dt_info($1, $2, $3, 110 112 guess_boot_cpuid($3)); 111 } 113 } 112 ; 114 ; 113 115 114 header: 116 header: 115 DT_V1 ';' 117 DT_V1 ';' 116 { 118 { 117 $$ = DTSF_V1; 119 $$ = DTSF_V1; 118 } 120 } 119 | DT_V1 ';' DT_PLUGIN ';' 121 | DT_V1 ';' DT_PLUGIN ';' 120 { 122 { 121 $$ = DTSF_V1 | DTSF_PL 123 $$ = DTSF_V1 | DTSF_PLUGIN; 122 } 124 } 123 ; 125 ; 124 126 125 headers: 127 headers: 126 header 128 header 127 | header headers 129 | header headers 128 { 130 { 129 if ($2 != $1) 131 if ($2 != $1) 130 ERROR(&@2, "He 132 ERROR(&@2, "Header flags don't match earlier ones"); 131 $$ = $1; 133 $$ = $1; 132 } 134 } 133 ; 135 ; 134 136 135 memreserves: 137 memreserves: 136 /* empty */ 138 /* empty */ 137 { 139 { 138 $$ = NULL; 140 $$ = NULL; 139 } 141 } 140 | memreserve memreserves 142 | memreserve memreserves 141 { 143 { 142 $$ = chain_reserve_ent 144 $$ = chain_reserve_entry($1, $2); 143 } 145 } 144 ; 146 ; 145 147 146 memreserve: 148 memreserve: 147 DT_MEMRESERVE integer_prim integer_p 149 DT_MEMRESERVE integer_prim integer_prim ';' 148 { 150 { 149 $$ = build_reserve_ent 151 $$ = build_reserve_entry($2, $3); 150 } 152 } 151 | DT_LABEL memreserve 153 | DT_LABEL memreserve 152 { 154 { 153 add_label(&$2->labels, 155 add_label(&$2->labels, $1); 154 $$ = $2; 156 $$ = $2; 155 } 157 } 156 ; 158 ; 157 159 158 dt_ref: DT_LABEL_REF | DT_PATH_REF; << 159 << 160 devicetree: 160 devicetree: 161 '/' nodedef 161 '/' nodedef 162 { 162 { 163 $$ = name_node($2, "") 163 $$ = name_node($2, ""); 164 } 164 } 165 | devicetree '/' nodedef 165 | devicetree '/' nodedef 166 { 166 { 167 $$ = merge_nodes($1, $ 167 $$ = merge_nodes($1, $3); 168 } 168 } 169 | dt_ref nodedef !! 169 170 { !! 170 | devicetree DT_LABEL DT_REF nodedef 171 /* << 172 * We rely on the rule << 173 * versioninfo plugi << 174 * so $-1 is what we w << 175 */ << 176 if (!($<flags>-1 & DTS << 177 ERROR(&@2, "La << 178 else if (is_ref_relati << 179 ERROR(&@2, "La << 180 $$ = add_orphan_node( << 181 name_n << 182 << 183 $2, $1 << 184 } << 185 | devicetree DT_LABEL dt_ref nodedef << 186 { 171 { 187 struct node *target = 172 struct node *target = get_node_by_ref($1, $3); 188 173 189 if (($<flags>-1 & DTSF << 190 ERROR(&@2, "La << 191 << 192 if (target) { 174 if (target) { 193 add_label(&tar 175 add_label(&target->labels, $2); 194 merge_nodes(ta 176 merge_nodes(target, $4); 195 } else 177 } else 196 ERROR(&@3, "La 178 ERROR(&@3, "Label or path %s not found", $3); 197 $$ = $1; 179 $$ = $1; 198 } 180 } 199 | devicetree DT_PATH_REF nodedef !! 181 | devicetree DT_REF nodedef 200 { << 201 /* << 202 * We rely on the rule << 203 * versioninfo plugi << 204 * so $-1 is what we w << 205 */ << 206 if ($<flags>-1 & DTSF_ << 207 if (is_ref_rel << 208 ERROR( << 209 add_orphan_nod << 210 } else { << 211 struct node *t << 212 << 213 if (target) << 214 merge_ << 215 else << 216 ERROR( << 217 } << 218 $$ = $1; << 219 } << 220 | devicetree DT_LABEL_REF nodedef << 221 { 182 { 222 struct node *target = 183 struct node *target = get_node_by_ref($1, $2); 223 184 224 if (target) { 185 if (target) { 225 merge_nodes(ta 186 merge_nodes(target, $3); 226 } else { 187 } else { 227 /* 188 /* 228 * We rely on 189 * We rely on the rule being always: 229 * versionin 190 * versioninfo plugindecl memreserves devicetree 230 * so $-1 is w 191 * so $-1 is what we want (plugindecl) 231 */ 192 */ 232 if ($<flags>-1 193 if ($<flags>-1 & DTSF_PLUGIN) 233 add_or 194 add_orphan_node($1, $3, $2); 234 else 195 else 235 ERROR( 196 ERROR(&@2, "Label or path %s not found", $2); 236 } 197 } 237 $$ = $1; 198 $$ = $1; 238 } 199 } 239 | devicetree DT_DEL_NODE dt_ref ';' !! 200 | devicetree DT_DEL_NODE DT_REF ';' 240 { 201 { 241 struct node *target = 202 struct node *target = get_node_by_ref($1, $3); 242 203 243 if (target) 204 if (target) 244 delete_node(ta 205 delete_node(target); 245 else 206 else 246 ERROR(&@3, "La 207 ERROR(&@3, "Label or path %s not found", $3); 247 208 248 209 249 $$ = $1; 210 $$ = $1; 250 } 211 } 251 | devicetree DT_OMIT_NO_REF dt_ref ';' !! 212 | /* empty */ 252 { 213 { 253 struct node *target = !! 214 /* build empty node */ 254 !! 215 $$ = name_node(build_node(NULL, NULL), ""); 255 if (target) << 256 omit_node_if_u << 257 else << 258 ERROR(&@3, "La << 259 << 260 << 261 $$ = $1; << 262 } 216 } 263 ; 217 ; 264 218 265 nodedef: 219 nodedef: 266 '{' proplist subnodes '}' ';' 220 '{' proplist subnodes '}' ';' 267 { 221 { 268 $$ = build_node($2, $3 !! 222 $$ = build_node($2, $3); 269 } 223 } 270 ; 224 ; 271 225 272 proplist: 226 proplist: 273 /* empty */ 227 /* empty */ 274 { 228 { 275 $$ = NULL; 229 $$ = NULL; 276 } 230 } 277 | proplist propdef 231 | proplist propdef 278 { 232 { 279 $$ = chain_property($2 233 $$ = chain_property($2, $1); 280 } 234 } 281 ; 235 ; 282 236 283 propdef: 237 propdef: 284 DT_PROPNODENAME '=' propdata ';' 238 DT_PROPNODENAME '=' propdata ';' 285 { 239 { 286 $$ = build_property($1 !! 240 $$ = build_property($1, $3); 287 free($1); << 288 } 241 } 289 | DT_PROPNODENAME ';' 242 | DT_PROPNODENAME ';' 290 { 243 { 291 $$ = build_property($1 !! 244 $$ = build_property($1, empty_data); 292 free($1); << 293 } 245 } 294 | DT_DEL_PROP DT_PROPNODENAME ';' 246 | DT_DEL_PROP DT_PROPNODENAME ';' 295 { 247 { 296 $$ = build_property_de 248 $$ = build_property_delete($2); 297 free($2); << 298 } 249 } 299 | DT_LABEL propdef 250 | DT_LABEL propdef 300 { 251 { 301 add_label(&$2->labels, 252 add_label(&$2->labels, $1); 302 $$ = $2; 253 $$ = $2; 303 } 254 } 304 ; 255 ; 305 256 306 propdata: 257 propdata: 307 propdataprefix DT_STRING 258 propdataprefix DT_STRING 308 { 259 { 309 $$ = data_merge($1, $2 260 $$ = data_merge($1, $2); 310 } 261 } 311 | propdataprefix arrayprefix '>' 262 | propdataprefix arrayprefix '>' 312 { 263 { 313 $$ = data_merge($1, $2 264 $$ = data_merge($1, $2.data); 314 } 265 } 315 | propdataprefix '[' bytestring ']' 266 | propdataprefix '[' bytestring ']' 316 { 267 { 317 $$ = data_merge($1, $3 268 $$ = data_merge($1, $3); 318 } 269 } 319 | propdataprefix dt_ref !! 270 | propdataprefix DT_REF 320 { 271 { 321 $1 = data_add_marker($ << 322 $$ = data_add_marker($ 272 $$ = data_add_marker($1, REF_PATH, $2); 323 } 273 } 324 | propdataprefix DT_INCBIN '(' DT_STRI 274 | propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')' 325 { 275 { 326 FILE *f = srcfile_rela 276 FILE *f = srcfile_relative_open($4.val, NULL); 327 struct data d; 277 struct data d; 328 278 329 if ($6 != 0) 279 if ($6 != 0) 330 if (fseek(f, $ 280 if (fseek(f, $6, SEEK_SET) != 0) 331 die("C 281 die("Couldn't seek to offset %llu in \"%s\": %s", 332 (u 282 (unsigned long long)$6, $4.val, 333 st 283 strerror(errno)); 334 284 335 d = data_copy_file(f, 285 d = data_copy_file(f, $8); 336 286 337 $$ = data_merge($1, d) 287 $$ = data_merge($1, d); 338 fclose(f); 288 fclose(f); 339 } 289 } 340 | propdataprefix DT_INCBIN '(' DT_STRI 290 | propdataprefix DT_INCBIN '(' DT_STRING ')' 341 { 291 { 342 FILE *f = srcfile_rela 292 FILE *f = srcfile_relative_open($4.val, NULL); 343 struct data d = empty_ 293 struct data d = empty_data; 344 294 345 d = data_copy_file(f, 295 d = data_copy_file(f, -1); 346 296 347 $$ = data_merge($1, d) 297 $$ = data_merge($1, d); 348 fclose(f); 298 fclose(f); 349 } 299 } 350 | propdata DT_LABEL 300 | propdata DT_LABEL 351 { 301 { 352 $$ = data_add_marker($ 302 $$ = data_add_marker($1, LABEL, $2); 353 } 303 } 354 ; 304 ; 355 305 356 propdataprefix: 306 propdataprefix: 357 /* empty */ 307 /* empty */ 358 { 308 { 359 $$ = empty_data; 309 $$ = empty_data; 360 } 310 } 361 | propdata ',' 311 | propdata ',' 362 { 312 { 363 $$ = $1; 313 $$ = $1; 364 } 314 } 365 | propdataprefix DT_LABEL 315 | propdataprefix DT_LABEL 366 { 316 { 367 $$ = data_add_marker($ 317 $$ = data_add_marker($1, LABEL, $2); 368 } 318 } 369 ; 319 ; 370 320 371 arrayprefix: 321 arrayprefix: 372 DT_BITS DT_LITERAL '<' 322 DT_BITS DT_LITERAL '<' 373 { 323 { 374 unsigned long long bit 324 unsigned long long bits; 375 enum markertype type = << 376 325 377 bits = $2; 326 bits = $2; 378 327 379 switch (bits) { !! 328 if ((bits != 8) && (bits != 16) && 380 case 8: type = TYPE_UI !! 329 (bits != 32) && (bits != 64)) { 381 case 16: type = TYPE_U << 382 case 32: type = TYPE_U << 383 case 64: type = TYPE_U << 384 default: << 385 ERROR(&@2, "Ar 330 ERROR(&@2, "Array elements must be" 386 " 8, 16, 331 " 8, 16, 32 or 64-bits"); 387 bits = 32; 332 bits = 32; 388 } 333 } 389 334 390 $$.data = data_add_mar !! 335 $$.data = empty_data; 391 $$.bits = bits; 336 $$.bits = bits; 392 } 337 } 393 | '<' 338 | '<' 394 { 339 { 395 $$.data = data_add_mar !! 340 $$.data = empty_data; 396 $$.bits = 32; 341 $$.bits = 32; 397 } 342 } 398 | arrayprefix integer_prim 343 | arrayprefix integer_prim 399 { 344 { 400 if ($1.bits < 64) { 345 if ($1.bits < 64) { 401 uint64_t mask 346 uint64_t mask = (1ULL << $1.bits) - 1; 402 /* 347 /* 403 * Bits above 348 * Bits above mask must either be all zero 404 * (positive w 349 * (positive within range of mask) or all one 405 * (negative a 350 * (negative and sign-extended). The second 406 * condition i 351 * condition is true if when we set all bits 407 * within the 352 * within the mask to one (i.e. | in the 408 * mask), all 353 * mask), all bits are one. 409 */ 354 */ 410 if (($2 > mask !! 355 if (($2 > mask) && (($2 | mask) != -1ULL)) 411 char * !! 356 ERROR(&@2, "Value out of range for" 412 fprint !! 357 " %d-bit array element", $1.bits); 413 << 414 << 415 << 416 free(l << 417 } << 418 } 358 } 419 359 420 $$.data = data_append_ 360 $$.data = data_append_integer($1.data, $2, $1.bits); 421 } 361 } 422 | arrayprefix dt_ref !! 362 | arrayprefix DT_REF 423 { 363 { 424 uint64_t val = ~0ULL > 364 uint64_t val = ~0ULL >> (64 - $1.bits); 425 365 426 if ($1.bits == 32) 366 if ($1.bits == 32) 427 $1.data = data 367 $1.data = data_add_marker($1.data, 428 368 REF_PHANDLE, 429 369 $2); 430 else 370 else 431 ERROR(&@2, "Re 371 ERROR(&@2, "References are only allowed in " 432 "a 372 "arrays with 32-bit elements."); 433 373 434 $$.data = data_append_ 374 $$.data = data_append_integer($1.data, val, $1.bits); 435 } 375 } 436 | arrayprefix DT_LABEL 376 | arrayprefix DT_LABEL 437 { 377 { 438 $$.data = data_add_mar 378 $$.data = data_add_marker($1.data, LABEL, $2); 439 } 379 } 440 ; 380 ; 441 381 442 integer_prim: 382 integer_prim: 443 DT_LITERAL 383 DT_LITERAL 444 | DT_CHAR_LITERAL 384 | DT_CHAR_LITERAL 445 | '(' integer_expr ')' 385 | '(' integer_expr ')' 446 { 386 { 447 $$ = $2; 387 $$ = $2; 448 } 388 } 449 ; 389 ; 450 390 451 integer_expr: 391 integer_expr: 452 integer_trinary 392 integer_trinary 453 ; 393 ; 454 394 455 integer_trinary: 395 integer_trinary: 456 integer_or 396 integer_or 457 | integer_or '?' integer_expr ':' inte 397 | integer_or '?' integer_expr ':' integer_trinary { $$ = $1 ? $3 : $5; } 458 ; 398 ; 459 399 460 integer_or: 400 integer_or: 461 integer_and 401 integer_and 462 | integer_or DT_OR integer_and { $$ = 402 | integer_or DT_OR integer_and { $$ = $1 || $3; } 463 ; 403 ; 464 404 465 integer_and: 405 integer_and: 466 integer_bitor 406 integer_bitor 467 | integer_and DT_AND integer_bitor { $ 407 | integer_and DT_AND integer_bitor { $$ = $1 && $3; } 468 ; 408 ; 469 409 470 integer_bitor: 410 integer_bitor: 471 integer_bitxor 411 integer_bitxor 472 | integer_bitor '|' integer_bitxor { $ 412 | integer_bitor '|' integer_bitxor { $$ = $1 | $3; } 473 ; 413 ; 474 414 475 integer_bitxor: 415 integer_bitxor: 476 integer_bitand 416 integer_bitand 477 | integer_bitxor '^' integer_bitand { 417 | integer_bitxor '^' integer_bitand { $$ = $1 ^ $3; } 478 ; 418 ; 479 419 480 integer_bitand: 420 integer_bitand: 481 integer_eq 421 integer_eq 482 | integer_bitand '&' integer_eq { $$ = 422 | integer_bitand '&' integer_eq { $$ = $1 & $3; } 483 ; 423 ; 484 424 485 integer_eq: 425 integer_eq: 486 integer_rela 426 integer_rela 487 | integer_eq DT_EQ integer_rela { $$ = 427 | integer_eq DT_EQ integer_rela { $$ = $1 == $3; } 488 | integer_eq DT_NE integer_rela { $$ = 428 | integer_eq DT_NE integer_rela { $$ = $1 != $3; } 489 ; 429 ; 490 430 491 integer_rela: 431 integer_rela: 492 integer_shift 432 integer_shift 493 | integer_rela '<' integer_shift { $$ 433 | integer_rela '<' integer_shift { $$ = $1 < $3; } 494 | integer_rela '>' integer_shift { $$ 434 | integer_rela '>' integer_shift { $$ = $1 > $3; } 495 | integer_rela DT_LE integer_shift { $ 435 | integer_rela DT_LE integer_shift { $$ = $1 <= $3; } 496 | integer_rela DT_GE integer_shift { $ 436 | integer_rela DT_GE integer_shift { $$ = $1 >= $3; } 497 ; 437 ; 498 438 499 integer_shift: 439 integer_shift: 500 integer_shift DT_LSHIFT integer_add !! 440 integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; } 501 | integer_shift DT_RSHIFT integer_add !! 441 | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; } 502 | integer_add 442 | integer_add 503 ; 443 ; 504 444 505 integer_add: 445 integer_add: 506 integer_add '+' integer_mul { $$ = $ 446 integer_add '+' integer_mul { $$ = $1 + $3; } 507 | integer_add '-' integer_mul { $$ = $ 447 | integer_add '-' integer_mul { $$ = $1 - $3; } 508 | integer_mul 448 | integer_mul 509 ; 449 ; 510 450 511 integer_mul: 451 integer_mul: 512 integer_mul '*' integer_unary { $$ = 452 integer_mul '*' integer_unary { $$ = $1 * $3; } 513 | integer_mul '/' integer_unary 453 | integer_mul '/' integer_unary 514 { 454 { 515 if ($3 != 0) { 455 if ($3 != 0) { 516 $$ = $1 / $3; 456 $$ = $1 / $3; 517 } else { 457 } else { 518 ERROR(&@$, "Di 458 ERROR(&@$, "Division by zero"); 519 $$ = 0; 459 $$ = 0; 520 } 460 } 521 } 461 } 522 | integer_mul '%' integer_unary 462 | integer_mul '%' integer_unary 523 { 463 { 524 if ($3 != 0) { 464 if ($3 != 0) { 525 $$ = $1 % $3; 465 $$ = $1 % $3; 526 } else { 466 } else { 527 ERROR(&@$, "Di 467 ERROR(&@$, "Division by zero"); 528 $$ = 0; 468 $$ = 0; 529 } 469 } 530 } 470 } 531 | integer_unary 471 | integer_unary 532 ; 472 ; 533 473 534 integer_unary: 474 integer_unary: 535 integer_prim 475 integer_prim 536 | '-' integer_unary { $$ = -$2; } 476 | '-' integer_unary { $$ = -$2; } 537 | '~' integer_unary { $$ = ~$2; } 477 | '~' integer_unary { $$ = ~$2; } 538 | '!' integer_unary { $$ = !$2; } 478 | '!' integer_unary { $$ = !$2; } 539 ; 479 ; 540 480 541 bytestring: 481 bytestring: 542 /* empty */ 482 /* empty */ 543 { 483 { 544 $$ = data_add_marker(e !! 484 $$ = empty_data; 545 } 485 } 546 | bytestring DT_BYTE 486 | bytestring DT_BYTE 547 { 487 { 548 $$ = data_append_byte( 488 $$ = data_append_byte($1, $2); 549 } 489 } 550 | bytestring DT_LABEL 490 | bytestring DT_LABEL 551 { 491 { 552 $$ = data_add_marker($ 492 $$ = data_add_marker($1, LABEL, $2); 553 } 493 } 554 ; 494 ; 555 495 556 subnodes: 496 subnodes: 557 /* empty */ 497 /* empty */ 558 { 498 { 559 $$ = NULL; 499 $$ = NULL; 560 } 500 } 561 | subnode subnodes 501 | subnode subnodes 562 { 502 { 563 $$ = chain_node($1, $2 503 $$ = chain_node($1, $2); 564 } 504 } 565 | subnode propdef 505 | subnode propdef 566 { 506 { 567 ERROR(&@2, "Properties 507 ERROR(&@2, "Properties must precede subnodes"); 568 YYERROR; 508 YYERROR; 569 } 509 } 570 ; 510 ; 571 511 572 subnode: 512 subnode: 573 DT_PROPNODENAME nodedef 513 DT_PROPNODENAME nodedef 574 { 514 { 575 $$ = name_node($2, $1) 515 $$ = name_node($2, $1); 576 free($1); << 577 } 516 } 578 | DT_DEL_NODE DT_PROPNODENAME ';' 517 | DT_DEL_NODE DT_PROPNODENAME ';' 579 { 518 { 580 $$ = name_node(build_n !! 519 $$ = name_node(build_node_delete(), $2); 581 free($2); << 582 } << 583 | DT_OMIT_NO_REF subnode << 584 { << 585 $$ = omit_node_if_unus << 586 } 520 } 587 | DT_LABEL subnode 521 | DT_LABEL subnode 588 { 522 { 589 add_label(&$2->labels, 523 add_label(&$2->labels, $1); 590 $$ = $2; 524 $$ = $2; 591 } 525 } 592 ; 526 ; 593 527 594 %% 528 %% 595 529 596 void yyerror(char const *s) 530 void yyerror(char const *s) 597 { 531 { 598 ERROR(&yylloc, "%s", s); 532 ERROR(&yylloc, "%s", s); 599 } 533 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.