| 
 | 1 | +/* Copyright (C) 2025 Free Software Foundation, Inc.  | 
 | 2 | +
  | 
 | 3 | +This file is part of GCC.  | 
 | 4 | +
  | 
 | 5 | +GCC is free software; you can redistribute it and/or modify it under  | 
 | 6 | +the terms of the GNU General Public License as published by the Free  | 
 | 7 | +Software Foundation; either version 3, or (at your option) any later  | 
 | 8 | +version.  | 
 | 9 | +
  | 
 | 10 | +GCC is distributed in the hope that it will be useful, but WITHOUT ANY  | 
 | 11 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or  | 
 | 12 | +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License  | 
 | 13 | +for more details.  | 
 | 14 | +
  | 
 | 15 | +You should have received a copy of the GNU General Public License  | 
 | 16 | +along with GCC; see the file COPYING3.  If not see  | 
 | 17 | +<http://www.gnu.org/licenses/>.  */  | 
 | 18 | + | 
 | 19 | +%{  | 
 | 20 | + | 
 | 21 | +#include <stdlib.h>  | 
 | 22 | +#include <stdio.h>  | 
 | 23 | +#include <ctype.h>  | 
 | 24 | + | 
 | 25 | +int yylex (void);  | 
 | 26 | +void yyerror (char const *);  | 
 | 27 | + | 
 | 28 | +#include "scan.h"  | 
 | 29 | + | 
 | 30 | +// expands to three %s parameters  | 
 | 31 | +#define UNWRAP_OPT_STR(prefix, s) (s ? prefix "_SOME (" : prefix "_NONE"), (s ? s : ""), (s ? ")" : "")  | 
 | 32 | + | 
 | 33 | +%}  | 
 | 34 | + | 
 | 35 | +%union  | 
 | 36 | +{  | 
 | 37 | +  char *str;  | 
 | 38 | +};  | 
 | 39 | + | 
 | 40 | +%token <str> IDENT STR NUM  | 
 | 41 | +%token SCOPE  | 
 | 42 | +%token K_SOME K_NONE  | 
 | 43 | +%token K_ACTIVE K_ACCEPTED K_REMOVED K_STABLE_REMOVED  | 
 | 44 | +%token K_E_START K_E_2018  | 
 | 45 | + | 
 | 46 | +%type <str> issue  | 
 | 47 | +%type <str> edition  | 
 | 48 | +%type <str> reason  | 
 | 49 | + | 
 | 50 | +%%  | 
 | 51 | + | 
 | 52 | +multi_database: multi_database database  | 
 | 53 | +| database  | 
 | 54 | +;  | 
 | 55 | + | 
 | 56 | +database: '(' entry_list ')';  | 
 | 57 | + | 
 | 58 | +entry_list: entry_list entry ','  | 
 | 59 | +| entry ','  | 
 | 60 | +;  | 
 | 61 | + | 
 | 62 | +entry: '(' K_ACTIVE ',' IDENT ',' STR ',' issue ',' edition ')' {  | 
 | 63 | +  char *ident_upper = strdup ($4);  | 
 | 64 | +  for (size_t i = 0; ident_upper[i]; i++)  | 
 | 65 | +    ident_upper[i] = toupper (ident_upper[i]);  | 
 | 66 | +  printf ("FEATURE_ACTIVE (\"%s\", %s, %s, %s%s%s, EDITION_%s)\n", $4, ident_upper, $6, UNWRAP_OPT_STR ("ISSUE", $8), $10 ? $10 : "NONE");  | 
 | 67 | +  free ($4);  | 
 | 68 | +  free (ident_upper);  | 
 | 69 | +  free ($6);  | 
 | 70 | +  free ($8);  | 
 | 71 | +}  | 
 | 72 | +| '(' K_ACCEPTED ',' IDENT ',' STR ',' issue ',' K_NONE ')' {  | 
 | 73 | +  char *ident_upper = strdup ($4);  | 
 | 74 | +  for (size_t i = 0; ident_upper[i]; i++)  | 
 | 75 | +    ident_upper[i] = toupper (ident_upper[i]);  | 
 | 76 | +  printf ("FEATURE_ACCEPTED (\"%s\", %s, %s, %s%s%s)\n", $4, ident_upper, $6, UNWRAP_OPT_STR ("ISSUE", $8));  | 
 | 77 | +  free ($4);  | 
 | 78 | +  free (ident_upper);  | 
 | 79 | +  free ($6);  | 
 | 80 | +  free ($8);  | 
 | 81 | +}  | 
 | 82 | +| '(' K_REMOVED ',' IDENT ',' STR ',' issue ',' K_NONE ',' reason ')' {  | 
 | 83 | +  char *ident_upper;  | 
 | 84 | +  // HACK: convert no_debug to F_NO_DEBUG instead  | 
 | 85 | +  // since NO_DEBUG is used as an unrelated macro  | 
 | 86 | +  if (!strcmp ($4, "no_debug"))  | 
 | 87 | +    {  | 
 | 88 | +      ident_upper = strdup ("F_NO_DEBUG");  | 
 | 89 | +    }  | 
 | 90 | +  else  | 
 | 91 | +    {  | 
 | 92 | +      ident_upper = strdup ($4);  | 
 | 93 | +      for (size_t i = 0; ident_upper[i]; i++)  | 
 | 94 | +        ident_upper[i] = toupper (ident_upper[i]);  | 
 | 95 | +    }  | 
 | 96 | +  printf ("FEATURE_REMOVED (\"%s\", %s, %s, %s%s%s, %s%s%s)\n", $4, ident_upper, $6, UNWRAP_OPT_STR ("ISSUE", $8), UNWRAP_OPT_STR ("REASON", $12));  | 
 | 97 | +  free ($4);  | 
 | 98 | +  free (ident_upper);  | 
 | 99 | +  free ($6);  | 
 | 100 | +  free ($8);  | 
 | 101 | +  free ($12);  | 
 | 102 | +}  | 
 | 103 | +| '(' K_STABLE_REMOVED ',' IDENT ',' STR ',' issue ',' K_NONE ')' {  | 
 | 104 | +  char *ident_upper = strdup ($4);  | 
 | 105 | +  for (size_t i = 0; ident_upper[i]; i++)  | 
 | 106 | +    ident_upper[i] = toupper (ident_upper[i]);  | 
 | 107 | +  printf ("FEATURE_STABLE_REMOVED (\"%s\", %s, %s, %s%s%s)\n", $4, ident_upper, $6, UNWRAP_OPT_STR ("ISSUE", $8));  | 
 | 108 | +  free ($4);  | 
 | 109 | +  free (ident_upper);  | 
 | 110 | +  free ($6);  | 
 | 111 | +  free ($8);  | 
 | 112 | +}  | 
 | 113 | +;  | 
 | 114 | + | 
 | 115 | +issue: K_SOME '(' NUM ')' { $$ = $3; }  | 
 | 116 | +| K_NONE { $$ = NULL; }  | 
 | 117 | +;  | 
 | 118 | + | 
 | 119 | +/* TODO: expand this as needed */  | 
 | 120 | +edition: K_NONE { $$ = NULL; }  | 
 | 121 | +| K_SOME '(' K_E_START SCOPE K_E_2018 ')' { $$ = "2018"; }  | 
 | 122 | +;  | 
 | 123 | + | 
 | 124 | +reason: K_SOME '(' STR ')' { $$ = $3; }  | 
 | 125 | +| K_NONE { $$ = NULL; }  | 
 | 126 | +;  | 
 | 127 | + | 
 | 128 | +%%  | 
 | 129 | + | 
 | 130 | +void yyerror (const char *msg)  | 
 | 131 | +{  | 
 | 132 | +  fprintf (stderr, "%s\n", msg);  | 
 | 133 | +}  | 
 | 134 | + | 
 | 135 | +int yywrap (void)  | 
 | 136 | +{  | 
 | 137 | +  return 1;  | 
 | 138 | +}  | 
 | 139 | + | 
 | 140 | +int main (void)  | 
 | 141 | +{  | 
 | 142 | +  return yyparse ();  | 
 | 143 | +}  | 
0 commit comments