1 /* 2 * Interface summary generation. 3 * 4 * Copyright (C) 2019, 2022 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 <stdio.h> 23 #include "summary.h" 24 25 26 27 static void indent(int level) 28 { 29 while (level--) putchar(' '); 30 } 31 32 static void show_imports(struct import *imp, int level) 33 { 34 if (imp == NULL) 35 return; 36 37 show_imports(imp->tail, level); 38 39 indent(level); 40 printf("%s: %s\n", "Import", imp->filename); 41 } 42 43 static void show_includes(struct include *inc, int level) 44 { 45 if (inc == NULL) 46 return; 47 48 show_includes(inc->tail, level); 49 50 indent(level); 51 printf("%s: %s\n", "Include", inc->filename); 52 } 53 54 static void show_identifiers(struct identifier *ident) 55 { 56 while (ident != NULL) 57 { 58 printf(" %s", ident->identifier); 59 ident = ident->tail; 60 } 61 } 62 63 static void show_parameter(struct parameter *param, int level) 64 { 65 char *type; 66 67 indent(level); 68 printf("Parameter: %s%s", param->specifier & IN_PARAMETER ? "IN" : "", 69 param->specifier & OUT_PARAMETER ? "OUT" : ""); 70 71 /* Items must have their type identifiers restored. */ 72 73 if (param->cls & ITEM_CLASS) 74 { 75 type = param->cls == FPAGE_ITEM ? "fpage" : "cap"; 76 printf(" %s", type); 77 } 78 79 show_identifiers(param->identifiers); 80 printf("\n"); 81 } 82 83 static void show_parameters(struct parameter *param, int level) 84 { 85 if (param == NULL) 86 return; 87 88 show_parameter(param, level); 89 show_parameters(param->tail, level); 90 } 91 92 static void show_attribute(struct attribute *attr, int level) 93 { 94 indent(level); 95 printf("Attribute: %s", attr->attribute); 96 97 show_identifiers(attr->identifiers); 98 printf("\n"); 99 } 100 101 static void show_attributes(struct attribute *attr, int level) 102 { 103 if (attr == NULL) 104 return; 105 106 show_attribute(attr, level); 107 show_attributes(attr->tail, level); 108 } 109 110 static void show_signature(struct signature *sig, int level) 111 { 112 indent(level); 113 printf("Signature: %s %s\n", sig->qualifier, sig->operation); 114 115 show_attributes(sig->attributes, level + 2); 116 show_parameters(sig->parameters, level + 2); 117 } 118 119 static void show_signatures(struct signature *sig, int level) 120 { 121 if (sig == NULL) 122 return; 123 124 show_signature(sig, level); 125 show_signatures(sig->tail, level); 126 } 127 128 static void show_bases(struct interface_ref *base, int level) 129 { 130 if (base == NULL) 131 return; 132 133 indent(level); 134 printf("Base: %s\n", base->name); 135 136 if (base->iface != NULL) 137 show_interface(base->iface, level + 2); 138 show_bases(base->tail, level); 139 } 140 141 142 143 /* Public functions. */ 144 145 void show_interface(struct interface *iface, int level) 146 { 147 indent(level); 148 printf("Interface: %s\n", iface->name); 149 indent(level); 150 printf("Basename: %s\n", iface->output_basename); 151 152 show_bases(iface->bases, level + 2); 153 show_imports(iface->imports, level); 154 show_includes(iface->includes, level); 155 show_attributes(iface->attributes, level); 156 show_signatures(iface->signatures, level); 157 } 158 159 void show_interfaces(struct interface *iface) 160 { 161 if (iface->tail != NULL) 162 show_interfaces(iface->tail); 163 164 show_interface(iface, 0); 165 }