MCPcopy Index your code
hub / github.com/python/cpython / resolve_decl

Function resolve_decl

Tools/c-analyzer/c_analyzer/analyze.py:100–146  ·  view source on GitHub ↗
(decl, typespecs, knowntypespecs, types)

Source from the content-addressed store, hash-verified

98
99
100def 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
149def find_typedecl(decl, typespec, typespecs):

Callers 1

analyze_declFunction · 0.85

Calls 8

is_potsFunction · 0.90
POTSTypeClass · 0.90
is_funcptrFunction · 0.90
FuncPtrClass · 0.90
is_system_typeFunction · 0.85
SystemTypeClass · 0.85
find_typedeclFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…