Visual range code validity determination method, electronic device and medium
By dividing the source code into multiple continuous visual ranges and obtaining the validity data of conditional compilation statements, the problem of low source code processing efficiency in the prior art is solved, and fast and accurate conditional compilation statement code validity judgment is achieved.
Patent Information
- Application Number
- CN202411704753.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2044-11-26
AI Technical Summary
When processing the source code of extremely large files, existing technologies have difficulty in quickly and accurately determining the validity of conditional compilation statement codes within the visible range, especially in the presence of code folding and hiding. Traditional lexical analysis algorithms require a long time to traverse the entire file.
The visible range to be processed is divided into multiple continuous visible ranges, the code validity data of the conditional compilation statement is obtained, and the validity of the conditional compilation statement in each continuous visible range is determined through pointer traversal and overlapping relationship, and the judgment is performed using the method of steps S1 to S9.
Improves the efficiency and accuracy of conditional compilation statement code validity judgment within the visible range, reduces processing time, and ensures accurate recognition in code folding and hiding situations.
Smart Images

Figure CN119621069B_ABST
Abstract
Claims
1. A method for determining the validity of a visual range code, characterized in that: Including: Step S1: Divide the visual range to be processed into M continuous visual ranges {G1, G2, ..., G m ,…,G M },G m is the mth continuous visual range, the value range of m is 1 to M, G1, G2, ..., G m ,…,G M Arrange in order of code position; Step S2: Obtain the code validity data {A1, A2, ..., A ... n ,…,A N }, A n The code validity data corresponding to the nth group of conditional compilation statements, n ranges from 1 to N, N is the total number of code validity data groups corresponding to conditional compilation statements, A1, A2, ..., A n ,…,A N Arrange in order of code position, A n Including the code location information and code validity information of the nth top-level conditional compilation statement and the code location information and code validity information of all descendant conditional compilation statements nested in the nth top-level conditional compilation statement; Step S3: Initially set m = 1, initially set the preset pointer to point to A1, and initially set n = 1; Step S4: Get A n The corresponding starting position SCn and ending position ECn; Step S5: If ECn < SV, then execute Step S7; if SCn > EV, then set the current preset pointer to point to A n-1 , execute Step S8; otherwise, execute Step S6, where SV is the starting position of G m , and EV is the ending position of G m ; Step S6: Get G m With A n The overlapping part AT n =[STP n ,ETP n ],STP n AT n Starting position, ETP n AT n The end position of Step S7. If n < N, set n = n + 1, and set the current preset pointer to point to A n , return to execute Step S4. If n = N and ECn ≤ EV, set the current preset pointer to be empty, and execute Step S8. If n = N and ECn > EV, execute Step S8; Step S8: Based on the overlapping part in {A1, A2, ..., A n ,…,A N } The corresponding code validity information determines G m The validity of the conditional compilation statement code; Step S9: If m < M, then set m = m + 1, and return to execute Step S5. If m = M or the current preset pointer points to null, then end the process.
2. The method according to claim 1, wherein Step S1 includes: Step S11: Set dividing lines at the folding position and the code hiding position in the visible range to be processed, and generate M continuous visible ranges {G1, G2, ..., G m ,…,G M }.
3. The method according to claim 1, wherein Step S1 includes: Step S01: Set dividing lines at the folding positions and code hiding positions in the visible range to be processed. If the number of code lines in each continuous visible range obtained is less than or equal to the preset code line threshold, then execute Step S03; otherwise, execute Step S02; Step S02: Evenly divide the continuous visible range with the number of code lines greater than the preset code line threshold into multiple continuous visible ranges, so that the number of code lines in each obtained continuous visible range is less than or equal to the preset code line threshold; Step S03: Generate M continuous visual ranges {G1, G2, ..., G m ,…,G M }.
4. The method according to claim 1, wherein Step S4 includes: Step S41: A n The starting position of the top-level conditional compilation statement is determined to be A n The corresponding starting position SCn; Step S42: A n The sum of the starting position and the length of the corresponding text corresponding to the top-level conditional compilation statement is determined as A n The corresponding end position ECn.
5. The method according to claim 1, wherein A n ={B1 n ,B2 n ,…,B x n ,…,B f(n) n ,U n }, where B x n A n The code validity data corresponding to the xth conditional compilation statement in the code validation data, the value range of x is 1 to f(n), and f(n) is A n The total number of conditional compilation statements in U n B x n Parent-child relationship information between all B x n The corresponding conditional compilation statements are nested to form a top-level conditional compilation statement; B x n ={BF xn ,BL xn ,BV xn }, where BF xn A n The starting position corresponding to the xth conditional compilation statement, BL xn A n The length of the text corresponding to the xth conditional compilation statement, BV xn A n The compilation status corresponding to the xth conditional compilation statement in the compilation state includes two states: valid and invalid.
6. The method according to claim 5, wherein In the step S8, all conditional compilation statement codes in the continuous visible range to be processed are set to be valid by default. n The overlapping part AT n implement: Step S81: Initially set AT n For the overlapping part to be processed, the level identifier t is initially set to 1, and the conditional compilation statement sequence number g(t) in the t-th level is initially set to 1. In the same level, the smaller the g(t) value is, the earlier the code line corresponding to the conditional compilation statement is in the source code. Step S82: Based on A n The code validity data in obtains the g(t)th conditional compilation statement B at the tth level tg(t) The overlapping part AT with the overlapping part to be processed tg(t) =[STP tg(t) ,ETP tg(t) ],STP tg(t) AT tg(t) Starting position, ETP tg(t) AT tg(t) The end position of Step S83. Obtain the compilation status of B based on the code validity data in A n . If the compilation status of B tg(t) corresponding is an invalid status, then update the code corresponding to A tg(t) to an invalid status, and update g(x) = g(x) + h(x), where the initial value of g(x) is 1, t < x ≤ T, and T is the maximum level serial number in A tg(t) , and h(x) is the number of conditional compilation statements nested in B n and belonging to the x-th level. Then execute step S86. If the compilation status of B tg(t) corresponding is a valid status, then execute step S84; tg(t) Step S84: Based on U n Judgment B tg(t) Check whether there is a sub-conditional compilation statement. If yes, execute step S85; otherwise, execute step S86. Step S85: First set t = t + 1, and return to execute Step S82; Step S86: If ETP tg(t) =ETP n , then end AT n The validity of the code is handled if ETP tg(t) <ETP n , then [ETP tg(t) ,ETP n ] is updated to the overlapping part to be processed, and step S87 is executed; Step S87: If g(t) < f(t), where f(t) is the total number of conditional compilation statements at the t-th level, then set g(t) = g(t) + 1, and return to execute Step S82. If g(t) = f(t), then first set t = t - 1, then set g(t) = g(t) + 1, and return to execute Step S82.
7. An electronic device, characterized in that: Including: At least one processor; And a memory communicatively connected to the at least one processor; Wherein, the memory stores instructions executable by the at least one processor, and the instructions are configured to execute the method according to any one of the preceding claims 1-6.
8. A computer-readable storage medium, characterized in that Stores computer-executable instructions for executing the method according to any one of the preceding claims 1-6.
Citation Information
Patent Citations
Code detection processing method and device
CN117762806A
Checking source code validity when code is updated
CN118202330A