@@ -523,10 +523,21 @@ def varintro(self) -> Dict[str, str]:
523523
524524 @property
525525 def offset (self ) -> int :
526+ """The offset is negated to reflect the actual relationship between
527+ the stack pointer address at function entry and the address of the
528+ variable.
529+ """
530+
526531 if not "offset" in self .varintro :
527532 chklogger .logger .warning (
528533 "Stack variable intro without offset; returning 0" )
529- return int (self .varintro .get ("offset" , "0" ))
534+ index = int (self .varintro .get ("offset" , "0" ))
535+ if index > 0 :
536+ return - index
537+ else :
538+ raise UF .CHBError (
539+ "Unexpected non-positive offset in stack-variable intro: "
540+ + str (self .offset ))
530541
531542 @property
532543 def name (self ) -> str :
@@ -539,18 +550,26 @@ def name(self) -> str:
539550 def typename (self ) -> Optional [str ]:
540551 return self .varintro .get ("typename" , None )
541552
553+ @property
554+ def mods (self ) -> List [str ]:
555+ return cast (List [str ], self .varintro .get ("mods" , []))
556+
557+ @property
558+ def is_array (self ) -> bool :
559+ return any (a for a in self .mods if a .startswith ("array" ))
560+
542561 @property
543562 def arraysize (self ) -> Optional [int ]:
544- if "array" in self .varintro :
545- return int (self .varintro .get ("array" , "0" ))
546- else :
547- return None
563+ if self .is_array :
564+ entry = next (a for a in self .mods if a .startswith ("array" ))
565+ eindex = entry .find (":" )
566+ if eindex > 0 :
567+ return int (entry [eindex + 1 :])
568+ return None
548569
549570 @property
550571 def ispointer (self ) -> bool :
551- if "ptrto" in self .varintro :
552- return self .varintro .get ("ptrto" , "no" ) == "yes"
553- return False
572+ return "ptrto" in self .mods
554573
555574 def to_xml (self , node : ET .Element ) -> None :
556575 xvintro = ET .Element ("vintro" )
@@ -612,6 +631,16 @@ def get_register_variable_introduction(self, iaddr: str) -> RegisterVarIntro:
612631 return rvintros [iaddr ]
613632 raise UF .CHBError ("No register variable introductions for " + iaddr )
614633
634+ def has_stack_variable_introduction (self , offset : int ) -> bool :
635+ return offset in self .stack_variable_introductions
636+
637+ def get_stack_variable_introduction (self , offset : int ) -> StackVarIntro :
638+ svintros = self .stack_variable_introductions
639+ if offset in svintros :
640+ return svintros [offset ]
641+ raise UF .CHBError (
642+ "No stack variable introduction for offset " + str (offset ))
643+
615644 def to_xml (self , node : ET .Element ) -> None :
616645 node .set ("faddr" , self .faddr )
617646 if len (self .stack_variable_introductions ) > 0 :
0 commit comments