|
| 1 | +# ------------------------------------------------------------------------------ |
| 2 | +# CodeHawk C Analyzer |
| 3 | +# Author: Henny Sipma |
| 4 | +# ------------------------------------------------------------------------------ |
| 5 | +# The MIT License (MIT) |
| 6 | +# |
| 7 | +# Copyright (c) 2025 Aarno Labs LLC |
| 8 | +# |
| 9 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | +# of this software and associated documentation files (the "Software"), to deal |
| 11 | +# in the Software without restriction, including without limitation the rights |
| 12 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | +# copies of the Software, and to permit persons to whom the Software is |
| 14 | +# furnished to do so, subject to the following conditions: |
| 15 | +# |
| 16 | +# The above copyright notice and this permission notice shall be included in all |
| 17 | +# copies or substantial portions of the Software. |
| 18 | +# |
| 19 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | +# SOFTWARE. |
| 26 | +# ------------------------------------------------------------------------------ |
| 27 | + |
| 28 | +import xml.etree.ElementTree as ET |
| 29 | + |
| 30 | +from typing import Optional, TYPE_CHECKING |
| 31 | + |
| 32 | +if TYPE_CHECKING: |
| 33 | + from chc.app.CContext import ProgramContext |
| 34 | + from chc.app.CContext import CContextDictionary |
| 35 | + from chc.app.CDictionary import CDictionary |
| 36 | + from chc.app.CExp import CExp |
| 37 | + from chc.app.CFile import CFile |
| 38 | + from chc.app.CFileDeclarations import CFileDeclarations |
| 39 | + from chc.app.CFunction import CFunction |
| 40 | + from chc.app.CLocation import CLocation |
| 41 | + |
| 42 | + |
| 43 | +class CFunctionReturnSite: |
| 44 | + |
| 45 | + def __init__(self, cfun: "CFunction", xnode: ET.Element) -> None: |
| 46 | + self._cfun = cfun |
| 47 | + self._xnode = xnode |
| 48 | + |
| 49 | + @property |
| 50 | + def cfun(self) -> "CFunction": |
| 51 | + return self._cfun |
| 52 | + |
| 53 | + @property |
| 54 | + def cdictionary(self) -> "CDictionary": |
| 55 | + return self.cfun.cdictionary |
| 56 | + |
| 57 | + @property |
| 58 | + def cfile(self) -> "CFile": |
| 59 | + return self.cfun.cfile |
| 60 | + |
| 61 | + @property |
| 62 | + def cfiledeclarations(self) -> "CFileDeclarations": |
| 63 | + return self.cfile.declarations |
| 64 | + |
| 65 | + @property |
| 66 | + def contextdictionary(self) -> "CContextDictionary": |
| 67 | + return self.cfile.contextdictionary |
| 68 | + |
| 69 | + @property |
| 70 | + def xnode(self) -> ET.Element: |
| 71 | + return self._xnode |
| 72 | + |
| 73 | + @property |
| 74 | + def location(self) -> "CLocation": |
| 75 | + return self.cfiledeclarations.read_xml_location(self.xnode) |
| 76 | + |
| 77 | + @property |
| 78 | + def returnexp(self) -> Optional["CExp"]: |
| 79 | + return self.cdictionary.read_xml_exp_o(self.xnode) |
| 80 | + |
| 81 | + @property |
| 82 | + def context(self) -> "ProgramContext": |
| 83 | + return self.contextdictionary.read_xml_program_context(self.xnode) |
| 84 | + |
| 85 | + def __str__(self): |
| 86 | + rexp = str(self.returnexp) if self.returnexp else "" |
| 87 | + return ( |
| 88 | + "return " + rexp + " (" |
| 89 | + + str(self.location.line) + ", " + str(self.location.byte) |
| 90 | + + ") (" |
| 91 | + + str(self.context) |
| 92 | + ) |
0 commit comments