001package gudusoft.gsqlparser.analyzer.v2;
002
003/**
004 * Configuration for the IR-based Analyzer v2 system.
005 * <p>
006 * Controls feature flags, analysis depth, dynamic SQL handling,
007 * and output formatting. Supports gradual rollout via dual-track mode.
008 *
009 * <pre>
010 * Rollout stages:
011 *   Stage 1: useIRPath=false, enableLegacyDiff=false  → Pure legacy
012 *   Stage 2: useIRPath=false, enableLegacyDiff=true   → Legacy primary, IR parallel + diff
013 *   Stage 3: useIRPath=true,  enableLegacyDiff=true   → IR primary, legacy fallback
014 *   Stage 4: useIRPath=true,  enableLegacyDiff=false  → IR only, legacy removable
015 * </pre>
016 */
017public class AnalyzerV2Config {
018
019    // === Path Control ===
020
021    /** Whether to enable the new IR path (default off, gradually enable during rollout). */
022    public boolean useIRPath = false;
023
024    /** Whether to run legacy path in parallel and output diff report. */
025    public boolean enableLegacyDiff = false;
026
027    // === Dynamic SQL Strategy ===
028
029    /** Dynamic SQL parsing strategy. */
030    public EDynamicSqlStrategy dynamicSqlStrategy = EDynamicSqlStrategy.BEST_EFFORT;
031
032    // === Analysis Depth Control ===
033
034    /** Maximum call graph depth (prevents infinite expansion on cyclic dependencies). */
035    public int maxCallGraphDepth = 50;
036
037    /** Whether to track cursor data flow (OPEN/FETCH/CLOSE lifecycle). */
038    public boolean trackCursorDataFlow = true;
039
040    /** Whether to track exception control flow (EXCEPTION WHEN → handler). */
041    public boolean trackExceptionFlow = true;
042
043    // === Output Control ===
044
045    /** Whether JSON output includes detailed sourceAnchor information. */
046    public boolean includeSourceAnchors = true;
047
048    /** Whether JSON output includes evidence chains. */
049    public boolean includeEvidence = true;
050
051    /**
052     * Join-analysis slice 174 (S13) — when {@code true} and an
053     * {@code ILogicalIRBuilder} is supplied, {@code IRTranslator} runs the
054     * Logical IR Phase 2 and carries the resulting
055     * {@code ir.logical.LogicalProgram} on {@code IRProgram}. Default off,
056     * so bound-only callers are unaffected.
057     */
058    public boolean enableLogicalPhase = false;
059
060    // === Factory Methods ===
061
062    /**
063     * Creates default configuration (legacy path, IR disabled).
064     */
065    public static AnalyzerV2Config createDefault() {
066        return new AnalyzerV2Config();
067    }
068
069    /**
070     * Creates IR-enabled configuration.
071     */
072    public static AnalyzerV2Config createIREnabled() {
073        AnalyzerV2Config config = new AnalyzerV2Config();
074        config.useIRPath = true;
075        return config;
076    }
077
078    /**
079     * Creates dual-track configuration for regression testing.
080     * Both IR and legacy paths run, with diff reporting enabled.
081     */
082    public static AnalyzerV2Config createDualTrack() {
083        AnalyzerV2Config config = new AnalyzerV2Config();
084        config.useIRPath = true;
085        config.enableLegacyDiff = true;
086        return config;
087    }
088}