paul@8 | 1 | /* |
paul@28 | 2 | * Interface summary generation. |
paul@28 | 3 | * |
paul@214 | 4 | * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk> |
paul@28 | 5 | * |
paul@28 | 6 | * This program is free software; you can redistribute it and/or |
paul@28 | 7 | * modify it under the terms of the GNU General Public License as |
paul@28 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@28 | 9 | * the License, or (at your option) any later version. |
paul@28 | 10 | * |
paul@28 | 11 | * This program is distributed in the hope that it will be useful, |
paul@28 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@28 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@28 | 14 | * GNU General Public License for more details. |
paul@28 | 15 | * |
paul@28 | 16 | * You should have received a copy of the GNU General Public License |
paul@28 | 17 | * along with this program; if not, write to the Free Software |
paul@28 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@28 | 19 | * Boston, MA 02110-1301, USA |
paul@8 | 20 | */ |
paul@8 | 21 | |
paul@8 | 22 | #include <stdio.h> |
paul@20 | 23 | #include "summary.h" |
paul@8 | 24 | |
paul@214 | 25 | |
paul@214 | 26 | |
paul@214 | 27 | static void indent(int level) |
paul@9 | 28 | { |
paul@214 | 29 | while (level--) putchar(' '); |
paul@9 | 30 | } |
paul@9 | 31 | |
paul@214 | 32 | static void show_imports(struct import *imp, int level) |
paul@214 | 33 | { |
paul@214 | 34 | if (imp == NULL) |
paul@214 | 35 | return; |
paul@214 | 36 | |
paul@214 | 37 | show_imports(imp->tail, level); |
paul@214 | 38 | |
paul@214 | 39 | indent(level); |
paul@214 | 40 | printf("%s: %s\n", "Import", imp->filename); |
paul@214 | 41 | } |
paul@214 | 42 | |
paul@214 | 43 | static void show_includes(struct include *inc, int level) |
paul@21 | 44 | { |
paul@23 | 45 | if (inc == NULL) |
paul@23 | 46 | return; |
paul@214 | 47 | |
paul@214 | 48 | show_includes(inc->tail, level); |
paul@21 | 49 | |
paul@214 | 50 | indent(level); |
paul@214 | 51 | printf("%s: %s\n", "Include", inc->filename); |
paul@8 | 52 | } |
paul@8 | 53 | |
paul@214 | 54 | static void show_identifiers(struct identifier *ident) |
paul@25 | 55 | { |
paul@214 | 56 | while (ident != NULL) |
paul@214 | 57 | { |
paul@214 | 58 | printf(" %s", ident->identifier); |
paul@214 | 59 | ident = ident->tail; |
paul@214 | 60 | } |
paul@25 | 61 | } |
paul@25 | 62 | |
paul@214 | 63 | static void show_parameter(struct parameter *param, int level) |
paul@9 | 64 | { |
paul@30 | 65 | char *type; |
paul@30 | 66 | |
paul@214 | 67 | indent(level); |
paul@18 | 68 | printf("Parameter: %s%s", param->specifier & IN_PARAMETER ? "IN" : "", |
paul@18 | 69 | param->specifier & OUT_PARAMETER ? "OUT" : ""); |
paul@18 | 70 | |
paul@30 | 71 | /* Items must have their type identifiers restored. */ |
paul@30 | 72 | |
paul@57 | 73 | if (param->cls & ITEM_CLASS) |
paul@30 | 74 | { |
paul@57 | 75 | type = param->cls == FPAGE_ITEM ? "fpage" : "cap"; |
paul@30 | 76 | printf(" %s", type); |
paul@30 | 77 | } |
paul@30 | 78 | |
paul@51 | 79 | show_identifiers(param->identifiers); |
paul@18 | 80 | printf("\n"); |
paul@9 | 81 | } |
paul@25 | 82 | |
paul@214 | 83 | static void show_parameters(struct parameter *param, int level) |
paul@214 | 84 | { |
paul@214 | 85 | if (param == NULL) |
paul@214 | 86 | return; |
paul@214 | 87 | |
paul@214 | 88 | show_parameter(param, level); |
paul@214 | 89 | show_parameters(param->tail, level); |
paul@214 | 90 | } |
paul@214 | 91 | |
paul@214 | 92 | static void show_attribute(struct attribute *attr, int level) |
paul@214 | 93 | { |
paul@214 | 94 | indent(level); |
paul@214 | 95 | printf("Attribute: %s", attr->attribute); |
paul@214 | 96 | |
paul@214 | 97 | show_identifiers(attr->identifiers); |
paul@214 | 98 | printf("\n"); |
paul@214 | 99 | } |
paul@214 | 100 | |
paul@214 | 101 | static void show_attributes(struct attribute *attr, int level) |
paul@214 | 102 | { |
paul@214 | 103 | if (attr == NULL) |
paul@214 | 104 | return; |
paul@214 | 105 | |
paul@214 | 106 | show_attribute(attr, level); |
paul@214 | 107 | show_attributes(attr->tail, level); |
paul@214 | 108 | } |
paul@214 | 109 | |
paul@214 | 110 | static void show_signature(struct signature *sig, int level) |
paul@214 | 111 | { |
paul@214 | 112 | indent(level); |
paul@214 | 113 | printf("Signature: %s %s\n", sig->qualifier, sig->operation); |
paul@214 | 114 | |
paul@214 | 115 | show_attributes(sig->attributes, level + 2); |
paul@214 | 116 | show_parameters(sig->parameters, level + 2); |
paul@214 | 117 | } |
paul@214 | 118 | |
paul@214 | 119 | static void show_signatures(struct signature *sig, int level) |
paul@25 | 120 | { |
paul@214 | 121 | if (sig == NULL) |
paul@214 | 122 | return; |
paul@214 | 123 | |
paul@214 | 124 | show_signature(sig, level); |
paul@214 | 125 | show_signatures(sig->tail, level); |
paul@214 | 126 | } |
paul@214 | 127 | |
paul@214 | 128 | static void show_bases(struct interface_ref *base, int level) |
paul@214 | 129 | { |
paul@214 | 130 | if (base == NULL) |
paul@214 | 131 | return; |
paul@214 | 132 | |
paul@214 | 133 | indent(level); |
paul@214 | 134 | printf("Base: %s\n", base->name); |
paul@214 | 135 | |
paul@214 | 136 | if (base->iface != NULL) |
paul@214 | 137 | show_interface(base->iface, level + 2); |
paul@214 | 138 | show_bases(base->tail, level); |
paul@25 | 139 | } |
paul@214 | 140 | |
paul@214 | 141 | |
paul@214 | 142 | |
paul@214 | 143 | /* Public functions. */ |
paul@214 | 144 | |
paul@214 | 145 | void show_interface(struct interface *iface, int level) |
paul@214 | 146 | { |
paul@214 | 147 | indent(level); |
paul@214 | 148 | printf("Interface: %s\n", iface->name); |
paul@214 | 149 | indent(level); |
paul@214 | 150 | printf("Basename: %s\n", iface->output_basename); |
paul@214 | 151 | |
paul@214 | 152 | show_bases(iface->bases, level + 2); |
paul@214 | 153 | show_imports(iface->imports, level); |
paul@214 | 154 | show_includes(iface->includes, level); |
paul@214 | 155 | show_attributes(iface->attributes, level); |
paul@214 | 156 | show_signatures(iface->signatures, level); |
paul@214 | 157 | } |
paul@214 | 158 | |
paul@214 | 159 | void show_interfaces(struct interface *iface) |
paul@214 | 160 | { |
paul@214 | 161 | if (iface->tail != NULL) |
paul@214 | 162 | show_interfaces(iface->tail); |
paul@214 | 163 | |
paul@214 | 164 | show_interface(iface, 0); |
paul@214 | 165 | } |