(decl, typespecs, knowntypespecs, types)
| 98 | |
| 99 | |
| 100 | def resolve_decl(decl, typespecs, knowntypespecs, types): |
| 101 | if decl.kind is KIND.ENUM: |
| 102 | typedeps = [] |
| 103 | else: |
| 104 | if decl.kind is KIND.VARIABLE: |
| 105 | vartypes = [decl.vartype] |
| 106 | elif decl.kind is KIND.FUNCTION: |
| 107 | vartypes = [decl.signature.returntype] |
| 108 | elif decl.kind is KIND.TYPEDEF: |
| 109 | vartypes = [decl.vartype] |
| 110 | elif decl.kind is KIND.STRUCT or decl.kind is KIND.UNION: |
| 111 | vartypes = [m.vartype for m in decl.members] |
| 112 | else: |
| 113 | # Skip this one! |
| 114 | return None |
| 115 | |
| 116 | typedeps = [] |
| 117 | for vartype in vartypes: |
| 118 | typespec = vartype.typespec |
| 119 | if is_pots(typespec): |
| 120 | typedecl = POTSType(typespec) |
| 121 | elif is_system_type(typespec): |
| 122 | typedecl = SystemType(typespec) |
| 123 | elif is_funcptr(vartype): |
| 124 | typedecl = FuncPtr(vartype) |
| 125 | else: |
| 126 | typedecl = find_typedecl(decl, typespec, typespecs) |
| 127 | if typedecl is None: |
| 128 | typedecl = find_typedecl(decl, typespec, knowntypespecs) |
| 129 | elif not isinstance(typedecl, TypeDeclaration): |
| 130 | raise NotImplementedError(repr(typedecl)) |
| 131 | if typedecl is None: |
| 132 | # We couldn't find it! |
| 133 | typedecl = UNKNOWN |
| 134 | elif typedecl not in types: |
| 135 | # XXX How can this happen? |
| 136 | typedecl = UNKNOWN |
| 137 | elif types[typedecl] is UNKNOWN: |
| 138 | typedecl = UNKNOWN |
| 139 | elif types[typedecl] is IGNORED: |
| 140 | # We don't care if it didn't resolve. |
| 141 | pass |
| 142 | elif types[typedecl] is None: |
| 143 | # The typedecl for the typespec hasn't been resolved yet. |
| 144 | typedecl = None |
| 145 | typedeps.append(typedecl) |
| 146 | return typedeps |
| 147 | |
| 148 | |
| 149 | def find_typedecl(decl, typespec, typespecs): |
no test coverage detected
searching dependent graphs…