1 /* 2 * Generation of declaration elements such as parameters and members. 3 * 4 * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include "declaration.h" 23 24 /* Generate parameters in each function signature. */ 25 26 void write_parameters(struct parameter *param, FILE *fp, enum parameter_role role) 27 { 28 if (param == NULL) 29 return; 30 31 write_parameter(param, fp, role); 32 write_parameter_separator(param->tail, fp); 33 write_parameters(param->tail, fp, role); 34 } 35 36 /* Generate a parameter in a signature. */ 37 38 void write_parameter(struct parameter *param, FILE *fp, enum parameter_role role) 39 { 40 struct identifier *ident = param->identifiers; 41 char *type; 42 int first = 1; 43 44 while (ident != NULL) 45 { 46 if (first) 47 first = 0; 48 else 49 fputs(" ", fp); 50 51 /* Emit type identifiers. */ 52 53 if (ident->tail != NULL) 54 fputs(ident->identifier, fp); 55 56 /* Emit the parameter name. */ 57 58 else 59 { 60 /* Items must have their type identifiers restored. */ 61 62 if (param->cls & ITEM_CLASS) 63 { 64 type = param->cls == FPAGE_ITEM ? L4_FPAGE_TYPE : L4_CAP_TYPE; 65 fputs(type, fp); 66 fputs(" ", fp); 67 } 68 69 fprintf(fp, "%s%s", (role == SIGNATURE_ROLE) && (param->specifier & OUT_PARAMETER) ? "*" : "", 70 ident->identifier); 71 } 72 73 ident = ident->tail; 74 } 75 } 76 77 void write_parameter_separator(struct parameter *param, FILE *fp) 78 { 79 if (param != NULL) 80 fputs(", ", fp); 81 } 82 83 /* Write structure members for word data structures or variable declarations for 84 parameters. */ 85 86 void write_declarations(struct parameter *param, enum specifier direction, 87 enum parameter_class cls, FILE *fp) 88 { 89 for (; param != NULL; param = param->tail) 90 { 91 if ((param->specifier & direction) && (param->cls & cls)) 92 { 93 fputs(" ", fp); 94 write_parameter(param, fp, STRUCTURE_ROLE); 95 fputs(";\n", fp); 96 } 97 } 98 }