import { Call, Joinpoint, FileJp } from "@specs-feup/clava/api/Joinpoints.js"; import { AnalysisType, MISRATransformationReport } from "../../MISRA.js"; import UserConfigurableRule from "../UserConfigurableRule.js"; /** * * Abstract base class for MISRA-C rules that prohibit the use of function of a standard library. * * Need to implement/define: * - analysisType * - standardLibrary * - invalidFunctions * - name() */ export default abstract class DisallowedStdLibFunctionRule extends UserConfigurableRule { /** * A positive integer starting from 1 that indicates the rule's priority, determining the order in which rules are applied. */ readonly priority = 1; /** * A map that keeps track of invalid usages found in each file. */ protected invalidFiles: Map; /** * The name of the standard library */ protected abstract standardLibrary: string; /** * Names of functions from {@link standardLibrary} that are forbidden. * If the set is empty, all functions from {@link standardLibrary} are forbidden. */ protected abstract invalidFunctions: Set; /** * Calls that could not be resolved and their respective error message, stored to prevent repeated attempts of correction after rebuild. */ protected unresolvedCalls: Map; /** * Files where headers were kept because other library features are still used. */ protected filesWithRetainedHeaders: Set; /** * Specifies the scope of analysis: single unit or entire system. */ abstract readonly analysisType: AnalysisType; /** * @returns Rule identifier according to MISRA-C:2012 */ abstract get name(): string; /** * Checks if all functions of the library are forbidden */ private isLibraryFullyDisallowed; /** * Logs a MISRA error when the entire library is disallowed and * records the file to track headers that must be retained. * * @param fileJp - The file in which the disallowed include was found. */ private logDisallowedInclude; /** * Logs a MISRA error for a disallowed function call and records * the call along with its error message to avoid repeated attempts * * @param callJp - The disallowed function call * @param msg - Description of the violation */ private logDisallowedCall; /** * Returns the prefix to be used for error messages related to the given joinpoint * * @param $jp - Joinpoint where the violation was detected * @returns Returns a prefix to prepend to error messages if no configuration is specified or if the configuration does not contain a fix for this violation */ protected getErrorMsgPrefix(callJp: Call): string; /** * Retrieves a fix for the given joinpoint using the provided configuration file * @param $jp - Joinpoint where the violation was detected * @return The fix retrieved from the configuration for the violation, or `undefined` if no applicable fix is found. */ protected getFixFromConfig(callJp: Call): Map | undefined; /** * * @param $jp - Joinpoint to analyze * @param logErrors - [logErrors=false] - Whether to log errors if a violation is detected * @returns Returns true if the joinpoint violates the rule, false otherwise */ match($jp: Joinpoint, logErrors?: boolean): boolean; /** * * @param $jp - Joinpoint to transform * @returns Report detailing the transformation result */ apply($jp: Joinpoint): MISRATransformationReport; private solveDisallowedFunctions; private solveDisallowedFunctionCall; private getExternFunctionDeclIds; /** * Removes the standard library include if it is fully disallowed and all invalid calls were fixed. * If the file is invalid after include removal because other library features are still being used (e.g.: typedefs), the include is re-added. * * @param fileJp The file to modify * @param fixedAllCalls Flag to indicate whether all calls were fixed */ private removeInclude; } //# sourceMappingURL=DisallowedStdLibFunctionRule.d.ts.map