Source code hierarchy positioning method, electronic equipment and medium
By acquiring and analyzing the hierarchical structure information of code files and using different display identifiers to distinguish code lines, the problem of quickly and accurately locating code hierarchies, especially the parent-child relationship hierarchy, is solved, thereby improving code browsing efficiency.
Patent Information
- Application Number
- CN202511250345.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-03
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2045-09-03
AI Technical Summary
When viewing source code, it is difficult to quickly and accurately locate the code level that the user is concerned about, especially the adjacent parent-child relationship hierarchy.
By obtaining the code line hierarchy information of the code file, the target level, code range of the target level, and code range of the target sub-level of the target code line are determined, and different display identifiers are used to distinguish the code lines to achieve fast and accurate positioning.
It enables fast and accurate positioning of the code hierarchy that users are concerned about, especially the parent-child relationship hierarchy, and improves code browsing efficiency.
Smart Images

Figure CN120743345A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a source code level positioning method, electronic equipment, and medium. Background Art
[0002] In the computer field, it is often necessary to review large amounts of source code, which often has a certain hierarchical structure. For example, in the C++ language, a class can contain multiple functions, and a function can contain multiple sub-statement blocks. In the SystemVerilog language, a module can contain multiple functions or methods, and functions and methods can contain multiple sub-statement blocks. There is a clear containment and inclusion relationship between these grammatical structures, forming a hierarchical structure of the code. When reviewing source code, it is often necessary to jump between multiple code levels to view the relevant relationships between the code. Among them, viewing adjacent hierarchical relationships with "parent-child" relationships is particularly common. Therefore, how to provide a method to quickly and accurately locate the code level that the user is concerned about has become a technical problem that needs to be solved urgently. Summary of the Invention
[0003] The present invention aims to provide a source code level positioning method, electronic device and medium, which can quickly and accurately locate the code level of the user's interest.
[0004] According to a first aspect of the present invention, a source code level positioning method is provided, comprising: Step S1, obtain the code line hierarchy information of the code file {(A1, B1), (A2, B2), ..., (A n ,B n ),...,(A N ,B N )},A n is the nth line number of the code file, B n The level corresponding to the nth line of code in the code file, where n ranges from 1 to N, and N is the total number of code line levels in the code file; Step S2: Based on the code line hierarchy information of the code file, determine the target level corresponding to the target code line, the code range (BS, BE) corresponding to the target level, the code range (CS, CE) corresponding to the parent level of the target level, and the list of all target sub-level code ranges {(DS1, DE1), (DS2, DE2), ..., (DS m ,DE m ),...,(DS M ,DS M )},(DS m ,DE m) is the mth sub-level code range in (BS, BE), the value of m ranges from 1 to M, and M is the total number of sub-level code ranges in (BS, BE); Step S3: Get the current visible code range (VS, VE), initially set the display identifier of each code line to the default identifier, update the display identifier of the code line belonging to (BS, BE) in (VS, VE) to the first display identifier, update the display identifier of the code line belonging to (CS, CE) in (VS, VE) to the second display identifier, and update the display identifier of the code line belonging to {(DS1, DE1), (DS2, DE2), ..., (DS m ,DE m ),...,(DS M ,DS M )}The code line display indicator is updated to the third display indicator.
[0005] According to a second aspect of the present invention, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executed by the at least one processor, the instructions being configured to execute the method described in the first aspect of the present invention.
[0006] According to a third aspect of the present invention, a computer-readable storage medium is provided, storing computer-executable instructions, wherein the computer instructions are used to execute the method according to the first aspect of the present invention.
[0007] The present invention has significant advantages and beneficial effects compared to existing technologies. Through the above-mentioned technical solution, the source code level location method, electronic device, and medium provided by the present invention can achieve considerable technological advancement and practicality, and have wide industrial application value, and at least have the following beneficial effects: The present invention first obtains the code line hierarchy information of the code file, and then determines the target level corresponding to the target code line, the code range corresponding to the target level, and all target sub-level code ranges based on the code line hierarchy information of the code file, and then displays the code lines belonging to the target level, the code range corresponding to the target level, and the target sub-level code range in the code lines within the visible range using different display identifiers, thereby realizing the rapid and accurate positioning of the code level that the user is concerned about. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0009] Figure 1 This is a flow chart of the source code level positioning method provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0010] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work shall fall within the scope of protection of the present invention.
[0011] The embodiment of the present invention provides a source code level positioning method, such as Figure 1 Shown, including: Step S1, obtain the code line hierarchy information of the code file {(A1, B1), (A2, B2), ..., (A n ,B n ),...,(A N ,B N )},(A n ,B n ) is the hierarchical structure information corresponding to the nth line of code in the code file, A n is the nth line number of the code file, B n The level corresponding to the nth line of code in the code file. The value of n ranges from 1 to N, where N is the total number of code line levels in the code file.
[0012] The code file may be a code file written in C++, SystemVerilog, VHDL, Verilog, etc. n ,...,A N Sort in order from smallest to largest.
[0013] Step S2: Based on the code line hierarchy information of the code file, determine the target level corresponding to the target code line, the code range (BS, BE) corresponding to the target level, the code range (CS, CE) corresponding to the parent level of the target level, and the list of all target sub-level code ranges {(DS1, DE1), (DS2, DE2), ..., (DS m ,DE m ),...,(DS M ,DS M )},(DS m ,DE m ) is the mth sub-level code range in (BS, BE), the value of m ranges from 1 to M, and M is the total number of sub-level code ranges in (BS, BE).
[0014] The target code line is the code line currently selected by the user. The target level is the B level corresponding to the target code line in the code line hierarchy information of the code file. n .
[0015] Step S3: Get the current visible code range (VS, VE), initially set the display identifier of each code line to the default identifier, update the display identifier of the code line belonging to (BS, BE) in (VS, VE) to the first display identifier, update the display identifier of the code line belonging to (CS, CE) in (VS, VE) to the second display identifier, and update the display identifier of the code line belonging to {(DS1, DE1), (DS2, DE2), ..., (DS m ,DE m ),...,(DS M ,DS M )}The code line display indicator is updated to the third display indicator.
[0016] As an embodiment, the default logo, the first display logo, the second display logo, and the third display logo are represented by different colors. As another embodiment, the default logo, the first display logo, the second display logo, and the third display logo are represented by different shapes. It should be noted that the default logo, the first display logo, the second display logo, and the third display logo are not limited to the two examples above, and other implementations that can clearly distinguish the default logo, the first display logo, the second display logo, and the third display logo are also applicable here.
[0017] It should be noted that when the target code line changes, step S2 and step S3 are executed again based on the new target code line. When the current visible code range changes, step S3 is executed again based on the new current visible code range.
[0018] As an embodiment, step S1 includes: Step S11, set n=1, initial code line number A0=0, initial level B0=0.
[0019] Step S12: parse the nth line of code in the code file using lexical parsing, and set A n =A n-1 +1, if the nth line of code contains progressive information, set B n =B n-1 +1, if the nth line of code contains exit information, then set B n =B n-1 -1, otherwise, set B n =B n-1 .
[0020] Among them, the progressive information is the information for entering the next code level, and the exit information is the information for exiting the current level. The progressive information and exit information corresponding to different code languages may be different.
[0021] It should be noted that all existing lexical analysis methods fall within the protection scope of the present invention, and will not be elaborated here.
[0022] Step S13: If n < N, set n = n + 1, and return to execute Step S12; if n = N, generate {(A1, B1), (A2, B2),..., (A n , B n ),...,(A N , B N )}.
[0023] It can be understood that by performing Steps S11 - S13, analyzing the code line by line, the hierarchical structure information of each code line is obtained, thereby generating the hierarchical structure information of the code lines of the code file.
[0024] As an embodiment, Step S2 includes: Step S21: Obtain the line number target A of the target code line n .
[0025] It should be noted that specifically, methods such as mouse selection and shortcut key locking can be used to select the line number of the target code line.
[0026] Step S22: Determine the target level target B corresponding to target A n based on the hierarchical structure information of the code lines of the code file n .
[0027] It can be understood that since the hierarchical structure information of the code lines of the code file records the level corresponding to each code line number, the target B corresponding to target A can be directly determined based on the hierarchical structure information of the code lines of the code file. n n .
[0028] Step S23: Starting from the target (A n , B n ), traverse the hierarchical structure of the code lines of the code file to the left, and determine the first A n that satisfies that the current B n is equal to the target B n n and the next B n is equal to the target B n n minus 1 as BS. Starting from the target (A n , B n ), traverse the hierarchical structure of the code lines of the code file to the right, and determine the first A n that satisfies that the current B n is equal to the target Bn And next B n Equal to target B n -1 A n Determine it as BE and generate the code range (BS, BE) corresponding to the target level.
[0029] Step S24: From target B n The corresponding minimum A n Start traversing the code line hierarchy of the code file to the left and find the first one that meets the current B n Equal to target B n -1 and next B n Equal to target B n -2 or empty A n Determined as CS, from target B n The corresponding maximum A n Start traversing the code line hierarchy of the code file to the right and find the first one that meets the current B n Equal to target B n -1 and next B n Equal to target B n -2 or empty A n Determine it as CE and generate the code range (CS, CE) corresponding to the parent level of the target level.
[0030] Step S25: traverse the code line hierarchy of the code file from BS to the right until BE, and find the mth code line that meets the current B n Equal to target B n +1 and previous B n Equal to target B n A n Determined to be DS m , the mth one that satisfies the current B n Equal to target B n +1 and next B n Equal to target B n A n Determined to be DE m , generate {(DS1,DE1),(DS2,DE2),...,(DS m ,DE m ),...,(DS M ,DS M )}.
[0031] It should be noted that when viewing the source code, it is usually necessary to view the adjacent hierarchical relationships with "parent-child" relationships. Through steps S21-S24, the code range (BS, BE) corresponding to the target level, the code range (CS, CE) corresponding to the parent level of the target level, and the code ranges of all target sub-levels are quickly and accurately determined.
[0032] After intuitively displaying the code range (BS, BE) corresponding to the target level within the visible range, the code range (CS, CE) corresponding to the parent level of the target level, and the code ranges of all target sublevels through steps S1 to S3, it is possible to further implement rapid jumps between "parent-child" relationship levels. This is illustrated below with several specific embodiments: Example 1 The step S3 may further include: Step S4: lock the current target line, and jump to the BS-th code line based on the preset first trigger module or jump to the BE-th code line based on the preset second trigger module.
[0033] Among them, the first trigger module and the second trigger module can be specifically different shortcut keys, or different buttons set on the display interface. By operating the corresponding shortcut keys or buttons, the starting row or ending row of the target level can be quickly and accurately positioned directly.
[0034] Example 2 The step S3 may further include: Step C4: lock the current target row, and jump to the CS-th code row based on the preset third trigger module or jump to the CE-th code row based on the preset fourth trigger module.
[0035] Among them, the third trigger module and the fourth trigger module can be specifically different shortcut keys, or different buttons set on the display interface. By operating the corresponding shortcut keys or buttons, the starting row or ending row of the parent level of the target level can be quickly and accurately positioned directly.
[0036] Example 3: After step S3, the following steps are also included: Step D4: Select the sub-level code type you want to focus on based on the preset display interface. The code types include module, function, loop body, conditional body, and statement block.
[0037] Specifically, a sub-level code type selection interface can be set on the preset display interface in the form of a floating window, pop-up window, etc. The user can select one or more code types according to application requirements, thereby filtering out sub-levels corresponding to code types that do not need to be concerned about.
[0038] Step D5: Present the first line of code corresponding to the target sub-level of the currently selected type of attention in the preset display interface.
[0039] It should be noted that in order to further improve the efficiency of users in selecting the sub-level to be jumped to, the first line of code corresponding to the target sub-level of the selected type to be focused on is displayed through step D5. Users can quickly and accurately select the sub-level to be jumped to by executing step D6 based on the first line of code corresponding to the target sub-level.
[0040] Step D6: Select the sub-level to be jumped to based on the first line of code corresponding to the target sub-level of the type currently selected and presented in the preset display interface.
[0041] Step D7: Jump to the DS corresponding to the sub-level to be jumped based on the selected sub-level to be jumped m or DE m .
[0042] Through steps D4 and D5, it is possible to quickly and accurately jump to the start row or end row of the target sub-level that the user needs to focus on.
[0043] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this invention pertains. The terms used herein in the specification of the present invention are for the purpose of describing specific embodiments only and are not intended to limit the present invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0044] It should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the steps as sequential processes, many of the steps can be performed in parallel, concurrently, or simultaneously. In addition, the order of the steps can be rearranged. A process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. A process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0045] The present invention first obtains the code line hierarchy information of the code file, and then determines the target level corresponding to the target code line, the code range corresponding to the target level, and all target sub-level code ranges based on the code line hierarchy information of the code file, and then displays the code lines belonging to the target level, the code range corresponding to the target level, and the target sub-level code range in the code lines within the visible range using different display identifiers, thereby realizing the rapid and accurate positioning of the code level that the user is concerned about.
[0046] An embodiment of the present invention also provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executed by the at least one processor, and the instructions are configured to execute the method described in the embodiment of the present invention.
[0047] An embodiment of the present invention further provides a computer-readable storage medium storing computer-executable instructions, wherein the computer instructions are used to execute the method described in the embodiment of the present invention.
[0048] An embodiment of the present invention first obtains the code line hierarchy information of the code file, and then determines the target level corresponding to the target code line, the code range corresponding to the target level, and all target sub-level code ranges based on the code line hierarchy information of the code file, and then displays the code lines in the visible range that belong to the target level, the code range corresponding to the target level, and the target sub-level code range using different display identifiers, thereby realizing the rapid and accurate positioning of the code level that the user is concerned about.
[0049] The above description is merely a preferred embodiment of the present invention and does not constitute any form of limitation to the present invention. Although the present invention has been disclosed as a preferred embodiment, it is not intended to limit the present invention. Any technician familiar with the present profession can make slight changes or modifications to equivalent embodiments using the technical contents disclosed above without departing from the scope of the technical solution of the present invention. However, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention are still within the scope of the technical solution of the present invention.
Claims
1. A source code level positioning method, characterized in that: include: Step S1, obtain the code line hierarchy information of the code file {(A1, B1), (A2, B2), ..., (A n ,B n ),...,(A N ,B N )},A n is the nth line number of the code file, B n The level corresponding to the nth line of code in the code file, where n ranges from 1 to N, and N is the total number of code line levels in the code file; Step S2: Based on the code line hierarchy information of the code file, determine the target level corresponding to the target code line, the code range (BS, BE) corresponding to the target level, the code range (CS, CE) corresponding to the parent level of the target level, and the list of all target sub-level code ranges {(DS1, DE1), (DS2, DE2), ..., (DS m ,DE m ),...,(DS M ,DS M )},(DS m ,DE m ) is the mth sub-level code range in (BS, BE), the value of m ranges from 1 to M, and M is the total number of sub-level code ranges in (BS, BE); Step S3: Get the current visible code range (VS, VE), initially set the display identifier of each code line to the default identifier, update the display identifier of the code line belonging to (BS, BE) in (VS, VE) to the first display identifier, update the display identifier of the code line belonging to (CS, CE) in (VS, VE) to the second display identifier, and update the display identifier of the code line belonging to {(DS1, DE1), (DS2, DE2), ..., (DS m ,DE m ),...,(DS M ,DS M )}The code line display indicator is updated to the third display indicator.
2. The method according to claim 1, characterized in that The step S1 comprises: Step S11, set n=1, initial code line number A0=0, initial level B0=0; Step S12: parse the nth line of code in the code file using lexical parsing, and set A n =A n-1 +1, if the nth line of code contains progressive information, set B n =B n-1 +1, if the nth line of code contains exit information, then set B n =B n-1 -1, otherwise, set B n =B n-1 ; Step S13: If n < N, set n = n + 1 and return to execute Step S12. If n = N, generate {(A1, B1), (A2, B2),..., (A n , B n ),...,(A N , B N )}.
3. The method according to claim 1, characterized in that The step S2 comprises: Step S21, obtain the target code line number target A n ; Step S22: Determine target A based on the code line hierarchy information of the code file. n Corresponding target level target B n ; Step S23: From the target (A n ,B n ) starts to traverse the code line hierarchy of the code file to the left, and takes the first one that meets the current B n Equal to target B n And next B n Equal to target B n -1 A n Determined as BS, from the target (A n ,B n ) starts to traverse the code line hierarchy of the code file to the right and finds the first one that meets the current B n Equal to target B n And next B n Equal to target B n -1 A n Determine it as BE and generate the code range (BS, BE) corresponding to the target level; Step S24: From target B n The corresponding minimum A n Start traversing the code line hierarchy of the code file to the left and find the first one that meets the current B n Equal to target B n -1 and next B n Equal to target B n -2 or empty A n Determined as CS, from target B n The corresponding maximum A n Start traversing the code line hierarchy of the code file to the right and find the first one that meets the current B n Equal to target B n -1 and next B n Equal to target B n -2 or empty A n Determine it as CE and generate the code range (CS, CE) corresponding to the parent level of the target level; Step S25: traverse the code line hierarchy of the code file from BS to the right until BE, and find the mth code line that meets the current B n Equal to target B n +1 and previous B n Equal to target B n A n Determined to be DS m , the mth one that satisfies the current B n Equal to target B n +1 and next B n Equal to target B n A n Determined to be DE m , generate {(DS1,DE1),(DS2,DE2),...,(DS m ,DE m ),...,(DS M ,DS M )}.
4. The method according to claim 1, wherein After step S3, the following steps are also included: Step S4: lock the current target line, and jump to the BS-th code line based on the preset first trigger module or jump to the BE-th code line based on the preset second trigger module.
5. The method according to claim 1, wherein After step S3, the following steps are also included: Step C4: lock the current target row, and jump to the CS-th code row based on the preset third trigger module or jump to the CE-th code row based on the preset fourth trigger module.
6. The method according to claim 1, characterized in that After step S3, the following steps are also included: Step D4: Select the sub-level code type you want to focus on based on the preset display interface. The code types include modules, functions, loop bodies, conditional bodies, and statement blocks. Step D5: presenting the first line of code corresponding to the target sub-level of the currently selected type of attention in the preset display interface; Step D6: Select the sub-level to be jumped to based on the first line of code corresponding to the target sub-level of the type currently selected and presented in the preset display interface; Step D7: Jump to the DS corresponding to the sub-level to be jumped based on the selected sub-level to be jumped m or DE m .
7. The method according to claim 1, characterized in that The default identifier, the first display identifier, the second display identifier and the third display identifier are represented by different colors.
8. The method according to claim 1, characterized in that The default logo, the first display logo, the second display logo and the third display logo are represented by different shapes.
9. An electronic device, characterized in that: include: at least one processor; and, a memory communicatively coupled to the at least one processor; The memory stores instructions to be executed by the at least one processor, wherein the instructions are configured to execute the method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that The computer-executable instructions are stored, and the computer-executable instructions are used to execute the method according to any one of the preceding claims 1 to 8.
Citation Information
Patent Citations
Code table hierarchical display method and device, equipment, storage medium and product
CN116186245A
Data flow diagram generation method and device, equipment, storage medium and program product
CN119938048A
Annotated Method For Computer Code Mapping and Visualization
US20220004367A1
Processor-implemented systems and methods for synthesized document clustering
US20220179883A1
Cited By
Historical operation information processing method, electronic equipment and medium
CN121351729A
Historical operation information processing method, electronic device, and medium
CN121351729B