Code inspection method, system and equipment and medium

By performing format checks and global variable redefinition checks on code files, the problem of redefinition during code file assembly in existing technologies is solved, ensuring the integrity and stability of the code package during compilation and linking.

CN121900767APending Publication Date: 2026-04-21CGN DIGITAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CGN DIGITAL TECH CO LTD
Filing Date
2025-12-26
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

In the prior art, when multiple code files are compiled and combined into a single executable program during the linking process, it is difficult to detect whether there are duplicated global variables, which can lead to errors in the compilation or linking stage and unpredictable runtime behavior.

Method used

A code inspection method is proposed, which includes format checking of each code file, identification of global variables, and generation of comprehensive inspection results for the code package, to ensure code standardization within the code file and consistency across files.

Benefits of technology

By performing format checks on each code file and checking for redefinition of global variables, we ensure that the code package is error-free during compilation and linking, thereby improving code quality and the stability of the executable program.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121900767A_ABST
    Figure CN121900767A_ABST
Patent Text Reader

Abstract

The invention provides a code checking method, system and device and a medium, and the checking method comprises the steps: obtaining a code package which comprises a plurality of code files; wherein all code files of the code package participate in compiling and are combined into a single executable program in the linking process; checking a code format in each code file to obtain a first checking result of each code file; identifying a global variable in each code file, and checking whether all the code files have repeatedly defined global variables or not to obtain a second check result; and generating a check result of the code package according to all the first check results and the second check results. According to the method, when the code files are checked, the code specification details in the single code file and the consistency between the cross-code files can be considered at the same time, and therefore the overall code quality is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software code technology, and in particular to a method, system, device, and medium for code inspection. Background Technology

[0002] In computer science, a code file is a collection of instructions and data written by programmers that can be recognized and executed by a computer. In C / C++, code files have specific naming and writing formats, header descriptions, block indentation requirements, variable and function naming and usage methods, and comment requirements. Well-structured code files can improve software development efficiency and reduce the incidence of code defects and bugs.

[0003] In existing technologies, manually inspecting code files is insufficient to simultaneously ensure both the detailed coding style within a single file and consistency across different files. This can lead to incomplete inspections and negatively impact overall code quality. For example, when multiple files within a code package are compiled and combined into a single executable during the final linking stage, the presence of duplicated global variables can cause serious compilation or linking errors and unpredictable runtime behavior. Therefore, improvements are needed. Summary of the Invention

[0004] This invention provides a method, system, device, and medium for checking code, in order to solve the technical problem in the prior art that when multiple code files are compiled and combined into a single executable program during the linking process, it is difficult to detect whether there are duplicated global variables.

[0005] This invention proposes a code inspection method, comprising:

[0006] Obtain a code package, which includes multiple code files; wherein all code files in the code package participate in compilation and are combined into a single executable program during the linking process;

[0007] The code format of each code file is checked to obtain the first check result for each code file;

[0008] Identify global variables in each of the code files, check if there are duplicate global variables in all code files, and obtain a second check result;

[0009] Based on all the results of the first and second checks, generate the check results for the code package.

[0010] In one embodiment of the present invention, the code format includes function format, identifier format, and syntax structure format; the step of checking the code format of each code file to obtain a first check result for each code file includes:

[0011] For each code file:

[0012] The identifier format is checked to obtain the identifier format check result;

[0013] The function format is checked to obtain the function format check result;

[0014] The syntax structure and format are checked to obtain the syntax structure and format check results;

[0015] When the function format check result, the identifier format check result, and the syntax structure format check result are all error-free, the first check result without error is obtained.

[0016] Otherwise, the first check result will be an error message.

[0017] In one embodiment of the present invention, the step of checking the identifier format to obtain the identifier format check result includes:

[0018] The identifier length is compared with the preset threshold length to obtain the length check result;

[0019] The characters of different identifiers are compared to obtain the character comparison check results;

[0020] Based on the length check result and the character comparison check result, the identifier format check result is obtained.

[0021] In one embodiment of the present invention, the step of checking the function format to obtain the function format check result includes:

[0022] The function parameter types are compared with the preset parameter types to obtain the function parameter check results;

[0023] Check if there is a blank line before the function header in the function definition, and check if there is a blank line after the function body in the function definition, to obtain the function definition check result;

[0024] The function checks for the existence of function header comments and obtains the comment check result; when function header comments exist, the keywords in the function header comments are compared with preset keywords to obtain the keyword comparison check result; based on the comment check result and the keyword comparison check result, the function header comment check result is obtained.

[0025] Based on the function header comment check results, the function parameter check results, and the function definition check results, the function format check results are obtained.

[0026] In one embodiment of the present invention, the step of checking its syntax structure format to obtain the syntax structure format check result includes:

[0027] Check if there are leading spaces in the top-level syntax structure to obtain the top-level syntax structure check results;

[0028] The pointer level is compared with the preset threshold level to obtain the pointer check result;

[0029] The nesting level of branching and looping statements is compared with the preset threshold level to obtain the branching and looping statement check results.

[0030] Based on the top-level syntax structure check results, the pointer check results, and the branch and loop statement check results, the syntax structure format check results are obtained.

[0031] In one embodiment of the present invention, the step of identifying global variables in each of the code files, checking whether there are duplicated global variables in all code files, and obtaining a second check result includes:

[0032] Identify global variables in each of the code files and check if there are duplicate global variables in all code files;

[0033] When duplicate global variables exist, the second check result results in an error.

[0034] Otherwise, a second check result without errors is obtained.

[0035] In one embodiment of the present invention, the step of generating the inspection result of the code package based on all the first inspection results and the second inspection results includes:

[0036] Judge all first and second inspection results:

[0037] If no errors are reported in the first and second checks, a check result indicating that the code package has no errors is generated.

[0038] Otherwise, the check results for generating the code package will show an error.

[0039] This invention also proposes a code inspection system, comprising:

[0040] An acquisition unit is used to acquire a code package, which includes multiple code files; wherein all code files of the code package participate in compilation and are combined into a single executable program during the linking process;

[0041] The first inspection unit is used to inspect the code format of each code file and obtain the first inspection result of each code file;

[0042] The second checking unit is used to identify global variables in each of the code files, check whether there are duplicated global variables in all code files, and obtain the second checking result.

[0043] The generation unit is used to generate the inspection results of the code package based on all the first and second inspection results.

[0044] The present invention also proposes an electronic device, the electronic device comprising:

[0045] One or more processors;

[0046] A storage device for storing one or more programs that, when executed by one or more processors, cause the electronic device to implement the code inspection method described in any of the preceding claims.

[0047] The present invention also proposes a computer-readable storage medium having a computer program stored thereon, which, when executed by a computer's processor, causes the computer to execute the checking method of any of the above-described codes.

[0048] The beneficial effects of this invention are as follows: The code inspection method, system, device, and medium proposed in this invention, when all code files in a code package participate in compilation and are combined into a single executable program during the linking process, can obtain a first inspection result for each code file by checking its code format, and a second inspection result by checking whether there are duplicate global variables in all code files. When the code format of a single code file does not conform to the specifications, a first inspection result indicating an error is obtained for that code file. When all code files contain duplicate global variables, a second inspection result indicating an error is obtained. Therefore, it is evident that only when all first inspection results and second inspection results are error-free will the generated code package inspection result be error-free. Attached Figure Description

[0049] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.

[0050] In the attached diagram:

[0051] Figure 1This is a schematic diagram illustrating the steps of a code inspection method provided in one embodiment of the present invention.

[0052] Figure 2 This is a structural block diagram of a code inspection system provided in one embodiment of the present invention.

[0053] Figure 3 This is a structural block diagram of an electronic device provided in one embodiment of the present invention. Detailed Implementation

[0054] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments. Various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.

[0055] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. The drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0056] In the following description, numerous details are explored to provide a more thorough explanation of embodiments of the invention. However, it will be apparent to those skilled in the art that embodiments of the invention may be practiced without these specific details. In other embodiments, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the invention.

[0057] Please see Figures 1 to 3 This invention proposes a code inspection method, system, device, and medium, applicable to the fields of code file development and management. For example, it inspects C / C++ code files, focusing on comments, identifier names, nesting levels, function formats, and pointer usage, identifying non-compliant code locations and their causes. This invention can simultaneously address code style details within a single file and ensure consistency across different code files during inspection, thereby guaranteeing overall code quality. Detailed descriptions are provided below using specific embodiments.

[0058] Please see Figure 1 In one embodiment of the present invention, a code inspection method is proposed, which may include the following steps.

[0059] Step S10: Obtain a code package, which includes multiple code files; wherein all code files in the code package participate in compilation and are combined into a single executable program during the linking process.

[0060] Specifically, this involves acquiring a code package containing multiple C language code files. These files collectively participate in the compilation process of a software project and are integrated into a single executable program during the final linking stage. For example, in an embedded system development project, the code package might contain different code files for hardware drivers, application logic, and communication protocol stacks.

[0061] Step S20: Check the code format of each code file to obtain the first check result for each code file.

[0062] Specifically, for each code file in the code package, a static check for code formatting is performed sequentially, covering dimensions such as function formatting, identifier formatting, and syntax structure formatting.

[0063] For example, it can check whether function header comments in each code file contain preset Chinese keywords, whether blank lines before and after function definitions conform to specifications, whether identifier lengths exceed limits and whether the first 31 characters conflict, whether pointer levels exceed two levels, whether branch and loop nesting depths exceed eight levels, and whether specific top-level syntax structures, such as header file inclusions, macro definitions, and function declarations and definitions, contain illegal spaces at the beginning of lines. After each code file is checked, a first check result is generated for that code file, which details all found format violations and their specific locations within the code file.

[0064] In one embodiment of the present invention, the code format includes function format, identifier format, and syntax structure format. In step S20, the code format of each code file is checked to obtain a first check result for each code file, which may include the following steps.

[0065] Step S210, for each code file:

[0066] Step S220: Check the identifier format to obtain the identifier format check result.

[0067] In one embodiment of the present invention, step S220 may include the following steps.

[0068] Step S221: Compare the identifier length with the preset threshold length to obtain the length check result.

[0069] Specifically, when checking the identifier format in the code file, an identifier length check is performed first. This step iterates through all identifiers in the current code file, excluding comments, including variable names, function names, etc. For each scanned identifier, the character length of its name is compared with a preset threshold length; in this embodiment, the preset threshold length is set to 31 characters. This comparison operation generates a length check result, which records which identifiers exceed 31 characters in length. These excessively long identifiers are marked for subsequent aggregation.

[0070] For example, the length check will report an error when the identifier length exceeds a preset threshold length.

[0071] Step S222: Compare the characters of different identifiers to obtain the character comparison check results.

[0072] Specifically, a character comparison check is performed between different identifiers. This step aims to detect whether the first few characters of any two different identifiers are completely identical. Specifically, the first 31 characters of the identifier names are compared. A global or project-wide dictionary structure is built to record the first 31 character sequence of each identified identifier and its original position information. By efficiently comparing these records, it is possible to discover whether there are two or more different identifiers whose names have completely identical first 31 character sequences, thus constituting a first 31 character conflict. This comparison process generates a detailed character comparison check result.

[0073] For example, when characters from different identifiers are repeated, the character matching check will report an error.

[0074] Step S223: Obtain the identifier format check result based on the length check result and the character comparison check result.

[0075] Specifically, based on the length check results and character comparison check results generated in the preceding steps, the final identifier format check result is obtained. This result clearly identifies identifier format problems existing in the current code file: on the one hand, it lists all identifiers longer than 31 characters; on the other hand, it specifically reports all identifier pairs or groups that conflict within the first 31 characters, clearly indicating the names of the conflicting identifiers and their respective line numbers in the code file. This identifier format check result will serve as one of the important bases for evaluating the code's compliance and will be integrated into a higher-level check report.

[0076] For example, if neither the length check nor the character comparison check results report an error, the identifier format check result will not report an error; otherwise, the identifier format check result will report an error.

[0077] Step S230: Check the function format and obtain the function format check result.

[0078] In one embodiment of the present invention, step S230 may include the following steps.

[0079] Step S231: Compare the parameter type of the function parameter with the preset parameter type to obtain the function parameter check result.

[0080] Specifically, the function parameter check is performed. This step identifies and compares the parameter types in the parameter list of each defined function in the code file. The function declaration or definition is parsed, the specific data type declared by each formal parameter is extracted, and it is compared with a set of preset prohibited parameter types. The preset parameter types explicitly include "array", specifically referring to array declarations in non-pointer form, and "custom structure type". If the analysis finds that the parameter type of a function matches the preset prohibited type, such as using an array in the form of int arr

[10] or a structure of type struct MyStruct, the corresponding error message is generated, and the function, file and line number of the illegal parameter are recorded. Finally, a function parameter check result is compiled.

[0081] For example, if the parameter type of a function does not conform to the preset parameter type, especially if the parameter type of a function matches the preset prohibited type, the function parameter check will report an error.

[0082] Step S232: Check if there is a blank line before the function header of the function definition and check if there is a blank line after the function body of the function definition to obtain the function definition check result.

[0083] Specifically, a function definition check is performed, focusing on the formatting and layout of function definitions within the source code. This step requires accurately identifying the start and end positions of each function definition. For each identified function definition, it checks whether there is at least one blank line before its function header (i.e., the return type and function name) and at least one blank line after its function body (i.e., the function implementation code block). This check considers various complex cases, such as when there may be multiple lines of comments directly above the function definition; it must correctly determine whether there is also a required blank line above the comment block. Based on the check results, the positions of all function definitions that do not conform to the blank line specifications (such as missing blank lines before or after) are recorded, and a detailed function definition check result is generated.

[0084] For example, if there is a blank line before the function header and a blank line after the function body, the function definition check will not report an error. However, if there is no blank line before the function header and / or no blank line after the function body, the function definition check will report an error.

[0085] Step S233: Check if there are function header comments and obtain the comment check result; and when there are function header comments, compare the keywords in the function header comments with preset keywords and obtain the keyword comparison check result; based on the comment check result and the keyword comparison check result, obtain the function header comment check result.

[0086] Specifically, a function header comment check is performed, which consists of two sub-steps. The first step is a comment existence check, which checks for a continuous comment block immediately preceding each function definition as its function header comment. The second step is a keyword semantic check. If a function header comment block is confirmed to exist, the entire text content within that block is extracted and compared one by one with a set of pre-defined, required keywords. This set of keywords includes "function," "input," "output," and "flow." It determines whether the comment text completely contains all these keywords. The combined results of the comment existence check and the keyword semantic check—for example, a missing comment block or a comment block lacking some required keywords—generate a clear error message indicating which elements are missing, and summarize these results into a function header comment check report.

[0087] For example, if a function header comment exists, the comment check will not report an error; if no function header comment exists, the comment check will report an error.

[0088] For example, when the keyword in the function header comment matches the preset keyword, the keyword comparison check will not report an error; when the keyword in the function header comment does not match the preset keyword, the keyword comparison check will report an error.

[0089] For example, if neither the comment check result nor the keyword comparison check result reports an error, the function header comment check result will not report an error; otherwise, the function header comment check result will report an error.

[0090] Step S234: Based on the function header comment check result, the function parameter check result, and the function definition check result, obtain the function format check result.

[0091] Specifically, the results of the above three checks are integrated to obtain the final function format check result. The results of the function parameter check, function definition check, and function header comment check are combined and analyzed. If no violations are found in any of the checks, a check result indicating that the function format of the file conforms to the specifications is generated. If any check finds a problem, a summary report is generated, which clearly lists all non-compliance found in terms of function parameter types, blank line formatting in function definitions, and the content and completeness of function header comments, and details the specific manifestation and location of each problem, providing direct evidence for code review and correction.

[0092] For example, if the function header comment check, function parameter check, and function definition check all show no errors, the function format check will also show no errors; otherwise, the function format check will show an error.

[0093] Step S240: Check its syntax structure and format to obtain the syntax structure and format check results.

[0094] In one embodiment of the present invention, step S240 may include the following steps.

[0095] Step S241: Check if there are spaces at the beginning of the lines of the top-level syntax structure to obtain the top-level syntax structure check results.

[0096] Specifically, a top-level syntax structure check is performed. This step focuses on specific types of syntax structures in the code file that should be written without indentation at the top-level scope or the beginning of the file. Regular expressions are used to precisely match these structures, including but not limited to header file references (such as #include).<stdio.h> The code snippet covers macro definitions (such as `#define MAX_LEN 100`), function declarations, and function definitions. For each matched structure, the code checks for any whitespace characters (such as spaces or tabs) at the beginning of the line. If a leading whitespace is found, the indentation is deemed non-compliant, as these specific structures must begin at the beginning of the line and should not have any indentation according to the encoding rules of this embodiment. All such violations are recorded, and a detailed top-level syntax structure check result is generated, including the type of violating structure, the file it belongs to, and the exact line number.

[0097] For example, if there is a space at the beginning of a line in the top-level syntax structure, the top-level syntax structure check will report an error; if there is no space at the beginning of a line in the top-level syntax structure, the top-level syntax structure check will not report an error.

[0098] Step S242: Compare the pointer level of the pointer with the preset threshold level to obtain the pointer check result.

[0099] Specifically, a pointer check is performed to limit the depth of pointer variable declarations in the code. After excluding interference from comments, all variable declaration statements in the code file are scanned. Specific regular expression patterns, such as those designed to match three or more consecutive asterisks, are used to identify pointer variables declared as level three or higher (e.g., `int ***p;`). The level of the identified pointer declarations is compared to a preset threshold level, which is set to 2, meaning a maximum allowed pointer level of two (e.g., `int **p;`). Any declaration exceeding this threshold is flagged as a violation. The pointer check results generated by this process clearly indicate all variable declarations using pointers exceeding two levels and their specific locations in the code.

[0100] For example, when the pointer level of a pointer exceeds a preset threshold level, the pointer check result will report an error; when the pointer level of a pointer does not exceed the preset threshold level, the pointer check result will not report an error.

[0101] Step S243: Compare the nesting level of branch and loop statements with the preset threshold level to obtain the branch and loop statement check results.

[0102] Specifically, the branching and looping statement check analyzes the nesting complexity of control flow statements in the code. Using a state machine or similar tracing mechanism, it precisely tracks the pairing and nesting relationships of curly braces {} during code parsing, dynamically calculating and updating the nesting depth of the current execution path. This check targets two types of control flow statements: branching statements (including if, else if, else) and looping statements (including for, while, do...while). For each such statement in the code, the system calculates its nesting level in real time and compares it to a preset threshold. This preset threshold is 8, meaning that the nesting depth of both branching and looping statements should not exceed 8 levels. Once a nesting depth exceeding this limit is detected, a violation is recorded. The final branching and looping statement check result will list the locations of all statements exceeding the nesting limit and indicate their specific nesting depth.

[0103] For example, when the nesting level of branch and loop statements exceeds the preset threshold level, the branch and loop statement check result will report an error; when the nesting level of branch and loop statements does not exceed the preset threshold level, the branch and loop statement check result will not report an error.

[0104] Step S244: Based on the top-level syntax structure check result, the pointer check result, and the branch and loop statement check result, obtain the syntax structure format check result.

[0105] Specifically, the results of the checks in the above three aspects are combined to obtain the final syntax structure format check result. The results of the top-level syntax structure check, pointer check, and branching and loop statement check are summarized. If no violations are found in all checks, a check result indicating that the file's syntax structure format fully conforms to the specification is generated. If any violations are found, a comprehensive report is generated, clearly categorizing all issues found in top-level structure indentation, pointer usage level, and control flow nesting depth. Each issue item includes a specific description, the violated rule, the file path, and line number information, providing developers with a comprehensive and accurate diagnosis of syntax structure compliance.

[0106] For example, if the top-level syntax structure check, pointer check, and branch and loop statement check all show no errors, the syntax structure format check will not show an error; otherwise, the syntax structure format check will show an error.

[0107] Step S250: When the function format check result, the identifier format check result, and the syntax structure format check result all show no errors, a first check result without errors is obtained.

[0108] Specifically, after completing a detailed inspection of a single code file, the inspection results are obtained in three dimensions: function format, identifier format, and syntax structure format. Each result clearly indicates whether there are any violations in the corresponding dimension and their specific locations.

[0109] Specifically, the system comprehensively evaluates the status of the function format check, identifier format check, and syntax structure format check results. Only when none of these three checks reveal any issues is the file deemed fully compliant with the specifications, resulting in a "no errors" final check result.

[0110] For example, when the length check and character comparison check results are not reported, the function header comment check results, function parameter check results, and function definition check results are not reported, and the top-level syntax structure check results, pointer check results, and branch and loop statement check results are not reported, that is, when none of the above seven items report errors, the first check result without errors is obtained.

[0111] Step S260: Otherwise, the first check result of the error is obtained.

[0112] Specifically, if any of the function format check results, the identifier format check results, and the syntax structure format check results are found to have a problem, a final "error" check result will be generated.

[0113] For example, if any of the following checks—length check, character comparison check, function header comment check, function parameter check, function definition check—reports no error, top-level syntax structure check, pointer check, and branch and loop statement check—reports an error, the first check result that indicates an error is obtained.

[0114] Step S30: Identify global variables in each of the code files, check whether there are duplicate global variables in all code files, and obtain the second check result.

[0115] Specifically, after formatting checks on all individual code files, a cross-file global variable redefinition check can be performed. This step iterates through every code file in the code package, using regular expressions to precisely identify the definitions of all global variables, while employing comment preprocessing techniques to prevent comments from interfering with the identification. Subsequently, the global variable names from all code files are compiled into a global symbol table for comparison. If the same variable name is found to be defined repeatedly in multiple code files, it is determined to be a cross-file redefinition error. This check process generates a second check result, summarizing information on all cross-file redefinition global variables, including the variable name and a list of files where the redefinition occurs.

[0116] In one embodiment of the present invention, step S30 may include the following steps.

[0117] Step S310: Identify global variables in each of the code files and check whether there are duplicate global variables in all code files.

[0118] Specifically, all files in the code package are scanned, and regular expressions are used to accurately identify the global variable definitions in each file. A global symbol table containing all variable names and their corresponding file information is then established to provide a data foundation for cross-file comparison.

[0119] Step S320: When there are duplicate global variables, the second check result of the error is obtained.

[0120] Specifically, based on the constructed global symbol table, cross-file duplicate checks are performed. Through an efficient set comparison algorithm, it detects whether the same global variable name is defined repeatedly in two or more different source files, thereby discovering symbol definition conflicts at the project level.

[0121] If a global variable is found to be defined repeatedly across files, a second check result with an error is generated, and the result explicitly lists each duplicate variable name and all file paths in which it appears.

[0122] Step S330: Otherwise, a second check result without errors is obtained.

[0123] Specifically, if all global variables are not defined repeatedly in different files, a second check result without errors is generated.

[0124] Step S40: Generate the inspection results of the code package based on all the first and second inspection results.

[0125] Specifically, the system summarizes and integrates the first inspection results from all code files, as well as the second inspection results obtained from cross-file checks, to generate a comprehensive inspection report for the entire code package. This report, output in text file format, clearly lists all issues present in the code package, including code formatting violations within each file and all duplicate definitions of global variables across files, providing developers with comprehensive diagnostic information on code style compliance.

[0126] In one embodiment of the present invention, step S40 may include the following steps.

[0127] Step S410: Determine all first and second check results.

[0128] Step S420: When all first and second check results are error-free, generate a check result indicating that the code package is error-free.

[0129] Step S430: Otherwise, generate the check results for code package errors.

[0130] Specifically, if neither the first nor the second check results report any errors, a check result indicating no errors in the code package is generated. If either the first or the second check results report an error, a check result indicating errors in the code package is generated.

[0131] Please see Figure 2 In one embodiment of the present invention, a code inspection system 100 may be proposed, which may include an acquisition unit 110, a first inspection unit 120, a second inspection unit 130 and a generation unit 140.

[0132] The acquisition unit 110 is used to acquire a code package, which includes multiple code files; wherein all the code files of the code package participate in the compilation and are combined into a single executable program during the linking process.

[0133] The first inspection unit 120 is used to inspect the code format of each code file and obtain the first inspection result of each code file.

[0134] The second checking unit 130 is used to identify global variables in each of the code files, check whether there are duplicate global variables in all code files, and obtain the second checking result.

[0135] The generation unit 140 is used to generate the inspection results of the code package based on all the first inspection results and the second inspection results.

[0136] Please see Figure 3 In one embodiment of the present invention, an electronic device 200 is also provided. The electronic device 200 may include a memory 210, a processor 220 and a bus, and may also include a computer program, such as a code inspection program, stored in the memory 210 and executable on the processor 220.

[0137] The memory 210 includes at least one type of readable storage medium, such as flash memory, portable hard drive, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 210 can be an internal storage unit of the electronic device 200, such as the portable hard drive of the electronic device 200. In other embodiments, the memory 210 can be an external storage device of the electronic device 200, such as a plug-in portable hard drive, smart media card (SMC), secure digital card (SD), flash card, etc., equipped on the electronic device 200. Furthermore, the memory 210 can include both internal and external storage units of the electronic device 200. The memory 210 can be used not only to store application software and various types of data installed on the electronic device 200, such as code for code checking, but also to temporarily store data that has been output or will be output.

[0138] In some embodiments, processor 220 may be composed of integrated circuits, such as a single packaged integrated circuit or multiple integrated circuits packaged with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips. Processor 220 is the control unit of the electronic device 200, connecting various components of the electronic device 200 via various interfaces and lines. It executes programs or modules (e.g., code checking programs) stored in the memory 210 and calls data stored in the memory 210 to perform various functions and process data of the electronic device 200.

[0139] The processor 220 executes the operating system and various installed applications of the electronic device 200. The processor 220 executes the applications to perform the steps in the code inspection method described above.

[0140] For example, the computer program may be divided into one or more modules, which are stored in the memory 210 and executed by the processor 220 to complete this application. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the electronic device 200. For example, the computer program may be divided into an acquisition unit 110, a first inspection unit 120, a second inspection unit 130, and a generation unit 140.

[0141] The integrated unit implemented as a software functional module described above can be stored in a computer-readable storage medium, which can be non-volatile or volatile. The software functional module stored in the storage medium includes several instructions to cause a computer device (which may be a personal computer, computer equipment, or network device, etc.) or processor to execute part of the functions of the code inspection method described in the various embodiments of this application.

[0142] In summary, this invention proposes a code inspection method, system, device, and medium. When all code files in a code package participate in compilation and are combined into a single executable program during linking, the first inspection result for each code file is obtained by checking its code format, and the second inspection result is obtained by checking whether duplicate global variables exist in all code files. When the code format of a single code file does not conform to the specifications, the first inspection result for that code file is reported as an error. When duplicate global variables exist in all code files, the second inspection result is reported as an error. Therefore, only when all first inspection results and second inspection results are error-free will the generated code package's inspection result be error-free.

[0143] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.

Claims

1. A code inspection method, characterized in that, include: Obtain a code package, which includes multiple code files; wherein all code files in the code package participate in compilation and are combined into a single executable program during the linking process; The code format of each code file is checked to obtain the first check result for each code file; Identify global variables in each of the code files, check if there are duplicate global variables in all code files, and obtain a second check result; Based on all the results of the first and second checks, generate the check results for the code package.

2. The code inspection method according to claim 1, characterized in that, The code format includes function format, identifier format, and syntax structure format; the step of checking the code format of each code file to obtain a first check result for each code file includes: For each code file: The identifier format is checked to obtain the identifier format check result; The function format is checked to obtain the function format check result; The syntax structure and format are checked to obtain the syntax structure and format check results; When the function format check result, the identifier format check result, and the syntax structure format check result are all error-free, the first check result without error is obtained. Otherwise, the first check result will be an error message.

3. The code inspection method according to claim 2, characterized in that, The step of checking the identifier format to obtain the identifier format check result includes: The identifier length is compared with the preset threshold length to obtain the length check result; The characters of different identifiers are compared to obtain the character comparison check results; Based on the length check result and the character comparison check result, the identifier format check result is obtained.

4. The code inspection method according to claim 2, characterized in that, The step of checking the function format to obtain the function format check result includes: The function parameter types are compared with the preset parameter types to obtain the function parameter check results; Check if there is a blank line before the function header in the function definition, and check if there is a blank line after the function body in the function definition, to obtain the function definition check result; The function checks for the existence of function header comments and obtains the comment check result; when function header comments exist, the keywords in the function header comments are compared with preset keywords to obtain the keyword comparison check result; based on the comment check result and the keyword comparison check result, the function header comment check result is obtained. Based on the function header comment check results, the function parameter check results, and the function definition check results, the function format check results are obtained.

5. The code inspection method according to claim 2, characterized in that, The step of checking its syntax structure and format to obtain the syntax structure and format check result includes: Check if there are leading spaces in the top-level syntax structure to obtain the top-level syntax structure check results; The pointer level is compared with the preset threshold level to obtain the pointer check result; The nesting level of branching and looping statements is compared with the preset threshold level to obtain the branching and looping statement check results. Based on the top-level syntax structure check results, the pointer check results, and the branch and loop statement check results, the syntax structure format check results are obtained.

6. The code inspection method according to claim 1, characterized in that, The step of identifying global variables in each of the code files, checking whether there are duplicate global variables in all code files, and obtaining a second check result includes: Identify global variables in each of the code files and check if there are duplicate global variables in all code files; When duplicate global variables exist, the second check result results in an error. Otherwise, a second check result without errors is obtained.

7. The code inspection method according to claim 1, characterized in that, The step of generating the inspection results of the code package based on all the first inspection results and the second inspection results includes: Judge all first and second inspection results: If no errors are reported in the first and second checks, a check result indicating that the code package has no errors is generated. Otherwise, the check results for generating the code package will show an error.

8. A code inspection system, characterized in that, include: An acquisition unit is used to acquire a code package, which includes multiple code files; wherein all code files of the code package participate in compilation and are combined into a single executable program during the linking process; The first inspection unit is used to inspect the code format of each code file and obtain the first inspection result of each code file; The second checking unit is used to identify global variables in each of the code files, check whether there are duplicated global variables in all code files, and obtain the second checking result. The generation unit is used to generate the inspection results of the code package based on all the first and second inspection results.

9. An electronic device, characterized in that, The electronic device includes: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the electronic device to implement the code inspection method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by the computer's processor, causes the computer to perform the inspection method of the code described in any one of claims 1 to 7.