@@ -151,7 +151,7 @@ def write_local_declarations(self, referenced: Set[str]) -> None:
151151 and not self .localsymboltable .is_formal (vinfo .vname )):
152152 self .ccode .newline (indent = self .indent )
153153 if vinfo .vtype is None :
154- self .ccode .write ("? " + vinfo .vname )
154+ self .ccode .write ("? " + vinfo .vname + ";" )
155155 continue
156156
157157 if vinfo .vtype .is_array :
@@ -185,14 +185,19 @@ def write_global_declarations(self) -> None:
185185 continue
186186 self .ccode .newline (indent = self .indent )
187187 if vinfo .vtype is None :
188- self .ccode .write ("? " + vinfo .vname )
188+ self .ccode .write ("? " + vinfo .vname + ";" )
189189 continue
190190
191191 if vinfo .vtype .is_function :
192192 ftype = cast (AST .ASTTypFun , vinfo .vtype )
193- ftype .returntyp .accept (self )
194- self .ccode .write (" " )
195- self .ccode .write (vinfo .vname )
193+ if ftype .returntyp .is_function_pointer :
194+ returntyp = cast (AST .ASTTypPtr , ftype .returntyp )
195+ fnptr = cast (AST .ASTTypFun , returntyp .tgttyp )
196+ self .funtypptr_with_name (fnptr , vinfo .vname )
197+ else :
198+ ftype .returntyp .accept (self )
199+ self .ccode .write (" " )
200+ self .ccode .write (vinfo .vname )
196201 self .ccode .write ("(" )
197202 if ftype .argtypes is not None :
198203 ftype .argtypes .accept (self )
@@ -608,20 +613,43 @@ def visit_fun_typ(self, t: AST.ASTTypFun) -> None:
608613 t .argtypes .accept (self )
609614 self .ccode .write (")" )
610615
616+ def funtypptr_with_name (self , t : AST .ASTTypFun , name : str ) -> None :
617+ if t .returntyp .is_function_pointer :
618+ returntyp = cast (AST .ASTTypPtr , t .returntyp )
619+ retty = cast (AST .ASTTypFun , returntyp .tgttyp )
620+ self .funtypptr_with_name (retty , name )
621+ self .ccode .write ("(" )
622+ if t .argtypes is not None :
623+ t .argtypes .accept (self )
624+ self .ccode .write (")" )
625+ else :
626+ t .returntyp .accept (self )
627+ self .ccode .write (" (*" )
628+ self .ccode .write (name )
629+ self .ccode .write (")(" )
630+ if t .argtypes is not None :
631+ t .argtypes .accept (self )
632+ self .ccode .write (")" )
633+
611634 def visit_funargs (self , funargs : AST .ASTFunArgs ) -> None :
612635 args = funargs .funargs
613636 if len (args ) == 0 :
614- pass
637+ self . ccode . write ( "void" )
615638 else :
616639 for arg in args [:- 1 ]:
617640 arg .accept (self )
618641 self .ccode .write (", " )
619642 args [- 1 ].accept (self )
620643
621644 def visit_funarg (self , funarg : AST .ASTFunArg ) -> None :
622- funarg .argtyp .accept (self )
623- self .ccode .write (" " )
624- self .ccode .write (funarg .argname )
645+ if funarg .argtyp .is_function_pointer :
646+ argtyp = cast (AST .ASTTypPtr , funarg .argtyp )
647+ fnptr = cast (AST .ASTTypFun , argtyp .tgttyp )
648+ self .funtypptr_with_name (fnptr , funarg .argname )
649+ else :
650+ funarg .argtyp .accept (self )
651+ self .ccode .write (" " )
652+ self .ccode .write (funarg .argname )
625653
626654 def visit_named_typ (self , t : AST .ASTTypNamed ) -> None :
627655 self .ccode .write ("typedef " )
@@ -649,6 +677,11 @@ def visit_compinfo(self, cinfo: AST.ASTCompInfo) -> None:
649677 if atype .size_expr is not None :
650678 atype .size_expr .accept (self )
651679 self .ccode .write ("];" )
680+ elif finfo .fieldtype .is_function_pointer :
681+ fieldtyp = cast (AST .ASTTypPtr , finfo .fieldtype )
682+ funtyp = cast (AST .ASTTypFun , fieldtyp .tgttyp )
683+ self .funtypptr_with_name (funtyp , finfo .fieldname )
684+ self .ccode .write (";" )
652685 else :
653686 finfo .fieldtype .accept (self )
654687 self .ccode .write (" " )
0 commit comments