CN116303013A - Source code analysis method, device, electronic equipment and storage medium - Google Patents
Source code analysis method, device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN116303013A CN116303013A CN202310252938.1A CN202310252938A CN116303013A CN 116303013 A CN116303013 A CN 116303013A CN 202310252938 A CN202310252938 A CN 202310252938A CN 116303013 A CN116303013 A CN 116303013A
- Authority
- CN
- China
- Prior art keywords
- function
- source code
- function call
- target
- code
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000004458 analytical method Methods 0.000 title claims abstract description 139
- 238000000034 method Methods 0.000 claims abstract description 31
- 230000006870 function Effects 0.000 claims description 380
- 238000004590 computer program Methods 0.000 claims description 16
- 238000004891 communication Methods 0.000 description 8
- 238000012545 processing Methods 0.000 description 7
- 238000012360 testing method Methods 0.000 description 6
- 238000010586 diagram Methods 0.000 description 5
- 230000000007 visual effect Effects 0.000 description 5
- 230000008569 process Effects 0.000 description 4
- 230000001419 dependent effect Effects 0.000 description 3
- 239000003607 modifier Substances 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012546 transfer Methods 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008901 benefit Effects 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000007667 floating Methods 0.000 description 1
- 239000011521 glass Substances 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 230000001953 sensory effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3604—Software analysis for verifying properties of programs
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
The embodiment of the invention discloses a source code analysis method, a source code analysis device, electronic equipment and a storage medium. The method comprises the following steps: responding to a source code analysis request aiming at a target item, and determining a target source code file corresponding to the source code analysis request; carrying out grammar analysis on the target source code file to obtain a first function list in the target source code file, wherein the first function list comprises function information to be analyzed; determining a function code block corresponding to function information to be analyzed in a target source code file, and determining a function call code row in the function code block, wherein the function call code row defines first function call information; the first function call information is used as target function call information, a function call chain corresponding to the source code analysis request is generated based on the target function call information, and the function call chain is displayed, so that the source code can be more accurately and rapidly visually analyzed, the cost of the source code analysis is reduced, and the accuracy of the source code analysis is improved.
Description
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for analyzing source codes, an electronic device, and a storage medium.
Background
For analysis of project source codes, in related technologies, professional technicians often rely on manual analysis, and the problem of high manual success exists. If the code quantity of the source codes is more or the logic of the source codes is more complex, the analysis is performed manually, and the analysis omission phenomenon usually occurs in the analysis, so that the accuracy of the analysis of the source codes is reduced.
Disclosure of Invention
In view of the above problems, the invention provides a method, a device, an electronic device and a storage medium for analyzing source codes, so as to realize more accurate and rapid visual analysis of the source codes, reduce the cost of source code analysis and improve the accuracy of source code analysis.
According to an aspect of the present invention, there is provided a source code analysis method, including:
responding to a source code analysis request aiming at a target item, and determining a target source code file corresponding to the source code analysis request;
carrying out grammar analysis on the target source code file to obtain a first function list in the target source code file, wherein the first function list comprises function information to be analyzed;
determining a function code block corresponding to the function information to be analyzed in the target source code file, and determining a function call code row in the function code block, wherein the function call code row is defined with first function call information;
And taking the first function call information as target function call information, generating a function call chain corresponding to the source code analysis request based on the target function call information, and displaying the function call chain.
According to another aspect of the present invention, there is provided a source code analysis apparatus. The device comprises:
the source code file acquisition module is used for responding to a source code analysis request aiming at a target item and determining a target source code file corresponding to the source code analysis request;
the source code file analysis module is used for carrying out grammar analysis on the target source code file to obtain a first function list in the target source code file, wherein the first function list comprises function information to be analyzed;
the call information determining module is used for determining a function code block corresponding to the function information to be analyzed in the target source code file and determining a function call code row in the function code block, wherein the function call code row is defined with first function call information;
and the call chain generation module is used for taking the first function call information as target function call information, generating a function call chain corresponding to the source code analysis request based on the target function call information, and displaying the function call chain.
According to another aspect of the present invention, there is provided an electronic apparatus including:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,,
the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform any one of the source code analysis methods of the present invention.
According to another aspect of the present invention, there is provided a computer readable storage medium storing computer instructions for causing a processor to implement any of the source code analysis methods of the present invention when executed.
According to the technical scheme, a target source code file corresponding to a source code analysis request is determined by receiving the source code analysis request aiming at a target item; and carrying out grammar analysis on the target source code file to obtain a first function list in the target source code file, wherein the first function list comprises function information to be analyzed. And determining a function code block corresponding to the function information to be analyzed in the target source code file, and determining a function call code row in the function code block, wherein the function call code row is defined with first function call information. And taking the first function call information as target function call information, generating a function call chain corresponding to the source code analysis request based on the target function call information, and displaying the function call chain. According to the technical scheme, the visual analysis of the source codes is realized more accurately and rapidly, the cost of the source code analysis is reduced, and the accuracy of the source code analysis is improved.
It should be understood that the description in this section is not intended to identify key or critical features of the embodiments of the invention or to delineate the scope of the invention. Other features of the present invention will become apparent from the description that follows.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a source code analysis method according to a first embodiment of the present invention;
FIG. 2 is a flow chart of a source code analysis method according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a source code analysis device according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention.
Detailed Description
In order that those skilled in the art will better understand the present invention, a technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in which it is apparent that the described embodiments are only some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present invention without making any inventive effort, shall fall within the scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present invention and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the invention described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Example 1
Fig. 1 is a flow chart of a source code analysis method according to an embodiment of the present invention, where the method may be applied to a case of analyzing source codes, and the method may be performed by a source code analysis device, where the source code analysis device may be implemented in hardware and/or software, and the source code analysis device may be configured in an electronic device such as a computer or a server.
As shown in fig. 1, the method of the present embodiment includes:
s110, responding to a source code analysis request aiming at a target item, and determining a target source code file corresponding to the source code analysis request.
The target item may be understood as a software item requiring source code analysis. The source code analysis request may be understood as a request for analyzing the source code of a software item. The source code analysis request is obtained by receiving a source code analysis instruction input by a user, and generating a source code analysis request based on the source code analysis instruction. The source code analysis instruction may be a section of instruction code for analyzing source code. Request parameters of the source code analysis request may include, but are not limited to, item identification and business information. The item identification may include an item code, an item name, and an item version number. The target source code file can be understood as a source code file which is required to be subjected to source code analysis and meets the source code analysis request. Alternatively, the source code file may be a JAVA source code file.
In an embodiment of the invention, a source code analysis request for a target item is received. After the source code analysis request is received, determining a target source code file corresponding to the source code analysis request based on the source code analysis request. Optionally, the determining the target source code file corresponding to the source code analysis request may include: acquiring a plurality of project source code files of the target project; and matching the item source code file corresponding to the source code analysis request in the item source code file, and taking the matched item source code file as a target source code file.
Specifically, after receiving a source code analysis request for a target item, a plurality of item source code files of the target item may be obtained. And then the project source code files matched with the source code analysis request are matched from the project source code files. And after successfully matching the project source code file corresponding to the source code analysis request, taking the matched project source code file as a target source code file.
On the basis of the embodiment, after the item source code file corresponding to the source code analysis request is not successfully matched, prompt information of the item source code file not matched with the source code analysis request can be generated.
Optionally, the matching the item source code file matched with the source code analysis request from the plurality of item source code files may include parsing the source code analysis request. So that request parameters in the source code analysis request can be determined. And then, selecting the project source code file corresponding to the request parameter from a plurality of project source code files based on the request parameter.
S120, carrying out grammar analysis on the target source code file to obtain a first function list in the target source code file, wherein the first function list comprises function information to be analyzed.
The first function list may be understood as a function list obtained by performing syntax analysis on the target source code file. The first function list may include function information to be analyzed. The function information to be analyzed can be understood as function information to be analyzed in the first function list. The function information to be analyzed can include a function modifier, a function name, a function annotation, a function entry list, a function exit type, and a function logic code block.
In the embodiment of the present invention, the parsing the target source code file to obtain the first function list in the target source code file may include: and carrying out grammar analysis on the target source code file so as to determine class code blocks or interface code blocks in the target source code file. Further, the code in the class code block or the interface code block may be parsed, so that the function code block in the class code block or the interface code block may be determined. And further based on the function information that may be based on the function code blocks.
Wherein a class code block may be understood as a code segment of a class defined in a target source code file. An interface code block may be understood as a code segment of an interface defined in a target source code file. The function code blocks may be concatenated into code segments of functions defined in class code blocks or interface code blocks. The function information in the function code block may include a function modifier, a function name, a function annotation, a function entry list, a function exit type, and a function logic code block.
On the basis of the embodiment, after the code in the class code block is parsed, class attribute information of a class corresponding to the class code block can be obtained. Wherein the attribute information includes a class modifier, a class name, a class type, a class annotation, and a class annotation.
S130, determining a function code block corresponding to the function information to be analyzed in the target source code file, and determining a function call code row in the function code block, wherein the function call code row is defined with first function call information.
The function code block can be understood as a function code block corresponding to the function information to be analyzed in the target source code file. Function call code may be understood as code in a block of function code for making a function call. The number of function call code lines in a function code block may be one, two or more. The first function call information may be understood as function call information of a function call row in a function code block in the target source code file. Alternatively, the first function call information may be a function call code statement.
Specifically, after the function information to be analyzed is obtained, the function code block corresponding to the function information to be analyzed in the target source code file can be determined according to the corresponding relation between the function information to be analyzed and the function code block. After determining the function code block corresponding to the function information to be analyzed, the code information of each row of code lines in the function code block can be analyzed. So that the line of function call code in the function code block can be determined. Further, a function call code statement defined by the function call code line may be determined, that is, first function call information defined by the function call code line may be determined.
In an embodiment of the present invention, the determining a function call code line in the function code block may include: performing logic grammar analysis on code sentences in the function code blocks so as to determine a first preset logic code row and/or a preset logic sub-code block in the function code blocks, wherein the preset logic sub-code block can comprise a second preset logic code row; and under the condition that the first preset logic code row and/or the second preset logic code row define function call information, the first preset logic code row and/or the second preset logic code row can be used as the function call code row.
The first preset logic code line may be understood as a code line corresponding to a predefined logic statement in the function code block. The preset logic subcode block can be understood as a subcode segment corresponding to a predefined logic code in the function code block. Optionally, the preset logical sub-code blocks may include at least one of a select logical code block, a loop logical code block, an exception capture code block, and a return execution code block. Illustratively, the selection logic code block may include at least one of an if code block, a while code block, and a switch code block. The loop logic code blocks may include while code blocks and/or for code blocks. The exception capture code block may be a try code block. The return execution code block may be a return code block.
Wherein the predetermined logic subcode block may comprise a second predetermined logic code line. The second preset logic code line can be understood as a code line corresponding to a predefined logic statement in the preset logic sub-code block. The number of second preset logic code lines in the preset logic sub-code block may be one, two or more. In practical applications, the number of second preset logic code lines in the preset logic sub-code block is usually plural.
S140, taking the first function call information as target function call information, generating a function call chain corresponding to the source code analysis request based on the target function call information, and displaying the function call chain.
The target function call information can be understood as function call information meeting the source code analysis request in the target item. The function call chain may be an inter-function call relationship chain generated based on the target function call information.
Specifically, after the first function call information is obtained, the first function call information may be used as target function call information. And generating a function call chain according to the target function call information and the sequence call relationship among functions, and obtaining the function call chain corresponding to the source code analysis request. After the function call chain is obtained, the function call chain can be displayed in a preset display mode. The preset display mode can be set according to actual requirements, and is not particularly limited herein.
Illustratively, performing logic grammar analysis on code sentences in the function code blocks so as to determine a first preset logic code row and a preset logic sub-code block in the function code blocks, wherein the preset logic sub-code block can comprise a second preset logic code row; after determining the first preset logical code line and the second preset logical code line, all logical code lines in the function code block may be determined. For each row of logical code, the logical code row definition logic statement may be analyzed to determine whether the logical code row defines function call information. If yes, the function call information defined by the logic code row can be obtained. After the analysis of all the logic code lines is completed, all the function call information can be obtained, and the target function call information is obtained.
In the embodiment of the invention, after the target function call information is obtained, the called function corresponding to the source code analysis request can be determined based on the target function call information. Further, the function name of the called function is obtained. In practical applications, the number of function names obtained is typically a plurality. Then, after a plurality of function names are acquired, each function name may be stored.
Optionally, after obtaining multiple function names, each function name may be spliced to obtain a spliced function name. And transferring the spliced function names serving as actual parameters to form parameters of a predefined function name storage method for storing the function names. After the parameter transfer is finished, the function name storage method can be executed to store and process each function name.
On the basis of the above embodiment, after the spliced function name is obtained, the spliced function name may be further subjected to encoding processing in a preset encoding manner. Optionally, the preset coding mode may be a Base64 coding mode.
On the basis of the foregoing embodiment, after parsing the target source code file, the method may further include: and obtaining annotation information and/or annotation information in the target source file, and storing the annotation information and/or the annotation information in a preset storage mode. The preset storage mode may be stored according to actual requirements, and is not limited herein, for example, a key value pair form.
In one embodiment, the target source code file is parsed to obtain annotation information in the target source code file. The annotation information may include at least one of line annotation information, block annotation information, doc (document) annotation information. In the embodiment of the invention, doc annotation information can be stored in a key-value mode.
In one embodiment, the target source code file is parsed to obtain annotation information in the target source code file. The annotation information may include attribute annotation information. The storage mode of the attribute annotation information can be a key-value storage mode.
On the basis of the embodiment, after the target source code file is parsed, the package information in the target source code file can be determined, wherein the package information further comprises dependent package information and membership package information. Therefore, the dependent file of the target source file can be determined according to the dependent package information, and the membership file of the target source code file can be determined according to the membership package information. The package information can describe the dependency file information and the membership file information of the target source code file so as to determine the dependency file and the membership file of the target source code file, and the benefit of the package information is that the code execution logic can be ensured.
According to the technical scheme, a target source code file corresponding to a source code analysis request is determined by receiving the source code analysis request aiming at a target item; and carrying out grammar analysis on the target source code file to obtain a first function list in the target source code file, wherein the first function list comprises function information to be analyzed. And determining a function code block corresponding to the function information to be analyzed in the target source code file, and determining a function call code row in the function code block, wherein the function call code row is defined with first function call information. And taking the first function call information as target function call information, generating a function call chain corresponding to the source code analysis request based on the target function call information, and displaying the function call chain. According to the technical scheme, the visual analysis of the source codes is realized more accurately and rapidly, the cost of the source code analysis is reduced, and the accuracy of the source code analysis is improved.
Example two
Fig. 2 is a flow chart of a source code analysis method according to a second embodiment of the present invention, where, on the basis of the foregoing embodiment, optionally, the first function call information includes a first function parameter type; the step of taking the first function call information as target function call information comprises the following steps: under the condition that the first function parameter type is not the basic parameter type, matching the item source code file corresponding to the first function parameter type in each item source code file to be used as an associated source code file associated with the target source code file; carrying out grammar analysis on the associated source code file to obtain a second function list in the associated source code file, and determining second function call information corresponding to the associated source code file based on the second function list, wherein the second function call information comprises a second function parameter type; and generating target function call information based on the first function call information and the second function call information under the condition that the second function parameter type is a basic parameter type. Wherein, the technical terms identical to or corresponding to the above embodiments are not repeated herein.
As shown in fig. 2, the method in this embodiment specifically includes:
s210, responding to a source code analysis request for a target item, acquiring a plurality of item source code files of the target item, matching the item source code files corresponding to the source code analysis request in the item source code files, and taking the matched item source code files as target source code files.
S220, carrying out grammar analysis on the target source code file to obtain a first function list in the target source code file, wherein the first function list comprises function information to be analyzed.
S230, determining a function code block corresponding to the function information to be analyzed in the target source code file, and determining a function call code row in the function code block, wherein the function call code row is defined with first function call information, and the first function call information comprises a first function parameter type.
The first function parameter type may be understood as a parameter type of a function corresponding to a function code block in the target source code file. Optionally, the first function parameter type may include a function entry parameter type and/or a function return parameter type. An entry parameter type may be understood as a parameter type of a formal parameter of a function. The function return parameter type may be understood as a parameter type of a return parameter of the function.
And S240, matching the item source code file corresponding to the first function parameter type in each item source code file as an associated source code file associated with the target source code file under the condition that the first function parameter type is not the basic parameter type.
The basic parameter types can include integer type, character string type, floating point type and Boolean type. The associated source code file may be understood as an item source code file matched with the first function parameter type in each item source code file.
In the embodiment of the present invention, matching the item source code file corresponding to the first function parameter type in each item source code file, as the associated source code file associated with the target source code file, may include: and determining predefined classes in each item source code file. And further, according to the corresponding relation between the first function parameter type and the predefined class, the predefined class corresponding to the first function parameter type can be determined. Therefore, the project source code file which corresponds to the first function parameter type and to which the predefined class belongs can be used as the associated source code file associated with the target source code file.
S250, carrying out grammar analysis on the associated source code file to obtain a second function list in the associated source code file, and determining second function call information corresponding to the associated source code file based on the second function list, wherein the second function call information comprises a second function parameter type.
The second function list may be a function list obtained by performing syntax analysis on the associated source code file. The second function call information may be understood as a call relation between functions in the associated source code file. The second function call information may include a second function parameter type. The second function parameter type may be understood as a parameter type of a function in the associated source code file.
In the embodiment of the invention, the second function list includes function information to be analyzed. The function information to be analyzed in the second function list can be understood as information of functions needing to be analyzed in the associated source code file. The determining, based on the second function list, second function call information corresponding to the associated source code file may include: and determining function code blocks corresponding to the function information to be analyzed in the second function list in the associated source code file. And further the code information of the code lines in the function code block can be analyzed. So that a line of function call code in the function code block can be determined. Further, a function call code statement defined by the function call code line may be determined, that is, second function call information defined by the function call code line may be determined. After the second function call information is obtained, the second function call information may be analyzed, so that a second function parameter type in the second function call information may be determined.
And S260, generating target function call information based on the first function call information and the second function call information under the condition that the second function parameter type is the basic parameter type.
Specifically, in the case that the second function parameter type is the basic parameter type, the first function call information and the second function call information may be processed according to execution logic between functions. Therefore, the target function call information can be generated, and the function call relation in the plurality of item source code files can be determined more accurately and rapidly.
In the embodiment of the invention, the calling relation between functions and the parameter transfer between the specific functions can be obtained by analyzing the source codes, so that the test case aiming at the target item can be obtained more quickly later, and the test workload is reduced. On the basis, during regression testing, data backtracking can be automatically carried out according to the collected data set, and consistency of test data is ensured. When the test cases are compared, different points of two tests can be displayed for different cases of the same service, so that the problem can be conveniently searched.
S270, generating a function call chain corresponding to the source code analysis request based on the target function call information, and displaying the function call chain.
According to the technical scheme provided by the embodiment of the invention, the first function call information comprises a first function parameter type; under the condition that the first function parameter type is not the basic parameter type, matching the item source code file corresponding to the first function parameter type in each item source code file to be used as an associated source code file associated with the target source code file; carrying out grammar analysis on the associated source code file to obtain a second function list in the associated source code file, and determining second function call information corresponding to the associated source code file based on the second function list, wherein the second function call information comprises a second function parameter type; and generating target function call information based on the first function call information and the second function call information under the condition that the second function parameter type is the basic parameter type, so that the function call relation in a plurality of item source code files can be more accurately and rapidly determined.
Example III
Fig. 3 is a schematic structural diagram of a source code analysis device according to a third embodiment of the present invention. As shown in fig. 3, the apparatus includes: the system comprises a source code file acquisition module 310, a source code file analysis module 320, a call information determination module 330 and a call chain generation module 340.
The source code file obtaining module 310 is configured to determine a target source code file corresponding to a source code analysis request for a target item in response to the source code analysis request;
the source code file analysis module 320 is configured to parse the target source code file to obtain a first function list in the target source code file, where the first function list includes function information to be analyzed;
a call information determining module 330, configured to determine a function code block corresponding to the function information to be analyzed in the target source code file, and determine a function call code line in the function code block, where the function call code line defines first function call information;
the call chain generating module 340 is configured to use the first function call information as target function call information, generate a function call chain corresponding to the source code analysis request based on the target function call information, and display the function call chain.
According to the technical scheme, a target source code file corresponding to a source code analysis request is determined by receiving the source code analysis request aiming at a target item; and carrying out grammar analysis on the target source code file to obtain a first function list in the target source code file, wherein the first function list comprises function information to be analyzed. And determining a function code block corresponding to the function information to be analyzed in the target source code file, and determining a function call code row in the function code block, wherein the function call code row is defined with first function call information. And taking the first function call information as target function call information, generating a function call chain corresponding to the source code analysis request based on the target function call information, and displaying the function call chain. According to the technical scheme, the visual analysis of the source codes is realized more accurately and rapidly, the cost of the source code analysis is reduced, and the accuracy of the source code analysis is improved.
Optionally, the source code file obtaining module 310 is specifically configured to:
acquiring a plurality of project source code files of the target project;
and matching the item source code file corresponding to the source code analysis request in the item source code file, and taking the matched item source code file as a target source code file.
Optionally, the first function call information includes a first function parameter type; a call chain generation module 340 for:
under the condition that the first function parameter type is not the basic parameter type, matching the item source code file corresponding to the first function parameter type in each item source code file to be used as an associated source code file associated with the target source code file;
carrying out grammar analysis on the associated source code file to obtain a second function list in the associated source code file, and determining second function call information corresponding to the associated source code file based on the second function list, wherein the second function call information comprises a second function parameter type;
and generating target function call information based on the first function call information and the second function call information under the condition that the second function parameter type is a basic parameter type.
Optionally, the first function parameter type includes a function entry parameter type and/or a function return parameter type.
Optionally, the call information determining module 330 includes a call code line determining unit, which is configured to:
performing logic grammar analysis on code sentences in the function code blocks, and determining a first preset logic code row and/or a preset logic sub-code block in the function code blocks, wherein the preset logic sub-code block comprises a second preset logic code row;
and under the condition that the first preset logic code row and/or the second preset logic code row define function call information, taking the first preset logic code row and/or the second preset logic code row as a function call code row.
Optionally, the preset logical sub-code blocks include at least one of a select logical code block, a loop logical code block, an exception capture code block, and a return execution code block.
Optionally, the device further comprises an analysis information storage module, which is used for obtaining annotation information and/or annotation information in the target source file after the target source file is parsed, and storing the annotation information and/or the annotation information in a preset storage mode.
The source code analysis device provided by the embodiment of the invention can execute the source code analysis method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
It should be noted that, each unit and module included in the source code analysis device are only divided according to the functional logic, but not limited to the above division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for distinguishing from each other, and are not used to limit the protection scope of the embodiments of the present invention.
Example IV
Fig. 4 shows a schematic diagram of the structure of an electronic device 10 that may be used to implement an embodiment of the invention. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. Electronic equipment may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the inventions described and/or claimed herein.
As shown in fig. 4, the electronic device 10 includes at least one processor 11, and a memory, such as a Read Only Memory (ROM) 12, a Random Access Memory (RAM) 13, etc., communicatively connected to the at least one processor 11, in which the memory stores a computer program executable by the at least one processor, and the processor 11 may perform various appropriate actions and processes according to the computer program stored in the Read Only Memory (ROM) 12 or the computer program loaded from the storage unit 18 into the Random Access Memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 may also be stored. The processor 11, the ROM 12 and the RAM 13 are connected to each other via a bus 14. An input/output (I/O) interface 15 is also connected to bus 14.
Various components in the electronic device 10 are connected to the I/O interface 15, including: an input unit 16 such as a keyboard, a mouse, etc.; an output unit 17 such as various types of displays, speakers, and the like; a storage unit 18 such as a magnetic disk, an optical disk, or the like; and a communication unit 19 such as a network card, modem, wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
The processor 11 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various processors running machine learning model algorithms, digital Signal Processors (DSPs), and any suitable processor, controller, microcontroller, etc. The processor 11 performs the various methods and processes described above, such as the source code analysis method.
In some embodiments, the source code analysis method may be implemented as a computer program tangibly embodied on a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 10 via the ROM 12 and/or the communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the source code analysis method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the source code analysis method in any other suitable manner (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
A computer program for carrying out methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions/acts specified in the flowchart and/or block diagram block or blocks to be implemented. The computer program may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of the present invention, a computer-readable storage medium may be a tangible medium that can contain, or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, the computer readable storage medium may be a machine readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which a user can provide input to the electronic device. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), blockchain networks, and the internet.
The computing system may include clients and servers. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical hosts and VPS service are overcome.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps described in the present invention may be performed in parallel, sequentially, or in a different order, so long as the desired results of the technical solution of the present invention are achieved, and the present invention is not limited herein.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives are possible, depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.
Claims (10)
1. A method of source code analysis, comprising:
responding to a source code analysis request aiming at a target item, and determining a target source code file corresponding to the source code analysis request;
carrying out grammar analysis on the target source code file to obtain a first function list in the target source code file, wherein the first function list comprises function information to be analyzed;
determining a function code block corresponding to the function information to be analyzed in the target source code file, and determining a function call code row in the function code block, wherein the function call code row is defined with first function call information;
And taking the first function call information as target function call information, generating a function call chain corresponding to the source code analysis request based on the target function call information, and displaying the function call chain.
2. The method of claim 1, wherein the determining the target source code file corresponding to the source code analysis request comprises:
acquiring a plurality of project source code files of the target project;
and matching the item source code file corresponding to the source code analysis request in the item source code file, and taking the matched item source code file as a target source code file.
3. The method of claim 2, wherein the first function call information comprises a first function parameter type; the step of taking the first function call information as target function call information comprises the following steps:
under the condition that the first function parameter type is not the basic parameter type, matching the item source code file corresponding to the first function parameter type in each item source code file to be used as an associated source code file associated with the target source code file;
carrying out grammar analysis on the associated source code file to obtain a second function list in the associated source code file, and determining second function call information corresponding to the associated source code file based on the second function list, wherein the second function call information comprises a second function parameter type;
And generating target function call information based on the first function call information and the second function call information under the condition that the second function parameter type is a basic parameter type.
4. A method according to claim 3, characterized in that the first function parameter type comprises a function entry parameter type and/or a function return parameter type.
5. The method of claim 1, wherein the determining a line of function call code in the block of function code comprises:
performing logic grammar analysis on code sentences in the function code blocks, and determining a first preset logic code row and/or a preset logic sub-code block in the function code blocks, wherein the preset logic sub-code block comprises a second preset logic code row;
and under the condition that the first preset logic code row and/or the second preset logic code row define function call information, taking the first preset logic code row and/or the second preset logic code row as a function call code row.
6. The method of claim 5, wherein the pre-set logical sub-code blocks include at least one of a select logical code block, a loop logical code block, an exception capture code block, and a return execution code block.
7. The method of claim 1, wherein after parsing the target source code file, the method further comprises:
and obtaining annotation information and/or annotation information in the target source file, and storing the annotation information and/or the annotation information in a preset storage mode.
8. A source code analysis apparatus, comprising:
the source code file acquisition module is used for responding to a source code analysis request aiming at a target item and determining a target source code file corresponding to the source code analysis request;
the source code file analysis module is used for carrying out grammar analysis on the target source code file to obtain a first function list in the target source code file, wherein the first function list comprises function information to be analyzed;
the call information determining module is used for determining a function code block corresponding to the function information to be analyzed in the target source code file and determining a function call code row in the function code block, wherein the function call code row is defined with first function call information;
and the call chain generation module is used for taking the first function call information as target function call information, generating a function call chain corresponding to the source code analysis request based on the target function call information, and displaying the function call chain.
9. An electronic device, the electronic device comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,,
the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the source code analysis method of any one of claims 1-7.
10. A computer readable storage medium storing computer instructions for causing a processor to perform the source code analysis method of any one of claims 1-7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310252938.1A CN116303013A (en) | 2023-03-07 | 2023-03-07 | Source code analysis method, device, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310252938.1A CN116303013A (en) | 2023-03-07 | 2023-03-07 | Source code analysis method, device, electronic equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116303013A true CN116303013A (en) | 2023-06-23 |
Family
ID=86800933
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310252938.1A Pending CN116303013A (en) | 2023-03-07 | 2023-03-07 | Source code analysis method, device, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116303013A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117150996A (en) * | 2023-10-30 | 2023-12-01 | 北京云枢创新软件技术有限公司 | Method for determining problem source code generating burr signal, electronic equipment and medium |
CN118568004A (en) * | 2024-07-31 | 2024-08-30 | 荣耀终端有限公司 | File checking method, electronic device, storage medium and chip system |
-
2023
- 2023-03-07 CN CN202310252938.1A patent/CN116303013A/en active Pending
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117150996A (en) * | 2023-10-30 | 2023-12-01 | 北京云枢创新软件技术有限公司 | Method for determining problem source code generating burr signal, electronic equipment and medium |
CN117150996B (en) * | 2023-10-30 | 2024-01-19 | 北京云枢创新软件技术有限公司 | Method for determining problem source code generating burr signal, electronic equipment and medium |
CN118568004A (en) * | 2024-07-31 | 2024-08-30 | 荣耀终端有限公司 | File checking method, electronic device, storage medium and chip system |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN116303013A (en) | Source code analysis method, device, electronic equipment and storage medium | |
CN115576828A (en) | Test case generation method, device, equipment and storage medium | |
CN116881156A (en) | Automatic test method, device, equipment and storage medium | |
CN113641544B (en) | Method, apparatus, device, medium and product for detecting application state | |
CN117724980A (en) | Method and device for testing software framework performance, electronic equipment and storage medium | |
CN116401113B (en) | Environment verification method, device and medium for heterogeneous many-core architecture acceleration card | |
CN116126719A (en) | Interface testing method and device, electronic equipment and storage medium | |
CN116009847A (en) | Code generation method, device, electronic equipment and storage medium | |
CN115269431A (en) | Interface testing method and device, electronic equipment and storage medium | |
CN115576831A (en) | Test case recommendation method, device, equipment and storage medium | |
CN116955504B (en) | Data processing method and device, electronic equipment and storage medium | |
CN118170430B (en) | Method, device, equipment and storage medium for processing call link | |
CN117150215B (en) | Assessment result determining method and device, electronic equipment and storage medium | |
CN118133794B (en) | Table configuration method, apparatus, device and storage medium | |
CN117056222A (en) | Interface test file generation method and device, electronic equipment and storage medium | |
CN115567624A (en) | Message processing method and device, electronic equipment and medium | |
CN117609064A (en) | Unit test method and device, electronic equipment and storage medium | |
CN115374010A (en) | Function testing method, device, equipment and storage medium | |
CN117670236A (en) | Mobile-terminal-based to-be-handled flow approval method, device, equipment and medium | |
CN118626140A (en) | Software integration method, device, electronic equipment, storage medium and product | |
CN116450400A (en) | Application program abnormality analysis method and device, electronic equipment and storage medium | |
CN116126895A (en) | SQL-based data processing method, device, equipment and medium | |
CN117251167A (en) | Software bill of materials construction method, device, equipment and medium | |
CN115983222A (en) | EasyExcel-based file data reading method, device, equipment and medium | |
CN117251209A (en) | Method, device, equipment and medium for generating detailed setting model through code analysis |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |