@@ -2,37 +2,19 @@ import { useEffect, useState } from "react";
22import { PreprocessedCodesContext } from "../../../context/PreProcessedCodesContext" ;
33import { useContext } from "react" ;
44import { ActivateItem } from "@/pages/Visualization/types/activateItem" ;
5- import { VariablesDto } from "@/pages/Visualization/types/dto/variablesDto" ;
6- import { ForDto } from "@/pages/Visualization/types/dto/forDto" ;
7- import { PrintDto } from "@/pages/Visualization/types/dto/printDto" ;
8- import { IfElseDto } from "@/pages/Visualization/types/dto/ifElseDto" ;
9- import { CodeFlowVariableDto } from "@/pages/Visualization/types/dto/codeFlowVariableDto" ;
10- import { WhileDto } from "@/pages/Visualization/types/dto/whileDto" ;
115import { AllDataStructureItem } from "@/pages/Visualization/types/dataStructuresItem/allDataStructureItem" ;
126import { WrapperDataStructureItem } from "@/pages/Visualization/types/dataStructuresItem/wrapperDataStructureItem" ;
13- import { CreateCallStackDto } from "@/pages/Visualization/types/dto/createCallStackDto" ;
14- import { EndUserFuncDto } from "@/pages/Visualization/types/dto/endUserFuncDto" ;
157import { usedNameObjectType } from "../../../types/dataStructuresItem/usedNameObjectType" ;
16- import { AppendDto } from "../../../types/dto/appendDto" ;
17- import { IfElseChangeDto } from "@/pages/Visualization/types/dto/ifElseChangeDto" ;
188import { State } from "../types" ;
199import { useConsoleStore , useCodeFlowLengthStore } from "@/store/console" ;
2010import { useEditorStore } from "@/store/editor" ;
2111import { useArrowStore } from "@/store/arrow" ;
2212import _ from "lodash" ;
2313
2414// Processors
25- import { processEndUserFunc } from "./processors/processEndUserFunc" ;
26- import { processAppend } from "./processors/processAppend" ;
27- import { processAssign } from "./processors/processAssign" ;
28- import { processCreateCallStack } from "./processors/processCreateCallStack" ;
29- import { processIfElseDefine } from "./processors/processIfElseDefine" ;
30- import { processCodeFlow } from "./processors/processCodeFlow" ;
31- import {
32- resetDataStructuresLight ,
33- calculateToLightStructures ,
34- applyLightToStructures ,
35- } from "./processors/utils" ;
15+ import { dispatchProcessor } from "./processors/processorDispatcher" ;
16+ import { ProcessorContext } from "./processors/types" ;
17+ import { resetDataStructuresLight , calculateToLightStructures , applyLightToStructures } from "./processors/utils" ;
3618
3719interface ProcessingState {
3820 prevTrackingId : number ;
@@ -113,98 +95,30 @@ export const usePreprocessedCodesProcessor = () => {
11395
11496 const codeType = preprocessedCode . type . toLowerCase ( ) ;
11597
116- // 타입별 처리
117- if ( codeType === "enduserfunc" ) {
118- const result = processEndUserFunc ( {
119- preprocessedCode : preprocessedCode as EndUserFuncDto ,
120- accCodeFlow : state . accCodeFlow ,
121- accDataStructures : state . accDataStructures ,
122- usedName : state . usedName ,
123- prevTrackingId : state . prevTrackingId ,
124- prevTrackingDepth : state . prevTrackingDepth ,
125- } ) ;
126-
127- state . accCodeFlow = result . accCodeFlow ;
128- state . accDataStructures = result . accDataStructures ;
129- state . usedName = result . usedName ;
130- state . arrowTexts . push ( result . arrowText ) ;
131- state . highlightLine . push ( result . highlightId ) ;
132- state . prevTrackingId = result . newTrackingId ;
133- state . prevTrackingDepth = result . newTrackingDepth ;
134- } else if ( codeType === "append" ) {
135- const result = processAppend ( {
136- preprocessedCode : preprocessedCode as AppendDto ,
137- accCodeFlow : state . accCodeFlow ,
138- accDataStructures : state . accDataStructures ,
139- usedId : state . usedId ,
140- } ) ;
141-
142- state . accCodeFlow = result . accCodeFlow ;
143- state . accDataStructures = result . accDataStructures ;
144- state . usedId = result . usedId ;
145- state . arrowTexts . push ( result . arrowText ) ;
146- state . highlightLine . push ( result . highlightId ) ;
147- } else if ( codeType === "assign" ) {
148- const result = processAssign ( {
149- preprocessedCode : preprocessedCode as VariablesDto ,
150- accCodeFlow : state . accCodeFlow ,
151- accDataStructures : state . accDataStructures ,
152- usedName : state . usedName ,
153- usedId : state . usedId ,
154- } ) ;
155-
156- state . accCodeFlow = result . accCodeFlow ;
157- state . accDataStructures = result . accDataStructures ;
158- state . usedName = result . usedName ;
159- state . usedId = result . usedId ;
160- state . arrowTexts . push ( ...result . arrowTexts ) ;
161- state . highlightLine . push ( ...result . highlightIds ) ;
162- } else if ( codeType === "createcallstack" ) {
163- const result = processCreateCallStack ( {
164- preprocessedCode : preprocessedCode as CreateCallStackDto ,
165- accDataStructures : state . accDataStructures ,
166- usedName : state . usedName ,
167- } ) ;
168-
169- state . accDataStructures = result . accDataStructures ;
170- state . usedName = result . usedName ;
171- state . arrowTexts . push ( result . arrowText ) ;
172- state . highlightLine . push ( result . highlightId ) ;
173- } else if ( codeType === "ifelsedefine" ) {
174- const result = processIfElseDefine ( {
175- preprocessedCode : preprocessedCode as IfElseDto ,
176- accCodeFlow : state . accCodeFlow ,
177- usedId : state . usedId ,
178- prevTrackingId : state . prevTrackingId ,
179- prevTrackingDepth : state . prevTrackingDepth ,
180- } ) ;
181-
182- state . accCodeFlow = result . accCodeFlow ;
183- state . usedId = result . usedId ;
184- state . arrowTexts . push ( result . arrowText ) ;
185- state . highlightLine . push ( result . highlightId ) ;
186- state . prevTrackingId = result . newTrackingId ;
187- state . prevTrackingDepth = result . newTrackingDepth ;
188- } else {
189- // 기타 타입 (for, print, while, variable 등)
190- const result = processCodeFlow ( {
191- preprocessedCode : preprocessedCode as ForDto | PrintDto | IfElseChangeDto | CodeFlowVariableDto | WhileDto ,
192- accCodeFlow : state . accCodeFlow ,
193- usedId : state . usedId ,
194- activate : state . activate ,
195- prevTrackingId : state . prevTrackingId ,
196- prevTrackingDepth : state . prevTrackingDepth ,
197- } ) ;
198-
199- state . accCodeFlow = result . accCodeFlow ;
200- state . usedId = result . usedId ;
201- state . activate = result . activate ;
202- state . arrowTexts . push ( result . arrowText ) ;
203- state . highlightLine . push ( result . highlightId ) ;
204- state . accConsoleLog += result . consoleLog ;
205- state . prevTrackingId = result . newTrackingId ;
206- state . prevTrackingDepth = result . newTrackingDepth ;
207- }
98+ const context : ProcessorContext = {
99+ preprocessedCode,
100+ accCodeFlow : state . accCodeFlow ,
101+ accDataStructures : state . accDataStructures ,
102+ usedName : state . usedName ,
103+ usedId : state . usedId ,
104+ activate : state . activate ,
105+ prevTrackingId : state . prevTrackingId ,
106+ prevTrackingDepth : state . prevTrackingDepth ,
107+ } ;
108+
109+ const result = dispatchProcessor ( codeType , context ) ;
110+
111+ if ( result . accCodeFlow ) state . accCodeFlow = result . accCodeFlow ;
112+ if ( result . accDataStructures ) state . accDataStructures = result . accDataStructures ;
113+ if ( result . usedName ) state . usedName = result . usedName ;
114+ if ( result . usedId ) state . usedId = result . usedId ;
115+ if ( result . activate ) state . activate = result . activate ;
116+ if ( result . consoleLog ) state . accConsoleLog += result . consoleLog ;
117+ if ( result . newTrackingId !== undefined ) state . prevTrackingId = result . newTrackingId ;
118+ if ( result . newTrackingDepth !== undefined ) state . prevTrackingDepth = result . newTrackingDepth ;
119+
120+ state . arrowTexts . push ( ...result . arrowTexts ) ;
121+ state . highlightLine . push ( ...result . highlightIds ) ;
208122
209123 // toLightStructures 계산 및 적용
210124 const { toLightStructures, accCodeFlow : updatedCodeFlow } = calculateToLightStructures (
0 commit comments