Skip to content

Commit ad063c6

Browse files
committed
ASTI: raise exception on unresolved typedef
1 parent cf7e02f commit ad063c6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

chb/astinterface/BC2ASTConverter.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# ------------------------------------------------------------------------------
2727
"""Converter from the BC types (CIL) to the AST types."""
2828

29-
from typing import Dict, List
29+
from typing import Dict, List, Optional
3030

3131
from chb.ast.ASTIndexer import ASTIndexer
3232
import chb.ast.ASTNode as AST
@@ -48,6 +48,7 @@
4848
from chb.bctypes.BCVarInfo import BCVarInfo
4949

5050
import chb.util.fileutil as UF
51+
from chb.util.loggingutil import chklogger
5152

5253
bc2ast_operators: Dict[str, str] = {
5354
"div": "div",
@@ -255,11 +256,16 @@ def convert_funarg(self, arg: BCFunArg) -> AST.ASTFunArg:
255256
return AST.ASTFunArg(arg.name, arg.typ.convert(self))
256257

257258
def convert_named_typ(self, t: BCT.BCTypNamed) -> AST.ASTTyp:
258-
typdef = t.typedef.ttype.convert(self)
259-
namedtype = AST.ASTTypNamed(t.tname, typdef)
260-
self.symboltable.add_typedef(namedtype)
261-
# return namedtype
262-
return typdef
259+
typdef = t.typedef
260+
if typdef is not None:
261+
asttypdef = typdef.ttype.convert(self)
262+
namedtype = AST.ASTTypNamed(t.tname, asttypdef)
263+
self.symboltable.add_typedef(namedtype)
264+
return asttypdef
265+
else:
266+
chklogger.logger.error(
267+
"No definition for typedef %s", t.tname)
268+
raise UF.CHBError("No definition for typedef name " + t.tname)
263269

264270
def convert_builtin_va_list(
265271
self, t: BCT.BCTypBuiltinVaList) -> AST.ASTTypBuiltinVAList:

0 commit comments

Comments
 (0)