Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 20x 20x 25x 25x 12x 20x 12x 12x 12x 12x 12x 12x 12x | /**
* ParameterExtractorUtils - Shared utilities for parameter extraction in C/C++.
*
* Contains common patterns for building parameter info from extracted values.
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import IExtractedParameter from "./IExtractedParameter";
class ParameterExtractorUtils {
/**
* Process a list of parameter declarations and collect parameter info.
*
* @param paramList The parameter list context (from either C or C++ grammar)
* @param extractInfo Function to extract parameter info from a single declaration
* @returns Array of extracted parameters
*/
static processParameterList(
paramList: any,
extractInfo: (paramDecl: any) => IExtractedParameter | null,
): IExtractedParameter[] {
const params: IExtractedParameter[] = [];
for (const paramDecl of paramList.parameterDeclaration?.() ?? []) {
const paramInfo = extractInfo(paramDecl);
if (paramInfo) {
params.push(paramInfo);
}
}
return params;
}
/**
* Build extracted parameter info from intermediate values.
*
* @param declarator The declarator context
* @param baseType The base type string
* @param isConst Whether the parameter is const
* @param isPointer Whether the parameter is a pointer
* @param isArray Whether the parameter is an array
* @param extractName Function to extract name from declarator
* @returns The extracted parameter info
*/
static buildParameterInfo(
declarator: any,
baseType: string,
isConst: boolean,
isPointer: boolean,
isArray: boolean,
extractName: (decl: any) => string | null,
): IExtractedParameter {
// Append * to type if pointer
const finalType = isPointer ? baseType + "*" : baseType;
// Get parameter name (may be empty for abstract declarators)
let paramName = "";
Eif (declarator) {
const name = extractName(declarator);
Eif (name) {
paramName = name;
}
}
return {
name: paramName,
type: finalType,
isConst,
isArray,
};
}
}
export default ParameterExtractorUtils;
|