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 | DT_REF nodedef 170 { 170 { 171 /* 171 /* 172 * We rely on the rule 172 * We rely on the rule being always: 173 * versioninfo plugi 173 * versioninfo plugindecl memreserves devicetree 174 * so $-1 is what we w 174 * so $-1 is what we want (plugindecl) 175 */ 175 */ 176 if (!($<flags>-1 & DTS 176 if (!($<flags>-1 & DTSF_PLUGIN)) 177 ERROR(&@2, "La 177 ERROR(&@2, "Label or path %s not found", $1); 178 else if (is_ref_relati !! 178 $$ = add_orphan_node(name_node(build_node(NULL, NULL), ""), $2, $1); 179 ERROR(&@2, "La << 180 $$ = add_orphan_node( << 181 name_n << 182 << 183 $2, $1 << 184 } 179 } 185 | devicetree DT_LABEL dt_ref nodedef !! 180 | devicetree DT_LABEL DT_REF nodedef 186 { 181 { 187 struct node *target = 182 struct node *target = get_node_by_ref($1, $3); 188 183 189 if (($<flags>-1 & DTSF << 190 ERROR(&@2, "La << 191 << 192 if (target) { 184 if (target) { 193 add_label(&tar 185 add_label(&target->labels, $2); 194 merge_nodes(ta 186 merge_nodes(target, $4); 195 } else 187 } else 196 ERROR(&@3, "La 188 ERROR(&@3, "Label or path %s not found", $3); 197 $$ = $1; 189 $$ = $1; 198 } 190 } 199 | devicetree DT_PATH_REF nodedef !! 191 | 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 { 192 { 222 struct node *target = 193 struct node *target = get_node_by_ref($1, $2); 223 194 224 if (target) { 195 if (target) { 225 merge_nodes(ta 196 merge_nodes(target, $3); 226 } else { 197 } else { 227 /* 198 /* 228 * We rely on 199 * We rely on the rule being always: 229 * versionin 200 * versioninfo plugindecl memreserves devicetree 230 * so $-1 is w 201 * so $-1 is what we want (plugindecl) 231 */ 202 */ 232 if ($<flags>-1 203 if ($<flags>-1 & DTSF_PLUGIN) 233 add_or 204 add_orphan_node($1, $3, $2); 234 else 205 else 235 ERROR( 206 ERROR(&@2, "Label or path %s not found", $2); 236 } 207 } 237 $$ = $1; 208 $$ = $1; 238 } 209 } 239 | devicetree DT_DEL_NODE dt_ref ';' !! 210 | devicetree DT_DEL_NODE DT_REF ';' 240 { 211 { 241 struct node *target = 212 struct node *target = get_node_by_ref($1, $3); 242 213 243 if (target) 214 if (target) 244 delete_node(ta 215 delete_node(target); 245 else 216 else 246 ERROR(&@3, "La 217 ERROR(&@3, "Label or path %s not found", $3); 247 218 248 219 249 $$ = $1; 220 $$ = $1; 250 } 221 } 251 | devicetree DT_OMIT_NO_REF dt_ref ';' << 252 { << 253 struct node *target = << 254 << 255 if (target) << 256 omit_node_if_u << 257 else << 258 ERROR(&@3, "La << 259 << 260 << 261 $$ = $1; << 262 } << 263 ; 222 ; 264 223 265 nodedef: 224 nodedef: 266 '{' proplist subnodes '}' ';' 225 '{' proplist subnodes '}' ';' 267 { 226 { 268 $$ = build_node($2, $3 !! 227 $$ = build_node($2, $3); 269 } 228 } 270 ; 229 ; 271 230 272 proplist: 231 proplist: 273 /* empty */ 232 /* empty */ 274 { 233 { 275 $$ = NULL; 234 $$ = NULL; 276 } 235 } 277 | proplist propdef 236 | proplist propdef 278 { 237 { 279 $$ = chain_property($2 238 $$ = chain_property($2, $1); 280 } 239 } 281 ; 240 ; 282 241 283 propdef: 242 propdef: 284 DT_PROPNODENAME '=' propdata ';' 243 DT_PROPNODENAME '=' propdata ';' 285 { 244 { 286 $$ = build_property($1 !! 245 $$ = build_property($1, $3); 287 free($1); << 288 } 246 } 289 | DT_PROPNODENAME ';' 247 | DT_PROPNODENAME ';' 290 { 248 { 291 $$ = build_property($1 !! 249 $$ = build_property($1, empty_data); 292 free($1); << 293 } 250 } 294 | DT_DEL_PROP DT_PROPNODENAME ';' 251 | DT_DEL_PROP DT_PROPNODENAME ';' 295 { 252 { 296 $$ = build_property_de 253 $$ = build_property_delete($2); 297 free($2); << 298 } 254 } 299 | DT_LABEL propdef 255 | DT_LABEL propdef 300 { 256 { 301 add_label(&$2->labels, 257 add_label(&$2->labels, $1); 302 $$ = $2; 258 $$ = $2; 303 } 259 } 304 ; 260 ; 305 261 306 propdata: 262 propdata: 307 propdataprefix DT_STRING 263 propdataprefix DT_STRING 308 { 264 { 309 $$ = data_merge($1, $2 265 $$ = data_merge($1, $2); 310 } 266 } 311 | propdataprefix arrayprefix '>' 267 | propdataprefix arrayprefix '>' 312 { 268 { 313 $$ = data_merge($1, $2 269 $$ = data_merge($1, $2.data); 314 } 270 } 315 | propdataprefix '[' bytestring ']' 271 | propdataprefix '[' bytestring ']' 316 { 272 { 317 $$ = data_merge($1, $3 273 $$ = data_merge($1, $3); 318 } 274 } 319 | propdataprefix dt_ref !! 275 | propdataprefix DT_REF 320 { 276 { 321 $1 = data_add_marker($ << 322 $$ = data_add_marker($ 277 $$ = data_add_marker($1, REF_PATH, $2); 323 } 278 } 324 | propdataprefix DT_INCBIN '(' DT_STRI 279 | propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')' 325 { 280 { 326 FILE *f = srcfile_rela 281 FILE *f = srcfile_relative_open($4.val, NULL); 327 struct data d; 282 struct data d; 328 283 329 if ($6 != 0) 284 if ($6 != 0) 330 if (fseek(f, $ 285 if (fseek(f, $6, SEEK_SET) != 0) 331 die("C 286 die("Couldn't seek to offset %llu in \"%s\": %s", 332 (u 287 (unsigned long long)$6, $4.val, 333 st 288 strerror(errno)); 334 289 335 d = data_copy_file(f, 290 d = data_copy_file(f, $8); 336 291 337 $$ = data_merge($1, d) 292 $$ = data_merge($1, d); 338 fclose(f); 293 fclose(f); 339 } 294 } 340 | propdataprefix DT_INCBIN '(' DT_STRI 295 | propdataprefix DT_INCBIN '(' DT_STRING ')' 341 { 296 { 342 FILE *f = srcfile_rela 297 FILE *f = srcfile_relative_open($4.val, NULL); 343 struct data d = empty_ 298 struct data d = empty_data; 344 299 345 d = data_copy_file(f, 300 d = data_copy_file(f, -1); 346 301 347 $$ = data_merge($1, d) 302 $$ = data_merge($1, d); 348 fclose(f); 303 fclose(f); 349 } 304 } 350 | propdata DT_LABEL 305 | propdata DT_LABEL 351 { 306 { 352 $$ = data_add_marker($ 307 $$ = data_add_marker($1, LABEL, $2); 353 } 308 } 354 ; 309 ; 355 310 356 propdataprefix: 311 propdataprefix: 357 /* empty */ 312 /* empty */ 358 { 313 { 359 $$ = empty_data; 314 $$ = empty_data; 360 } 315 } 361 | propdata ',' 316 | propdata ',' 362 { 317 { 363 $$ = $1; 318 $$ = $1; 364 } 319 } 365 | propdataprefix DT_LABEL 320 | propdataprefix DT_LABEL 366 { 321 { 367 $$ = data_add_marker($ 322 $$ = data_add_marker($1, LABEL, $2); 368 } 323 } 369 ; 324 ; 370 325 371 arrayprefix: 326 arrayprefix: 372 DT_BITS DT_LITERAL '<' 327 DT_BITS DT_LITERAL '<' 373 { 328 { 374 unsigned long long bit 329 unsigned long long bits; 375 enum markertype type = << 376 330 377 bits = $2; 331 bits = $2; 378 332 379 switch (bits) { !! 333 if ((bits != 8) && (bits != 16) && 380 case 8: type = TYPE_UI !! 334 (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 335 ERROR(&@2, "Array elements must be" 386 " 8, 16, 336 " 8, 16, 32 or 64-bits"); 387 bits = 32; 337 bits = 32; 388 } 338 } 389 339 390 $$.data = data_add_mar !! 340 $$.data = empty_data; 391 $$.bits = bits; 341 $$.bits = bits; 392 } 342 } 393 | '<' 343 | '<' 394 { 344 { 395 $$.data = data_add_mar !! 345 $$.data = empty_data; 396 $$.bits = 32; 346 $$.bits = 32; 397 } 347 } 398 | arrayprefix integer_prim 348 | arrayprefix integer_prim 399 { 349 { 400 if ($1.bits < 64) { 350 if ($1.bits < 64) { 401 uint64_t mask 351 uint64_t mask = (1ULL << $1.bits) - 1; 402 /* 352 /* 403 * Bits above 353 * Bits above mask must either be all zero 404 * (positive w 354 * (positive within range of mask) or all one 405 * (negative a 355 * (negative and sign-extended). The second 406 * condition i 356 * condition is true if when we set all bits 407 * within the 357 * within the mask to one (i.e. | in the 408 * mask), all 358 * mask), all bits are one. 409 */ 359 */ 410 if (($2 > mask !! 360 if (($2 > mask) && (($2 | mask) != -1ULL)) 411 char * !! 361 ERROR(&@2, "Value out of range for" 412 fprint !! 362 " %d-bit array element", $1.bits); 413 << 414 << 415 << 416 free(l << 417 } << 418 } 363 } 419 364 420 $$.data = data_append_ 365 $$.data = data_append_integer($1.data, $2, $1.bits); 421 } 366 } 422 | arrayprefix dt_ref !! 367 | arrayprefix DT_REF 423 { 368 { 424 uint64_t val = ~0ULL > 369 uint64_t val = ~0ULL >> (64 - $1.bits); 425 370 426 if ($1.bits == 32) 371 if ($1.bits == 32) 427 $1.data = data 372 $1.data = data_add_marker($1.data, 428 373 REF_PHANDLE, 429 374 $2); 430 else 375 else 431 ERROR(&@2, "Re 376 ERROR(&@2, "References are only allowed in " 432 "a 377 "arrays with 32-bit elements."); 433 378 434 $$.data = data_append_ 379 $$.data = data_append_integer($1.data, val, $1.bits); 435 } 380 } 436 | arrayprefix DT_LABEL 381 | arrayprefix DT_LABEL 437 { 382 { 438 $$.data = data_add_mar 383 $$.data = data_add_marker($1.data, LABEL, $2); 439 } 384 } 440 ; 385 ; 441 386 442 integer_prim: 387 integer_prim: 443 DT_LITERAL 388 DT_LITERAL 444 | DT_CHAR_LITERAL 389 | DT_CHAR_LITERAL 445 | '(' integer_expr ')' 390 | '(' integer_expr ')' 446 { 391 { 447 $$ = $2; 392 $$ = $2; 448 } 393 } 449 ; 394 ; 450 395 451 integer_expr: 396 integer_expr: 452 integer_trinary 397 integer_trinary 453 ; 398 ; 454 399 455 integer_trinary: 400 integer_trinary: 456 integer_or 401 integer_or 457 | integer_or '?' integer_expr ':' inte 402 | integer_or '?' integer_expr ':' integer_trinary { $$ = $1 ? $3 : $5; } 458 ; 403 ; 459 404 460 integer_or: 405 integer_or: 461 integer_and 406 integer_and 462 | integer_or DT_OR integer_and { $$ = 407 | integer_or DT_OR integer_and { $$ = $1 || $3; } 463 ; 408 ; 464 409 465 integer_and: 410 integer_and: 466 integer_bitor 411 integer_bitor 467 | integer_and DT_AND integer_bitor { $ 412 | integer_and DT_AND integer_bitor { $$ = $1 && $3; } 468 ; 413 ; 469 414 470 integer_bitor: 415 integer_bitor: 471 integer_bitxor 416 integer_bitxor 472 | integer_bitor '|' integer_bitxor { $ 417 | integer_bitor '|' integer_bitxor { $$ = $1 | $3; } 473 ; 418 ; 474 419 475 integer_bitxor: 420 integer_bitxor: 476 integer_bitand 421 integer_bitand 477 | integer_bitxor '^' integer_bitand { 422 | integer_bitxor '^' integer_bitand { $$ = $1 ^ $3; } 478 ; 423 ; 479 424 480 integer_bitand: 425 integer_bitand: 481 integer_eq 426 integer_eq 482 | integer_bitand '&' integer_eq { $$ = 427 | integer_bitand '&' integer_eq { $$ = $1 & $3; } 483 ; 428 ; 484 429 485 integer_eq: 430 integer_eq: 486 integer_rela 431 integer_rela 487 | integer_eq DT_EQ integer_rela { $$ = 432 | integer_eq DT_EQ integer_rela { $$ = $1 == $3; } 488 | integer_eq DT_NE integer_rela { $$ = 433 | integer_eq DT_NE integer_rela { $$ = $1 != $3; } 489 ; 434 ; 490 435 491 integer_rela: 436 integer_rela: 492 integer_shift 437 integer_shift 493 | integer_rela '<' integer_shift { $$ 438 | integer_rela '<' integer_shift { $$ = $1 < $3; } 494 | integer_rela '>' integer_shift { $$ 439 | integer_rela '>' integer_shift { $$ = $1 > $3; } 495 | integer_rela DT_LE integer_shift { $ 440 | integer_rela DT_LE integer_shift { $$ = $1 <= $3; } 496 | integer_rela DT_GE integer_shift { $ 441 | integer_rela DT_GE integer_shift { $$ = $1 >= $3; } 497 ; 442 ; 498 443 499 integer_shift: 444 integer_shift: 500 integer_shift DT_LSHIFT integer_add !! 445 integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; } 501 | integer_shift DT_RSHIFT integer_add !! 446 | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; } 502 | integer_add 447 | integer_add 503 ; 448 ; 504 449 505 integer_add: 450 integer_add: 506 integer_add '+' integer_mul { $$ = $ 451 integer_add '+' integer_mul { $$ = $1 + $3; } 507 | integer_add '-' integer_mul { $$ = $ 452 | integer_add '-' integer_mul { $$ = $1 - $3; } 508 | integer_mul 453 | integer_mul 509 ; 454 ; 510 455 511 integer_mul: 456 integer_mul: 512 integer_mul '*' integer_unary { $$ = 457 integer_mul '*' integer_unary { $$ = $1 * $3; } 513 | integer_mul '/' integer_unary 458 | integer_mul '/' integer_unary 514 { 459 { 515 if ($3 != 0) { 460 if ($3 != 0) { 516 $$ = $1 / $3; 461 $$ = $1 / $3; 517 } else { 462 } else { 518 ERROR(&@$, "Di 463 ERROR(&@$, "Division by zero"); 519 $$ = 0; 464 $$ = 0; 520 } 465 } 521 } 466 } 522 | integer_mul '%' integer_unary 467 | integer_mul '%' integer_unary 523 { 468 { 524 if ($3 != 0) { 469 if ($3 != 0) { 525 $$ = $1 % $3; 470 $$ = $1 % $3; 526 } else { 471 } else { 527 ERROR(&@$, "Di 472 ERROR(&@$, "Division by zero"); 528 $$ = 0; 473 $$ = 0; 529 } 474 } 530 } 475 } 531 | integer_unary 476 | integer_unary 532 ; 477 ; 533 478 534 integer_unary: 479 integer_unary: 535 integer_prim 480 integer_prim 536 | '-' integer_unary { $$ = -$2; } 481 | '-' integer_unary { $$ = -$2; } 537 | '~' integer_unary { $$ = ~$2; } 482 | '~' integer_unary { $$ = ~$2; } 538 | '!' integer_unary { $$ = !$2; } 483 | '!' integer_unary { $$ = !$2; } 539 ; 484 ; 540 485 541 bytestring: 486 bytestring: 542 /* empty */ 487 /* empty */ 543 { 488 { 544 $$ = data_add_marker(e !! 489 $$ = empty_data; 545 } 490 } 546 | bytestring DT_BYTE 491 | bytestring DT_BYTE 547 { 492 { 548 $$ = data_append_byte( 493 $$ = data_append_byte($1, $2); 549 } 494 } 550 | bytestring DT_LABEL 495 | bytestring DT_LABEL 551 { 496 { 552 $$ = data_add_marker($ 497 $$ = data_add_marker($1, LABEL, $2); 553 } 498 } 554 ; 499 ; 555 500 556 subnodes: 501 subnodes: 557 /* empty */ 502 /* empty */ 558 { 503 { 559 $$ = NULL; 504 $$ = NULL; 560 } 505 } 561 | subnode subnodes 506 | subnode subnodes 562 { 507 { 563 $$ = chain_node($1, $2 508 $$ = chain_node($1, $2); 564 } 509 } 565 | subnode propdef 510 | subnode propdef 566 { 511 { 567 ERROR(&@2, "Properties 512 ERROR(&@2, "Properties must precede subnodes"); 568 YYERROR; 513 YYERROR; 569 } 514 } 570 ; 515 ; 571 516 572 subnode: 517 subnode: 573 DT_PROPNODENAME nodedef 518 DT_PROPNODENAME nodedef 574 { 519 { 575 $$ = name_node($2, $1) 520 $$ = name_node($2, $1); 576 free($1); << 577 } 521 } 578 | DT_DEL_NODE DT_PROPNODENAME ';' 522 | DT_DEL_NODE DT_PROPNODENAME ';' 579 { 523 { 580 $$ = name_node(build_n !! 524 $$ = name_node(build_node_delete(), $2); 581 free($2); << 582 } << 583 | DT_OMIT_NO_REF subnode << 584 { << 585 $$ = omit_node_if_unus << 586 } 525 } 587 | DT_LABEL subnode 526 | DT_LABEL subnode 588 { 527 { 589 add_label(&$2->labels, 528 add_label(&$2->labels, $1); 590 $$ = $2; 529 $$ = $2; 591 } 530 } 592 ; 531 ; 593 532 594 %% 533 %% 595 534 596 void yyerror(char const *s) 535 void yyerror(char const *s) 597 { 536 { 598 ERROR(&yylloc, "%s", s); 537 ERROR(&yylloc, "%s", s); 599 } 538 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.