|
| 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 | +(* chutil *) |
| 29 | +open CHTraceResult |
| 30 | +open CHXmlDocument |
| 31 | + |
| 32 | +(* cchpre *) |
| 33 | +open CCHPreTypes |
| 34 | + |
| 35 | + |
| 36 | +let eloc (line: int): string = __FILE__ ^ ":" ^ (string_of_int line) |
| 37 | +let elocm (line: int): string = (eloc line) ^ ": " |
| 38 | + |
| 39 | + |
| 40 | +let analysis_digest_name (kind: analysis_digest_kind_t): string = |
| 41 | + match kind with |
| 42 | + | UndefinedBehaviorAnalysis -> "undefined-behavior" |
| 43 | + | OutputParameterAnalysis _ -> "output parameters" |
| 44 | + |
| 45 | + |
| 46 | +class analysis_digest_t |
| 47 | + (_fname: string) |
| 48 | + (_pod: podictionary_int) |
| 49 | + (kind: analysis_digest_kind_t): analysis_digest_int = |
| 50 | +object (self) |
| 51 | + |
| 52 | + method is_active (po_s: proof_obligation_int list) = |
| 53 | + match kind with |
| 54 | + | UndefinedBehaviorAnalysis -> true |
| 55 | + | OutputParameterAnalysis digest -> digest#is_active po_s |
| 56 | + |
| 57 | + method kind = kind |
| 58 | + |
| 59 | + method write_xml (node: xml_element_int) = |
| 60 | + let _ = node#setAttribute "name" (analysis_digest_name self#kind) in |
| 61 | + match self#kind with |
| 62 | + | OutputParameterAnalysis digest -> digest#write_xml node |
| 63 | + | _ -> () |
| 64 | + |
| 65 | + method read_xml (node: xml_element_int): unit traceresult = |
| 66 | + match self#kind with |
| 67 | + | UndefinedBehaviorAnalysis -> Ok () |
| 68 | + | OutputParameterAnalysis digest -> digest#read_xml node |
| 69 | + |
| 70 | +end |
| 71 | + |
| 72 | + |
| 73 | +let mk_undefined_behavior_analysis_digest |
| 74 | + (fname: string) (pod: podictionary_int): analysis_digest_int = |
| 75 | + new analysis_digest_t fname pod UndefinedBehaviorAnalysis |
| 76 | + |
| 77 | + |
| 78 | +let mk_output_parameter_analysis_digest |
| 79 | + (fname: string) (pod: podictionary_int): analysis_digest_int = |
| 80 | + let opdigest = CCHOutputParameterAnalysis.mk_analysis_digest fname pod in |
| 81 | + new analysis_digest_t fname pod (OutputParameterAnalysis opdigest) |
| 82 | + |
| 83 | + |
| 84 | +let read_xml_analysis_digest |
| 85 | + (node: xml_element_int) |
| 86 | + (fname: string) |
| 87 | + (pod: podictionary_int): analysis_digest_int traceresult = |
| 88 | + let name = node#getAttribute "name" in |
| 89 | + match name with |
| 90 | + | "undefined-behavior" -> |
| 91 | + Ok (mk_undefined_behavior_analysis_digest fname pod) |
| 92 | + | "output parameters" -> |
| 93 | + let digest = mk_output_parameter_analysis_digest fname pod in |
| 94 | + let _ = digest#read_xml node in |
| 95 | + Ok digest |
| 96 | + | _ -> |
| 97 | + Error [(elocm __LINE__) ^ "Name of analysis not recognized: " ^ name] |
0 commit comments