CN109471634B - Method and device for checking source code format - Google Patents

Method and device for checking source code format Download PDF

Info

Publication number
CN109471634B
CN109471634B CN201810988816.8A CN201810988816A CN109471634B CN 109471634 B CN109471634 B CN 109471634B CN 201810988816 A CN201810988816 A CN 201810988816A CN 109471634 B CN109471634 B CN 109471634B
Authority
CN
China
Prior art keywords
format
source code
string
code format
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.)
Active
Application number
CN201810988816.8A
Other languages
Chinese (zh)
Other versions
CN109471634A (en
Inventor
彭凡
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Silead Inc
Original Assignee
Silead Inc
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Silead Inc filed Critical Silead Inc
Priority to CN201810988816.8A priority Critical patent/CN109471634B/en
Publication of CN109471634A publication Critical patent/CN109471634A/en
Application granted granted Critical
Publication of CN109471634B publication Critical patent/CN109471634B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/436Semantic checking

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The application provides a checking method and device for source code format, which can determine a positioning string in a target source code, and obtains the corresponding semantic environment and format check character string according to the positioning character string, further matches the format check character string with the standard code format, judges whether the format specification requirement is met, therefore, the normalization and the consistency of the source code format are ensured, the source code format is distinguished under different semantic environments, the accuracy and the integrity of the source code format inspection are improved, the source code format inspection can be improved for a more complex code semantic environment, the inspection mode is more flexible, the practicability of the source code format inspection technology is improved, misoperation caused by automatic code conversion is avoided, the reading efficiency of developers on the source code is also improved, and further the working efficiency of the developers is improved.

Description

Method and device for checking source code format
Technical Field
The present application relates to the field of computer software, and in particular, to a method and an apparatus for checking a source code format.
Background
Currently, in the software development process, in order to achieve standardization and normalization of the development code format and facilitate maintenance and team cooperation of the software code, the development code format needs to be checked to determine whether the corresponding specification is satisfied. The united states patent application Method And Apparatus for reforming Source Code application (US20070011654) provides a Method for checking Source Code format, which mainly realizes the conversion between the Source Code format of the Source Code warehouse And the Code format expected by the user when detecting the Source Code, And the main problem lies in that: the scheme does not subdivide the processing of the positioning strings under different semantics, for example, when the content of a sentence follows the '}', in general, the content behind the '}' should be another line, but if the '}' is in the overall context defined by a macro, the processing can not be performed, and if the front of the '{' corresponding to the '}' is next to the do keyword, the processing can also not be performed, and the like.
Furthermore, the U.S. patent application scheme does not distinguish between the code styles of general application layer source code and Kernel layer source code, e.g., a '{' after an if statement may tend to be required to be another line in application layer source code, while in Kernel layer source code (following the GNU style, such as Linux Kernel) tends to be placed in the same line as the if statement. Therefore, the scheme is too simple and rough to check the source code format, and cannot realize the checking of the source code format under different semantic environments, and in addition, the scheme does not realize the comparison of the original code content and the code content retransmitted after being read by a user and ensure the complete consistency, so that the content or semantic change of the original code content after the format is converted can be caused due to the defect of an automatic conversion tool, and the correctness and the integrity of the code content in a code warehouse are damaged.
Invention of the inventionContent providing method and apparatus
An object of the present application is to provide a method and apparatus for checking a source code format.
In order to achieve the above object, the present application provides a method for checking a source code format, wherein the method includes:
acquiring a target source code for format check;
reading the target source code, and searching and determining a positioning string;
determining a semantic environment and a format check character string corresponding to the positioning character string according to the determined positioning character string;
and matching the format check character string with a preset standard code format corresponding to the semantic environment, and giving corresponding prompt information when the matching is inconsistent.
Further, the positioning string comprises: operators, keywords, and parentheses.
Further, according to the determined positioning character string, determining a semantic environment and a format check character string corresponding to the positioning character string:
acquiring a file stream pointer pointing to the positioning string, and moving the file stream pointer forwards or backwards in the context of the positioning string;
and determining the semantic environment and the format check character string corresponding to the positioning character string according to the character acquired by the file stream pointer and a preset semantic environment judgment rule.
Further, after determining the semantic environment and the format check character string corresponding to the positioning character string according to the determined positioning character string, the method further includes:
and acquiring a preset standard code format corresponding to the semantic environment according to the semantic environment.
Further, before the target source code for format check is obtained, the method further includes:
and monitoring user operation, and triggering the acquisition of the target source code when the user executes the target source code submitting operation.
Further, after the target source code for format check is obtained, the method further includes:
acquiring a preset source code format specification;
and acquiring a preset standard code format according to the configuration in the source code format specification.
Further, the method further comprises:
acquiring a file path of a target source code file;
determining a code format of a target source code according to the file path, wherein the code format comprises a Linux Kernel format and an application program format;
acquiring a preset standard code format corresponding to the code format according to the determined code format;
and carrying out format check on the target source code according to the preset standard code format.
Further, performing format check on the target source code according to the preset standard code format, including:
if the determined code format is the Linux Kernel format, the positioning string is a left curly brace, the acquired preset standard code format is an if (or else if or while or for or switch) statement and then directly follows {, or a single-line statement after the if (or else if or while or for or switch) statement does not use { sum } wrapping, the acquired format check character string is matched with the preset standard code format, and when the matching is unsuccessful, prompt information that the format check fails is given.
Further, performing format check on the target source code according to the preset standard code format, including:
if the determined code format is an application program format, the positioning string is a left curly brace, another line is started after the obtained preset standard code format is an if (or else if or while or for or switch) statement, and then the { } is followed, or { and } is used for wrapping a single line statement after the if (or else if or while or for or switch) statement, the obtained format check character string is matched with the preset standard code format, and when the matching is unsuccessful, prompt information that the format check fails is given.
The present application also provides an inspection apparatus in a source code format, the apparatus comprising a memory for storing computer program instructions and a processor for executing the program instructions, wherein the computer program instructions, when executed by the processor, cause the apparatus to perform the aforementioned inspection method in a source code format.
The present application also provides a computer readable medium having stored thereon computer readable instructions executable by a processor to implement the aforementioned inspection method of source code format.
Compared with the prior art, the scheme provided by the application can determine the positioning character string in the target source code, and obtains the corresponding semantic environment and format check character string according to the positioning character string, further matches the format check character string with the standard code format, judges whether the format specification requirement is met, therefore, the normalization and the consistency of the source code format are ensured, the source code format is distinguished under different semantic environments, the accuracy and the integrity of the source code format inspection are improved, the source code format inspection can be improved for a more complex code semantic environment, the inspection mode is more flexible, the practicability of the source code format inspection technology is improved, the possible misoperation of automatic code conversion is avoided, the reading efficiency of developers on the source code is also improved, and the working efficiency of the developers is further improved.
Drawings
Other features, objects and advantages of the present application will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
fig. 1 is a flowchart of a method for checking a source code format according to an embodiment of the present application.
Fig. 2 is a schematic diagram of a preferred source code format checking method according to an embodiment of the present application.
Detailed Description
The present application is described in further detail below with reference to the attached figures.
In a typical configuration of the present application, the terminal, the device serving the network, and the trusted party each include one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include non-transitory computer readable media (transient media), such as modulated data signals and carrier waves.
Some embodiments of the present application provide a method for checking a source code format, as shown in fig. 1, the method specifically includes the following steps:
step S101, acquiring a target source code for format check;
step S102, reading the target source code, searching and determining a positioning string;
step S103, determining a semantic environment and a format check character string corresponding to the positioning character string according to the determined positioning character string;
and step S104, matching the format check character string with a preset standard code format corresponding to the semantic environment, and giving corresponding prompt information when the matching is inconsistent.
The scheme is particularly suitable for a scene of carrying out format check on a source code submitted by a software developer, can determine a positioning character string from a target source code, obtains a format check character string in a context according to the positioning character string, further matches the format check character string with a standard code format, judges whether the format specification requirement is met, and gives corresponding prompt information for the developer to refer and carry out corresponding modification if the format specification is not met.
The source code format to be checked is an organization form of a plurality of codes in the source code, the source code format is displayed to a user in a code editor, different code display formats have different influences on code reading, the efficiency of developers reading the familiar source code format is high, the code errors are easy to find, in the same software project development team, a plurality of developers are guaranteed to write the codes in the same source code format, the communication efficiency and the development efficiency in the team can be improved, and the code error rate is reduced. Here, the user and the developer have the same meaning and refer to the relevant person who writes the code and reads the code.
In step S101, a target source code for format check is first acquired. Preferably, before the target source code is acquired, user operation can be monitored, and when the user executes the target source code submitting operation, the acquisition of the target source code is triggered. In some embodiments of the application, a software developer can obtain a source code when submitting the developed source code to a code management system, the obtained source code is subjected to source code format check before being stored in a code library, the obtained source code is a target source code, and the target source code is stored in the code library which is responsible for maintenance of the code management system after the format check is passed. Preferably, a function module for checking the source code format can be expanded for the code management system, and the function module is used for completing the acquisition and format checking functions of the target source code.
In the team development process of the software project, each software developer is responsible for the development of software modules in a plurality of software projects, and in order to facilitate the progress management and source code tracking of source codes, each developer needs to periodically submit the source codes developed by the developer to a code management system for storage and management, wherein the common code management systems include but are not limited to a CVS system, an SVN system, a Git system and the like. Preferably, in some embodiments of the present application, a Git system is used to implement storage and management of source code, as shown in fig. 2, a developer submits a code to the Git system, a code submission operation triggers running of a script file in the Git system, the script file calls a source code format detection parser stored in advance in a designated path of a server to perform format parsing on all source code files submitted by the developer, where the designated path of the server may be generally/usr/local/bin, and the code format detection parser is not a functional module initially provided by the code management system, but an extended functional module added by the developer to the code management system according to own needs.
For example, a git/hooks/pre-commit script, which may be called automatically by a developer when entering the git commit command under a directory where the git command may be executed, may be as follows:
Figure BDA0001780299120000061
Figure BDA0001780299120000071
in the above codes, parseCommit is a program for implementing source code format detection and parsing in some embodiments of the present application, and is used to perform format parsing on source code submitted by a developer. The pre-commit script file under git/hooks calls the program parseCommit in parsed code format, the statement format is like parseCommit $ changed _ files, and changed _ files contains all source code files in the code submission.
Preferably, after the target source code for format check is obtained, the source code format detection parser may further obtain a preset source code format specification, and obtain a preset standard code format according to a configuration in the source code format specification. The source code format specification can be determined according to the code format checking requirements of software enterprises and developers, for example, the source code format specification meeting the requirements of the own enterprise can be formulated according to the relevant standards in the field of software development. Here, the source code format specification is independent of the code management system and can be used for different code management systems.
In some embodiments of the present application, the source code format specification may be stored in an XML file, nodes in the XML file correspond to the standard code format specification, and the source code format specification may be configured in the XML nodes. The source code format specification XML file may be stored under a preset server path, such as/usr/etc.
For example, the source code format specification XML file may be iso _ code _ format _ check, the storage path of the file may be/usr/gitxml/, and the contents in the file may be as follows:
Figure BDA0001780299120000081
in the code, a TypeSetting node represents TypeSetting setting, and a sysparm _ on value of 1 represents that a switch is turned on, namely format check of source code TypeSetting setting is required; the BiOperatorSpace node represents a blank of a binocular operator, the sysparm _ on value is 1, the switch is turned on, and format check whether blanks exist on the two sides of the binocular operator is needed; the BracePosition node represents another row of curly braces, and the sysparm _ on value of 1 represents that the switch is opened, namely, the format check whether the left curly braces and the right curly braces separately form another row is required.
In some embodiments of the present application, the source code format checking and parsing program reads the source code format specification file, obtains a source code format configuration therein, for example, a biamperarspace node configuration, and obtains a preset standard code format according to the configurations. The preset standard code format can be stored in a character string form, and can be used as part of data in the source code format checking and analyzing program, or can be stored in a separate file, and the source code format checking and analyzing program acquires the standard code format from the file when needed.
In step S102, the target source code is read, and the location string is searched and determined. In some embodiments of the present application, after obtaining the target source code, the code management system searches for and determines the locator string by reading the target source code character by character one by character. Here, the locator string refers to a string used to determine a format check position, and preferably, the locator string may include, but is not limited to, the following: operators, keywords, and parentheses. The locator string can be set and adjusted according to the requirements of developers for checking the source code format. The operators may include, but are not limited to, unary operators, binary operators, and the like, and may be, for example, '+', '-', '/', and the like. Keywords may include, but are not limited to, the following keywords: for, if, switch, while, etc. The brackets may include, but are not limited to, round brackets and curly brackets, and may be, for example: '(', ')', '{', '}' and the like.
Preferably, the target source code is read character by character in a file stream mode, wherein a file stream pointer Fp is mainly used in the file stream mode, the source code submitted to the code management system by a developer is saved in a file form, and all the target source code in the source code file can be obtained by moving the file stream pointer Fp. In the development language, corresponding function functions are generally provided for the forward and backward movement of the file stream pointer Fp in the source code file, for example, a getc function can be used for the forward movement of the file stream pointer Fp, a fseek function and an ungc function can be used for the backward movement of the file stream pointer Fp, and the like. When the source code file is just opened through the file stream pointer Fp, the file stream pointer Fp points to the head of the source code file, the file stream pointer Fp moves forward to point to the tail of the source code file, and the file stream pointer Fp moves backward to point to the head of the source code file.
In some embodiments of the present application, when the file stream pointer Fp is moved to point to a character, it may be determined whether the character is a first character of an operator, a parenthesis, or a keyword in a positioning character string, and if the character is an operator or a parenthesis in a positioning character string, the character may be determined to be a positioning character string; if the character is the first character of the keyword, moving the file stream pointer Fp forward until a certain ending character is pointed, comparing a character string formed by the character and all characters between the character and the ending character with the keyword, and if the character string is matched with the keyword, determining the character string as a positioning character string; if the character is not a positioning string, the file stream pointer Fp is moved forward by one character.
In a preferred embodiment of the application, a file stream pointer pointing to a next character can be continuously acquired through a getc function, a file stream pointer pointing to a previous character can be continuously acquired through a combination of a fseek function and an unfortc function, a required character string is stored through a bufAddChar function, whether a difference exists between the stored character string and a character string corresponding to a preset standard code format or not is judged through a strcmp function, and a format error prompt message is printed on a screen by calling a fprintf function according to the difference; in addition, whether a line in which a character is located is a for sentence or a macro definition sentence or not can be determined by a macro sentence written in advance.
In step S103, according to the determined positioning string, a semantic environment and a format check string corresponding to the positioning string are determined. Specifically, a file stream pointer pointing to the positioning string is obtained, the file stream pointer is moved forwards or backwards in the context of the positioning string, and then a semantic environment and a format check string corresponding to the positioning string are determined according to the character obtained by the file stream pointer and a preset semantic environment judgment rule.
In some embodiments of the present application, a currently pointed character is obtained by moving a file stream pointer forward or backward, a required character string may be stored in a cache, and then the character string is matched with a preset semantic environment determination rule, and if matching is successful, it is considered that a certain semantic environment is satisfied. Here, the semantic context may include, but is not limited to, the following: a constant name environment, a constant value environment, a parenthesis environment, a curly parenthesis environment, a function declaration or definition environment, a for statement environment, an annotation environment, a macro definition environment, a curly parenthesis wrapping environment, and the like.
For example, the locating string pointed by the initial position of the file stream pointer is '}', and the preset semantic environment judgment rule may include the following two rules, rule one: if the positioning character string is '}' and the character '{' of the positioning character string in the backward direction is not adjacent to the '\ n' character, the character string between the first '\ n' character in the backward direction and the first space character in the forward direction is matched with the character string "# define", and the semantic environment in which the positioning character string is positioned is the macro definition environment. Rule two: if the positioning string is '}' and the character '{' of the positioning string in the backward direction is adjacent to the '\ n' character, and the '\\' character can be found in the backward direction, the semantic environment in which the positioning string is located is the macro definition environment.
In a specific source code format check, the filestream pointer is continuously moved backward from the initial position of the positioning string, and when moving to the first '{' position, it is known that the compound sentence included between '{' and '}' has ended, at which time the character in the backward direction of the '{' character is not the '\ n' character, the filestream pointer continues to move backward until the first '\ n' character is encountered, whereupon the string between the '\ n' character and the first space character in the forward direction of the source code is saved into the cache and matched with the string "# fine", and if the matching is successful, the positioning string is determined to be in the macro-defined semantic environment, and the format check string is determined to be a string composed of all characters from the '\\ n' character up to the positioning string '}'.
For another example, the locating string pointed by the initial position of the file stream pointer is '}', and the preset semantic environment judgment rule may be the following rule: if the positioning character string is '}' and the character's {' of the positioning character string in the backward direction is found out later, the character string 'do', the semantic environment in which the positioning character string is located is a do-while semantic environment.
In the concrete source code format check, the filestream pointer is continuously moved backward from the initial position of the positioning string, when moving to the first '{' position, it is known that the compound sentence included between '{' and '}' has ended, at which time the filestream pointer continues to move backward, if a "do" string is encountered before a '\ n' character is encountered or a "do" string is encountered after a '\ n' character is encountered, it can be determined that the positioning string is in the semantic environment of do-while, and the format check string is determined as a string composed of all characters from the "do" string up to the positioning string '}'.
After determining the corresponding semantic environment and format check character string, the file stream pointer can be moved forward or backward by the same number of bytes to return to the initial position, i.e. the position pointing to the positioning character string, and then the subsequent positioning character string searching is continued forward.
Preferably, after the semantic environment and the format check character string are determined, a preset standard code format corresponding to the semantic environment may be further acquired according to the semantic environment. The preset standard code format can be multiple and respectively corresponds to different semantic environments, can be set according to user requirements, can be realized in a source code format inspection program, and can also be independent of the source code format inspection program and stored in a standard code format file. The preset standard code format indicates a code writing format which a developer should follow, and codes which do not conform to the standard code format are regarded as codes with format problems and need to be modified according to the standard format.
In step S104, the format check character string is matched with a preset standard code format corresponding to the semantic environment, and when the matching is inconsistent, corresponding prompt information is given. For example, the preset standard code format is a character string "if" and a character '(' a space character exists between them, the standard code format character string corresponding to the preset standard code format is "if (", if the format check character string is "if (", the format check character string does not match the standard code format character string corresponding to the preset standard code format, and corresponding prompt information is given, where the prompt information is, for example, "FileName: fpsvc/fpsvcrxclient. c Row:82Col:25Reason: pls add one space between "if" and "(" | ". The source code format check of the source code file fails, as long as one source code file fails to be checked in the source code format during the submission, the source code format check submitted this time is declared to fail.
In some embodiments of the present application, the code styles of the application layer source code and the Kernel layer source code may be further distinguished, and a specific difference between the code styles of the application layer source code and the Kernel layer source code is that the Kernel layer source code completely follows a GNU style or a Linux style, for example, a '{' does not usually form another line; if there is only one line of code after the if statement, then there is no wrapping with '{' and '}' before and after the code. This style difference is not really hard and is more of a custom result. The differences in code format handling are represented by: when meeting the condition that '{' does not take another line after statements such as if, switch, while, for, etc., if the source code is Kernel layer source code, the source code format detection and analysis program skips the condition and does not process the situation, and if the source code is application layer source code, the source code format detection and analysis program reports code format errors.
Preferably, the distinguishing process of the code styles of the application layer source code and the Kernel layer source code includes the following steps: firstly, acquiring a file path of a target source code file; determining the code format of the target source code according to the file path; further acquiring a preset standard code format corresponding to the code format according to the determined code format; and finally, carrying out format check on the target source code according to the preset standard code format. Here, the code format of the target source code includes a Linux Kernel format and an application format.
In some embodiments of the present application, the path part of the file name is analyzed when the input file is read, so that whether the file is a Kernel source code file or an application source code file is known. The common sense file storage paths of the application program source code file and the Kernel source code file are different, for example, the Kernel layer source code in the Android open source project has a fixed storage path, the storage path of the application program source code file can be flexibly set, and the corresponding code format can be determined through the difference of the target source code file paths. Because there are some differences in the two code formats, the user can provide some standard code formats corresponding to the two code formats in advance, and perform format check on the target source code according to the standard code formats.
Preferably, the format check of the target source code is performed according to the preset standard code format, and specifically, the method may include the following steps: if the determined code format is the Linux Kernel format, the positioning string is a left curly brace, the acquired preset standard code format is an if (or else if or while or for or switch) statement and then directly follows {, or a single-line statement after the if (or else if or while or for or switch) statement does not use { sum } wrapping, the acquired format check character string is matched with the preset standard code format, and when the matching is unsuccessful, prompt information that the format check fails is given.
Preferably, the format check of the target source code is performed according to the preset standard code format, and specifically, the method may include the following steps: if the determined code format is an application program format, the positioning string is a left curly brace, another line is started after the obtained preset standard code format is an if (or else if or while or for or switch) statement, and then the { } is followed, or { and } is used for wrapping a single line statement after the if (or else if or while or for or switch) statement, the obtained format check character string is matched with the preset standard code format, and when the matching is unsuccessful, prompt information that the format check fails is given.
Some embodiments of the present application also provide an inspection apparatus in a source code format, the apparatus comprising a memory for storing computer program instructions and a processor for executing the program instructions, wherein the computer program instructions, when executed by the processor, cause the apparatus to perform the aforementioned inspection method in a source code format.
Some embodiments of the present application also provide a computer readable medium having stored thereon computer readable instructions executable by a processor to implement the method of inspecting the aforementioned source code format.
Compared with the prior art, the scheme provided by the application can determine the positioning character string in the target source code, and obtains the corresponding semantic environment and format check character string according to the positioning character string, further matches the format check character string with the standard code format, judges whether the format specification requirement is met, therefore, the normalization and the consistency of the source code format are ensured, the source code format is distinguished under different semantic environments, the accuracy and the integrity of the source code format inspection are improved, the source code format inspection can be improved for a more complex code semantic environment, the inspection mode is more flexible, the practicability of the source code format inspection technology is improved, misoperation caused by automatic code conversion is avoided, the reading efficiency of developers on the source code is also improved, and further the working efficiency of the developers is improved.
It should be noted that the present application may be implemented in software and/or a combination of software and hardware, for example, implemented using Application Specific Integrated Circuits (ASICs), general purpose computers or any other similar hardware devices. In one embodiment, the software programs of the present application may be executed by a processor to implement the steps or functions described above. Likewise, the software programs (including associated data structures) of the present application may be stored in a computer readable recording medium, such as RAM memory, magnetic or optical drive or diskette and the like. Additionally, some of the steps or functions of the present application may be implemented in hardware, for example, as circuitry that cooperates with the processor to perform various steps or functions.
In addition, some of the present application may be implemented as a computer program product, such as computer program instructions, which when executed by a computer, may invoke or provide methods and/or techniques in accordance with the present application through the operation of the computer. Program instructions which invoke the methods of the present application may be stored on a fixed or removable recording medium and/or transmitted via a data stream on a broadcast or other signal-bearing medium and/or stored within a working memory of a computer device operating in accordance with the program instructions. An embodiment according to the present application comprises an apparatus comprising a memory for storing computer program instructions and a processor for executing the program instructions, wherein the computer program instructions, when executed by the processor, trigger the apparatus to perform a method and/or a solution according to the aforementioned embodiments of the present application.
It will be evident to those skilled in the art that the present application is not limited to the details of the foregoing illustrative embodiments, and that the present application may be embodied in other specific forms without departing from the spirit or essential attributes thereof. The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the application being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference sign in a claim should not be construed as limiting the claim concerned. Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the apparatus claims may also be implemented by one unit or means in software or hardware.

Claims (10)

1. A method for checking a source code format, wherein the method comprises:
acquiring a target source code for format check;
reading the target source code, and searching and determining a positioning string;
acquiring a file stream pointer pointing to the positioning character string, moving the file stream pointer forwards or backwards in the context of the positioning character string, and determining a semantic environment and a format check character string corresponding to the positioning character string according to the character string acquired by the file stream pointer and a preset semantic environment judgment rule;
matching the format check character string with a preset standard code format corresponding to the semantic environment, and giving corresponding prompt information when the matching is inconsistent;
acquiring a file path of a target source code file;
determining a code format of a target source code according to the file path, wherein the code format comprises a Linux Kernel format and an application program format;
acquiring a preset standard code format corresponding to the code format according to the determined code format;
and carrying out format check on the target source code according to the preset standard code format.
2. The method of claim 1, wherein the locator string comprises: operators, keywords, and parentheses.
3. The method of claim 1, wherein determining, from the determined locator string, a semantic environment and format check string to which the locator string corresponds comprises:
acquiring a file stream pointer pointing to the positioning string, and moving the file stream pointer forwards or backwards in the context of the positioning string;
and determining the semantic environment and the format check character string corresponding to the positioning character string according to the character acquired by the file stream pointer and a preset semantic environment judgment rule.
4. The method of claim 3, wherein after determining the semantic environment and format check string corresponding to the locator string according to the determined locator string, further comprising:
and acquiring a preset standard code format corresponding to the semantic environment according to the semantic environment.
5. The method of claim 1, wherein prior to obtaining the target source code for format checking, further comprising:
and monitoring user operation, and triggering the acquisition of the target source code when the user executes the target source code submitting operation.
6. The method of claim 1, wherein after obtaining the target source code for format checking, further comprising:
acquiring a preset source code format specification;
and acquiring a preset standard code format according to the configuration in the source code format specification.
7. The method of claim 1, wherein performing a format check on the target source code according to the preset standard code format comprises:
if the determined code format is the Linux Kernel format, the positioning string is a left curly brace, the acquired preset standard code format is an if (or else if or while or for or switch) statement and then directly follows {, or a single-line statement after the if (or else if or while or for or switch) statement does not use { sum } wrapping, the acquired format check character string is matched with the preset standard code format, and when the matching is unsuccessful, prompt information that the format check fails is given.
8. The method of claim 1, wherein performing a format check on the target source code according to the preset standard code format comprises:
if the determined code format is an application program format, the positioning string is a left curly brace, another line is started after the obtained preset standard code format is an if (or else if or while or for or switch) statement, and then the { } is followed, or { and } is used for wrapping a single line statement after the if (or else if or while or for or switch) statement, the obtained format check character string is matched with the preset standard code format, and when the matching is unsuccessful, prompt information that the format check fails is given.
9. An inspection apparatus in source code format, the apparatus comprising a memory for storing computer program instructions and a processor for executing the program instructions, wherein the computer program instructions, when executed by the processor, cause the apparatus to perform the method of any of claims 1 to 8.
10. A computer readable medium having computer readable instructions stored thereon which are executable by a processor to implement the method of any one of claims 1 to 8.
CN201810988816.8A 2018-08-28 2018-08-28 Method and device for checking source code format Active CN109471634B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810988816.8A CN109471634B (en) 2018-08-28 2018-08-28 Method and device for checking source code format

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810988816.8A CN109471634B (en) 2018-08-28 2018-08-28 Method and device for checking source code format

Publications (2)

Publication Number Publication Date
CN109471634A CN109471634A (en) 2019-03-15
CN109471634B true CN109471634B (en) 2021-11-16

Family

ID=65659987

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810988816.8A Active CN109471634B (en) 2018-08-28 2018-08-28 Method and device for checking source code format

Country Status (1)

Country Link
CN (1) CN109471634B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110083587A (en) * 2019-04-16 2019-08-02 会找房(北京)网络技术有限公司 A kind of databases comparison measures and procedures for the examination and approval based on Git
CN110096442B (en) * 2019-04-25 2023-06-30 北京码上趣学科技有限公司 Code debugging method, user equipment, storage medium and device
CN111552513B (en) * 2020-04-30 2024-04-16 中国银行股份有限公司 Character set replacement method and device
CN111679830A (en) * 2020-06-03 2020-09-18 中国银行股份有限公司 File coding format detection method and device
CN112486566A (en) * 2020-10-23 2021-03-12 百果园技术(新加坡)有限公司 Code file processing method, device, equipment and storage medium
CN112817876B (en) * 2021-04-19 2022-02-01 阿里云计算有限公司 Code diagnosis method, device, server, user equipment and storage medium

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101017458A (en) * 2007-03-02 2007-08-15 北京邮电大学 Software safety code analyzer based on static analysis of source code and testing method therefor
CN102799520A (en) * 2012-06-27 2012-11-28 清华大学 Static checking method and device for source code pairing
CN103294598A (en) * 2013-05-28 2013-09-11 华为技术有限公司 Method and device for source code inspection
CN103309804A (en) * 2013-04-08 2013-09-18 中国电子科技集团公司第十研究所 Automatic code rule checking platform
CN103778210A (en) * 2014-01-15 2014-05-07 北京京东尚科信息技术有限公司 Method and device for judging specific file type of file to be analyzed
CN104050085A (en) * 2014-06-25 2014-09-17 北京思特奇信息技术股份有限公司 Forced code standard inspection method and system
CN105068925A (en) * 2015-07-29 2015-11-18 北京理工大学 Software security flaw discovering system
CN106201889A (en) * 2016-07-15 2016-12-07 国云科技股份有限公司 A kind of system and its implementation checking that program code writes specification
CN106970819A (en) * 2017-03-28 2017-07-21 清华大学 A kind of c program code specification check device based on the regular description languages of PRDL
CN107357733A (en) * 2017-07-17 2017-11-17 万帮充电设备有限公司 Improve the method and device of code quality

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070011654A1 (en) * 2005-07-10 2007-01-11 Opperman David B Method and apparatus for reformatting source code appearance

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101017458A (en) * 2007-03-02 2007-08-15 北京邮电大学 Software safety code analyzer based on static analysis of source code and testing method therefor
CN102799520A (en) * 2012-06-27 2012-11-28 清华大学 Static checking method and device for source code pairing
CN103309804A (en) * 2013-04-08 2013-09-18 中国电子科技集团公司第十研究所 Automatic code rule checking platform
CN103294598A (en) * 2013-05-28 2013-09-11 华为技术有限公司 Method and device for source code inspection
CN103778210A (en) * 2014-01-15 2014-05-07 北京京东尚科信息技术有限公司 Method and device for judging specific file type of file to be analyzed
CN104050085A (en) * 2014-06-25 2014-09-17 北京思特奇信息技术股份有限公司 Forced code standard inspection method and system
CN105068925A (en) * 2015-07-29 2015-11-18 北京理工大学 Software security flaw discovering system
CN106201889A (en) * 2016-07-15 2016-12-07 国云科技股份有限公司 A kind of system and its implementation checking that program code writes specification
CN106970819A (en) * 2017-03-28 2017-07-21 清华大学 A kind of c program code specification check device based on the regular description languages of PRDL
CN107357733A (en) * 2017-07-17 2017-11-17 万帮充电设备有限公司 Improve the method and device of code quality

Also Published As

Publication number Publication date
CN109471634A (en) 2019-03-15

Similar Documents

Publication Publication Date Title
CN109471634B (en) Method and device for checking source code format
CN109474488B (en) Interface testing method and device and computer equipment
US9152731B2 (en) Detecting a broken point in a web application automatic test case
US9898387B2 (en) Development tools for logging and analyzing software bugs
EP3265916B1 (en) A method for identifying a cause for a failure of a test
US8875110B2 (en) Code inspection executing system for performing a code inspection of ABAP source codes
US9280442B1 (en) System and method for generating coverage reports for software unit tests
US9043759B1 (en) System and method for generating software unit tests simultaneously with API documentation
US9104797B1 (en) Efficient cloud-based annotation of crash reports
US9098500B1 (en) Revision history storage and maintenance
US10990514B2 (en) Detecting problematic code changes
US10229042B2 (en) Detection of meaningful changes in content
US8042099B2 (en) Facilitating availability of object data types at runtime
CN107766353B (en) Method and device for migrating statistical information of database
KR101979329B1 (en) Method and apparatus for tracking security vulnerable input data of executable binaries thereof
US8898649B2 (en) Application program analysis method, analysis system and recording medium for identifying a contributing factor for an invalid operation of an application program
CN110851351A (en) Deployment environment testing method and device, computer equipment and storage medium
US20190196946A1 (en) Software testing systems and methods
US20230325181A1 (en) Code Analysis Method and Related Device
WO2020112420A1 (en) Indexing and searching a time-travel trace for arbitrary length/arbitrary alignment values
CN112363706A (en) Nested combination preprocessing method and equipment
CN110716804A (en) Method and device for automatically deleting useless resources, storage medium and electronic equipment
CN111352631B (en) Interface compatibility detection method and device
CN114817047A (en) Compiler test method, case generation method and device and instruction storage structure
CN114780420A (en) Method, device, equipment and storage medium for automatic test based on test case

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
GR01 Patent grant
GR01 Patent grant