CN109471634A - The inspection method and equipment of source code format - Google Patents

The inspection method and equipment of source code format Download PDF

Info

Publication number
CN109471634A
CN109471634A CN201810988816.8A CN201810988816A CN109471634A CN 109471634 A CN109471634 A CN 109471634A CN 201810988816 A CN201810988816 A CN 201810988816A CN 109471634 A CN109471634 A CN 109471634A
Authority
CN
China
Prior art keywords
format
source code
character string
code
code format
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.)
Granted
Application number
CN201810988816.8A
Other languages
Chinese (zh)
Other versions
CN109471634B (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

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

This application provides a kind of inspection method of source code format and equipment, location character string can be determined in target source code, and corresponding semantic environment and format checking character string are obtained according to location character string, further format checking character string is matched with standard code format, judge whether to meet format specification requirement, to ensure that the normalization and consistency of source code format, also achieve the differentiation under different semantic environments to source code format, improve the accuracy and integrality of source code format inspection, source code format inspection can be improved for more complicated code semantic environment, test mode is more flexible, improve the practicability of source code format Examined effect, avoid the automatic conversion bring maloperation of code, developer is also improved to the reading efficiency of source code, and then improve developer Working efficiency.

Description

The inspection method and equipment of source code format
Technical field
This application involves computer software fields more particularly to the inspection methods and equipment of a kind of source code format.
Background technique
Currently, in software development process, for the standardization and standardization for realizing exploitation code format, facilitate software code Maintenance and team collaboration, need to check the format of exploitation code, it is determined whether meet corresponding specification.United States Patent (USP) Apply for Method And Apparatus for Reformatting Source Code Appearance (US20070011654) a kind of inspection method of source code format is given, the program mainly realizes the source of source code storage Code format and user detect the inversion of phases mutual back and forth of desired obtained code format between the two, main problem when source code Be: the program does not segment processing of the location character string under different semantemes, for example, ' ' followed by sentence content When, under normal circumstances, content after ' } ' should newline, but if ' } ' is under the whole context of a macrodefinition, then It can be not processed, for another example fruit ' } ' corresponding ' { ' front immediately do keyword, then can also be not processed etc..
In addition, code wind of the U.S. Patent application scheme for general application layer source code and Kernel layers of source code Lattice simultaneously do not differentiate between processing, for example, after if sentence ' ' may tend to be required newline in application layer source code, and Tend to be placed on same a line with if sentence if in Kernel layers of source code (GNU style being followed, such as linux kernel).Therefore The program is too simple to the inspection of source code format and rough, can not achieve the inspection of the source code format under different semantic environments It looks into, in addition, the code content that the program and being not implemented retransmits again after reading original code content and user is compared and true Protect it is completely the same, in this way can due to automatic conversion tool defect and cause original code content after format is converted may hair It is perhaps semantic in raw to change, so that the correctness and integrality to the code content in code storage damage.
Apply for content
The purpose of the application is to provide the inspection method and equipment of a kind of source code format.
To achieve the above object, this application provides a kind of inspection methods of source code format, wherein this method comprises:
Obtain the target source code for carrying out format checking;
The target source code is read, search and determines location character string;
According to determining location character string, the corresponding semantic environment of the location character string and format checking character are determined String;
Format checking character string preset standard code format corresponding with the semantic environment is matched, With it is inconsistent when, provide corresponding prompt information.
Further, the location character string includes: operator, keyword and bracket.
Further, according to determining location character string, the corresponding semantic environment of the location character string and format are determined Check character string:
Obtain be directed toward location character string file flow index, and by the file flow index location character string context In be moved forward or rearward;
The character obtained according to the file flow index and default semantic environment decision rule, determine the location character string Corresponding semantic environment and format checking character string.
Further, according to determining location character string, the corresponding semantic environment of the location character string and format are determined After inspection character string, further includes:
According to the semantic environment, preset standard code format corresponding with the semantic environment is obtained.
Further, before the target source code for obtaining progress format checking, further includes:
User's operation is monitored, when user's performance objective source code is submitted and operated, triggers the acquisition to target source code.
Further, after the target source code for obtaining progress format checking, further includes:
Obtain preset source code format specification;
According to the configuration in the source code format specification, preset standard code format is obtained.
Further, this method further include:
Obtain the file path of target source code file;
According to the file path, the code format of target source code is determined, wherein the code format includes Linux Kernel format and application format;
According to determining code format, preset standard code format corresponding with the code format is obtained;
Format checking is carried out to the target source code according to the preset standard code format.
Further, format checking is carried out to the target source code according to the preset standard code format, comprising:
If it is determined that code format be Linux Kernel format, and the location character string be left brace, acquisition Preset standard code format be if (or else if or while or for or switch) sentence after follow directly after, or be if Logical anchor after (or else if or while or for or switch) sentence without using and package, then the format that will acquire It checks that character string is matched with the preset standard code format, when matching unsuccessful, it is unsanctioned to provide format checking Prompt information.
Further, format checking is carried out to the target source code according to the preset standard code format, comprising:
If it is determined that code format be application format, and the location character string is left brace, acquisition it is default Standard code format be if (or else if or while or for or switch) sentence after newline followed by, or be if Logical anchor after (or else if or while or for or switch) sentence use and package, then the format inspection that will acquire It looks into character string to be matched with the preset standard code format, when matching unsuccessful, provides that format checking is unsanctioned to be mentioned Show information.
Present invention also provides a kind of inspection equipment of source code format, which includes referring to for storing computer program The memory of order and processor for executing program instructions, wherein when the computer program instructions are executed by the processor, The equipment is set to execute the inspection method of aforementioned source code format.
Present invention also provides a kind of computer-readable mediums, are stored thereon with computer-readable instruction, the computer Readable instruction can be executed by processor the inspection method to realize aforementioned source code format.
Compared with prior art, scheme provided by the present application can determine location character string, and root in target source code Corresponding semantic environment and format checking character string are obtained according to location character string, further by format checking character string and standard Code format is matched, and judges whether to meet format specification requirement, thus ensure that source code format normalization with it is consistent Property, also achieve the differentiation under different semantic environments to source code format, improve source code format inspection accuracy and Integrality can improve source code format inspection for more complicated code semantic environment, and test mode is more flexible, improves The practicability of source code format Examined effect avoids the possible maloperation of automatic conversion of code, also improves developer To the reading efficiency of source code, and then improve the working efficiency of developer.
Detailed description of the invention
By reading a detailed description of non-restrictive embodiments in the light of the attached drawings below, the application's is other Feature, objects and advantages will become more apparent upon:
Fig. 1 is a kind of flow chart of the inspection method of source code format provided by the embodiments of the present application.
Fig. 2 is a kind of schematic diagram of the inspection method of preferred source code format provided by the embodiments of the present application.
Specific embodiment
The application is described in further detail with reference to the accompanying drawing.
In a typical configuration of this application, terminal, the equipment of service network and trusted party include one or more Processor (CPU), input/output interface, network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/or The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable medium Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method Or technology come realize information store.Information can be computer readable instructions, data structure, the module of program or other data. The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), moves State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable Programmable read only memory (EEPROM), flash memory or other memory techniques, read-only disc read only memory (CD-ROM) (CD-ROM), Digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or Any other non-transmission medium, can be used for storage can be accessed by a computing device information.As defined in this article, computer Readable medium does not include non-temporary computer readable media (transitory media), such as the data-signal and carrier wave of modulation.
Some embodiments of the present application provide a kind of inspection method of source code format, as shown in Figure 1, this method is specific Include the following steps:
Step S101 obtains the target source code for carrying out format checking;
Step S102 reads the target source code, searches and determines location character string;
Step S103 determines the corresponding semantic environment of the location character string and format according to determining location character string Check character string;
Step S104 carries out format checking character string preset standard code format corresponding with the semantic environment Matching provides corresponding prompt information when matching inconsistent.
The program is especially suitable for carrying out the source code that software developer submits the scene of format checking, Neng Goucong Location character string is determined in target source code, and the format checking character string in context is obtained according to location character string, then into One step matches format checking character string with standard code format, judges whether to meet format specification requirement, if be not inconsistent Format specification is closed, corresponding prompt information is provided, refers to for developer and modified accordingly.
Here, the source code format to be checked refers to the organizational form of a plurality of code in source code, in Code Edit The display format shown to user is shown as in device, different code display formats has code reading different shadows It rings, developer's efficiency when reading source code format known to oneself is higher, is easy to find code error therein, same In a software project development team, guarantees that multiple developers write code with same source code format, can be improved team Internal communication efficiency and development efficiency reduces code error rate.Here, user is identical with the meaning of developer, all refers to The related personnel of written in code and code reading.
In step s101, the target source code for carrying out format checking is obtained first.Preferably, target source code is being obtained Before, user's operation can also be monitored, when user's performance objective source code is submitted and operated, triggering obtains target source code It takes.In some embodiments of the present application, when the source code of exploitation can be submitted to code management system by software developer Source code acquisition is carried out, the source code of acquisition first carries out source code format inspection before being stored in code library, the source obtained at this time Code is target source code, and target source code is restored again into the code that code management system is responsible for maintenance after format checking passes through Library.Preferably, the functional module for being used for source code format inspection can be extended for code management system, pass through the functional module To complete the acquisition and format checking function of target source code.
In team's development process of software project, each software developer is responsible for software module in several software projects Exploitation, for convenience of the progress control for carrying out source code and source code tracking, each developer needs periodically to develop oneself Source code be submitted to code management system and carry out storage and management, common code management system includes but is not limited to such as CVS System, SVN system, Git system etc..Preferably, in some embodiments of the present application, source code is realized using Git system Storage and management, as shown in Fig. 2, code is submitted to Git system by developer, code submits operation that can trigger operation Git system A script file in system, the script file call the source code format detection solution being stored under server specified path in advance Analysis program carries out format parsing to all source code files that developer submits, here, the server specified path usually may be used For/usr/local/bin, code format detection analysis program is not the functional module that code management system initially provides, but Developer is the increased extended function module of code management system according to their own needs.
For example, can be called automatically when developer inputs git commit order under the catalogue of executable git order .git/hooks/pre-commit script, the content for script can be such that
In above-mentioned code, parseCommit is that source code format detection parsing is realized in some embodiments of the present application Program, source code for submitting to developer carries out format parsing.Developer triggers git when executing git commit Code management system executes the pre-commit script file under .git/hooks/, and this document calls the journey of parsing code format Sequence parseCommit, Sentence format is shaped like parseCommit $ changed_files, and changed_files contains this All source code files in code submission.
Preferably, after obtaining the target source code for carrying out format checking, source code format detection analysis program may be used also Preset source code format specification is obtained, and according to the configuration in source code format specification, obtains preset standard code format.Source Code format specification can be determining according to the code format demands on examination of software enterprise, developer, such as can be according to software development The relevant criterion formulation in field meets source code format specification of oneself enterprise demand etc..Here, source code format specification and generation Code management system is independent, can be used for different code management systems.
In some embodiments of the present application, source code format specification be can be reserved in XML file, the node in XML file It is corresponding with standard code format specification, source code format specification can be configured in XML node.Source code format specification XML file can be reserved under preset server path, such as/usr/ etc..
For example, source code format specification XML file can be iso_code_format_check.xml, the storage of this document Path can be/usr/gitxml/, and the content in this document can be as follows:
In above-mentioned code, TypeSetting node indicates typesetting setting, and sysparm_on value is that 1 expression switch is opened, Need to carry out the format checking of source code typesetting setting;BiOperatorSpace node indicates binary operator space, Sysparm_on value is that 1 expression switch is opened, that is, needs to carry out the format checking whether binary operator two sides have space; BracePosition node indicates brace newline, and sysparm_on value is that 1 expression switch is opened, that is, needs to carry out a left side The format checking of the whether independent newline of right brace.
In some embodiments of the present application, source code format checks that analysis program reads source code format authority file, obtains It takes source code format therein to configure, such as the configuration of BiOperatorSpace node, obtains preset mark further according to these configurations Quasi- code format.Here, preset standard code format can be stored in the form of character string, source code format inspection can not only be used for A part of data in analysis program, can also be stored in individual file, and source code format checks that analysis program is needing When from this document obtain standard code format.
In step s 102, the target source code is read, search and determines location character string.Some implementations of the application In example, code management system is after getting target source code, by searching reading one by one by character for target source code And determine location character string.Here, location character string refers to the character string for determining format checking position, it is preferable that positioning Character string can include but is not limited to following content: operator, keyword and bracket.Location character string can be according to developer couple It is configured and adjusts in the needs of source code format inspection.Operator can include but is not limited to unary operator, binary fortune Operator etc. may be, for example, '+', '-', ' * ', '/' etc..Keyword can include but is not limited to following keyword: for, if, Switch, while etc..Bracket can include but is not limited to round parentheses and brace, may be, for example: ' (', ') ', ' ', ' ' etc..
Preferably, target source code is read in character by character by way of file stream, here, mainly making by file stream mode With file flow index Fp, the source code that developer is submitted to code management system all saves in the form of a file, passes through file The movement of flow index Fp can be obtained all target source codes in source code file.In development language, file stream is referred to Back-and-forth motion of the needle Fp in source code file usually both provides corresponding power function, for example, file flow index Fp is forward Mobile usable getc function, file flow index Fp's moves backward usable fseek function and ungetc function etc..In source When code file has just passed through file flow index Fp opening, what file flow index Fp was directed toward is the head of source code file, file stream Pointer Fp moves forward the tail portion movement for being directed to source code file, and file flow index Fp, which is moved backward, is directed to source code file Head it is mobile.
In some embodiments of the present application, when file flow index Fp is moved to one character of direction, the character can be first judged Whether be operator in location character string, bracket or keyword first character, if the character is in location character string Operator or bracket, then can determine that the character is location character string;If the character is the first character of keyword, File flow index Fp is moved forward until being directed toward some termination character, by the character and its all word between termination character The character string that symbol is constituted is compared with keyword, if the character string and keyword match, it is fixed which is determined as Position character string;If the character is not location character string, file flow index Fp is moved forward into a character.
In the preferred embodiment of the application, the file stream for being directed toward the latter character can be constantly obtained by getc function Pointer, while the file flow index for being directed toward previous character is constantly obtained by the combination of fseek function and ungetc function, then The character strings of needs is saved by bufAddChar function, and judges by strcmp function the character string saved and default Standard code format corresponding character string whether there is difference, call fprintf function to print format on the screen accordingly Bomp information;Further, it is also possible to whether judge that character is expert at by the macrostatement write in advance is for sentence, or Whether person is macrodefinition sentence etc..
In step s 103, according to determining location character string, determine the corresponding semantic environment of the location character string and Format checking character string.Specifically first obtaining the file flow index for being directed toward location character string, and file flow index is being positioned It is moved forward or rearward in the context of character string, the character and default semantic environment obtained further according to file flow index determines rule Then, the corresponding semantic environment of location character string and format checking character string are determined.
In some embodiments of the present application, the word that is currently pointed to by the mobile acquisition forward or backward of file flow index Symbol, while the character string of needs can be saved in the buffer, then by the character string and preset semantic environment decision rule It is matched, if successful match, then it is assumed that meet a certain semantic environment.Here, semantic environment may include but be not limited to it is as follows: Constant name environment, constant value environment, round parentheses environment, brace environment, function declaration define environment, for statement context, note Release environment, macrodefinition environment, brace line feed environment etc..
For example, the location character string that file flow index initial position is directed toward is ' } ', presetting semantic environment judgment rule can be with Including following two rule, rule one: if location character string is ' } ', and the character of the location character string backward directions ' ' with ' N' character is non-conterminous, by backward directions first ' character string between n' character and first space character of forward direction with Character string " #define " matching, then semantic environment locating for location character string is macrodefinition environment.Rule two: if location character String is ' } ', and the character of the location character string backward directions ' { ' and ' n' character adjacent, can be found in backward directions ' ' word Symbol, then semantic environment locating for location character string is macrodefinition environment.
In the inspection of specific source code format, file flow index is persistently moved backward from location character string initial position, When being moved at first ' { ' position, it is known that it include that compound statement between ' { ' and ' } ' is over, at this time ' ' word Character in the backward directions of symbol is not ' n' character, then file flow index continues to move backward, until meet first ' n' Character, then by should ' character string between n' character and first space character of source code forward direction be saved in caching, And match the character string with character string " #define ", determine the location character string in macrodefinition if successful match Semantic environment under, and format checking character string is determined as from ' n' character until location character string ' ' between institute The character string being made of character.
In another example the location character string that file flow index initial position is directed toward is ' } ', presetting semantic environment judgment rule can Think following rule: if location character string is ' } ', and the character of the location character string backward directions ' ' character is found later It goes here and there " do ", then semantic environment locating for location character string is do-while semantic environment.
In the inspection of specific source code format, file flow index is persistently moved backward from location character string initial position, When being moved at first ' { ' position, then know to include that compound statement between ' { ' and ' } ' is over, at this time file Flow index continues to move backward, if encounter ' encounter before n' character " do " character string or encounter ' n' character it After encounter " do " character string, then can determine the location character string under the semantic environment of do-while, and by format checking The character string that all characters that character string was determined as from " do " character string until location character string between ' } ' form.
After the corresponding semantic environment of determination and format checking character string, file flow index can be moved forward or rearward Identical byte number is further continued for doing subsequent location character string forward to return to the position that initial position is directed toward location character string It searches.
Preferably, after determining semantic environment and format checking character string, can also according to the semantic environment, obtain with The corresponding preset standard code format of the semantic environment.Here, preset standard code format can have a plurality of, difference is respectively corresponded Semantic environment, preset standard code format sets according to user, can check in program and realize in source code format, It can also check that program is independent with source code format, be stored in standard code formatted file.Preset standard code format indicates The code format write that developer should follow, the code not being inconsistent with standard code format is considered as having format issues Code needs to modify according to reference format.
In step S104, by the preset standard code format progress corresponding with semantic environment of format checking character string Match, when matching inconsistent, provides corresponding prompt information.For example, preset standard code format be character string " if " and character ' (' between have a space character, the corresponding standard code format string of preset standard code format is " if (", if format checking Character string is " if (", then format checking character string standard code format string corresponding with preset standard code format is not Match, corresponding prompt information can be provided, prompt information is, for example, " FileName:fpsvc/fpsvcrxclient/ fpsvcrxclient.c Row:82Col:25Reason:pls add one space between"if"and"("!".It is preferred that Ground, as long as there is the inconsistent mistake of matching, the source code format inspection failure of source code file, this is submitted only There is a source code file source code format inspection failure occur, then this source code format inspection submitted is counted out. Developer submits again after can modifying to the file for source code format inspection failure occur.
In some embodiments of the present application, can also code spice to application layer source code and Kernel layers of source code into Row differentiation processing, the specific difference of the code spice of application layer source code and Kernel layers of source code are embodied in Kernel layers of source code Fully comply with GNU style or Linux-style, such as ' { ' usually not newline;If only a line generation after if sentence Code, then will not be used before and after code ' ' and ' ' package.The difference of this style is in fact more about there is no the regulation of hardness Fixed custom at result.Different manifestations in code format processing exist: after encountering the sentences such as if, switch, while, for ' ' simultaneously Not the case where newline, if it is Kernel layers of source code, then source code format detection analysis program can skip such case It disregards, and if it is application layer source code, then source code format detection analysis program can report code format mistake.
Preferably, processing is distinguished to the code spice of application layer source code and Kernel layers of source code, it may include such as Lower step: the file path of target source code file is obtained first;Further according to file path, the code lattice of target source code are determined Formula;According further to determining code format, preset standard code format corresponding with the code format is obtained;Last root Format checking is carried out to the target source code according to the preset standard code format.Here, the code format of target source code Including Linux Kernel format and application format.
In some embodiments of the present application, the path sections of filename are parsed when by reading input file, from And learn that this document be Kernel source code file is still application source code file.Due to application source code file It is different with the common-sense file of Kernel source code file storage path, such as Kernel layers of source generation in Android open source projects Code has a fixed storage path, and the storage path of application source code file can flexible setting, target source code can be passed through The difference of file path determines corresponding code format.Since, there are some differences, user can mention in advance in two kinds of code formats For some standard code formats corresponding with two kinds of code formats respectively, lattice are carried out to target source code according to standard code format Formula inspection.
Preferably, format checking is carried out to the target source code according to the preset standard code format, can specifically wrapped Include following method: if it is determined that code format be Linux Kernel format, and the location character string be left brace, obtain Preset standard code format be if (or else if or while or for or switch) sentence after follow directly after, or be if Logical anchor after (or else if or while or for or switch) sentence without using and package, then the format that will acquire It checks that character string is matched with the preset standard code format, when matching unsuccessful, it is unsanctioned to provide format checking Prompt information.
Preferably, format checking is carried out to the target source code according to the preset standard code format, can specifically wrapped Include following method: if it is determined that code format be application format, and the location character string be left brace, acquisition it is pre- Be marked with quasi- code format be if (or else if or while or for or switch) sentence after newline followed by, Huo Zhewei Logical anchor after if (or else if or while or for or switch) sentence use and package, then the format that will acquire It checks that character string is matched with the preset standard code format, when matching unsuccessful, it is unsanctioned to provide format checking Prompt information.
Some embodiments of the present application additionally provide a kind of inspection equipment of source code format, which includes for storing The memory of computer program instructions and processor for executing program instructions, wherein when the computer program instructions are by this When processor executes, the equipment is made to execute the inspection method of aforementioned source code format.
Some embodiments of the present application additionally provide a kind of computer-readable medium, are stored thereon with computer-readable finger It enables, the computer-readable instruction can be executed by processor the inspection method to realize aforementioned source code format.
Compared with prior art, scheme provided by the present application can determine location character string, and root in target source code Corresponding semantic environment and format checking character string are obtained according to location character string, further by format checking character string and standard Code format is matched, and judges whether to meet format specification requirement, thus ensure that source code format normalization with it is consistent Property, also achieve the differentiation under different semantic environments to source code format, improve source code format inspection accuracy and Integrality can improve source code format inspection for more complicated code semantic environment, and test mode is more flexible, improves The practicability of source code format Examined effect avoids the automatic conversion bring maloperation of code, also improves developer To the reading efficiency of source code, and then improve the working efficiency of developer.
It should be noted that the application can be carried out in the assembly of software and/or software and hardware, for example, can adopt With specific integrated circuit (ASIC), general purpose computer or any other realized similar to hardware device.In one embodiment In, the software program of the application can be executed to implement the above steps or functions by processor.Similarly, the application Software program (including relevant data structure) can be stored in computer readable recording medium, for example, RAM memory, Magnetic or optical driver or floppy disc and similar devices.In addition, hardware can be used to realize in some steps or function of the application, example Such as, as the circuit cooperated with processor thereby executing each step or function.
In addition, a part of the application can be applied to computer program product, such as computer program instructions, when its quilt When computer executes, by the operation of the computer, it can call or provide according to the present processes and/or technical solution. And the program instruction of the present processes is called, it is possibly stored in fixed or moveable recording medium, and/or pass through Broadcast or the data flow in other signal-bearing mediums and transmitted, and/or be stored according to described program instruction operation In the working storage of computer equipment.Here, including a device according to one embodiment of the application, which includes using Memory in storage computer program instructions and processor for executing program instructions, wherein when the computer program refers to When enabling by processor execution, method and/or skill of the device operation based on aforementioned multiple embodiments according to the application are triggered Art scheme.
It is obvious to a person skilled in the art that the application is not limited to the details of above-mentioned exemplary embodiment, Er Qie In the case where without departing substantially from spirit herein or essential characteristic, the application can be realized in other specific forms.Therefore, no matter From the point of view of which point, the present embodiments are to be considered as illustrative and not restrictive, and scope of the present application is by appended power Benefit requires rather than above description limits, it is intended that all by what is fallen within the meaning and scope of the equivalent elements of the claims Variation is included in the application.Any reference signs in the claims should not be construed as limiting the involved claims.This Outside, it is clear that one word of " comprising " does not exclude other units or steps, and odd number is not excluded for plural number.That states in device claim is multiple Unit or device can also be implemented through software or hardware by a unit or device.

Claims (11)

1. a kind of inspection method of source code format, wherein this method comprises:
Obtain the target source code for carrying out format checking;
The target source code is read, search and determines location character string;
According to determining location character string, the corresponding semantic environment of the location character string and format checking character string are determined;
Format checking character string preset standard code format corresponding with the semantic environment is matched, is being matched not When consistent, corresponding prompt information is provided.
2. according to the method described in claim 1, wherein, the location character string includes: operator, keyword and bracket.
3. according to the method described in claim 1, wherein, according to determining location character string, determining the location character string pair The semantic environment and format checking character string answered, comprising:
Obtain be directed toward location character string file flow index, and by the file flow index in the context of location character string to It is preceding or move backward;
The character obtained according to the file flow index and default semantic environment decision rule determine that the location character string is corresponding Semantic environment and format checking character string.
4. according to the method described in claim 3, wherein, according to determining location character string, determining the location character string pair After the semantic environment and format checking character string answered, further includes:
According to the semantic environment, preset standard code format corresponding with the semantic environment is obtained.
5. according to the method described in claim 1, wherein, acquisition carries out before the target source code of format checking, further includes:
User's operation is monitored, when user's performance objective source code is submitted and operated, triggers the acquisition to target source code.
6. according to the method described in claim 1, wherein, acquisition carries out after the target source code of format checking, further includes:
Obtain preset source code format specification;
According to the configuration in the source code format specification, preset standard code format is obtained.
7. according to the method described in claim 1, wherein, this method further include:
Obtain the file path of target source code file;
According to the file path, the code format of target source code is determined, wherein the code format includes Linux Kernel format and application format;
According to determining code format, preset standard code format corresponding with the code format is obtained;
Format checking is carried out to the target source code according to the preset standard code format.
8. according to the method described in claim 7, wherein, according to the preset standard code format to the target source code into Row format inspection, comprising:
If it is determined that code format be Linux Kernel format, and the location character string is left brace, acquisition it is default Standard code format be if (or else if or while or for or switch) sentence after follow directly after, or for if (or Else if or while or for or switch) logical anchor after sentence without using and package, then the format checking that will acquire Character string is matched with the preset standard code format, when matching unsuccessful, provides the unsanctioned prompt of format checking Information.
9. according to the method described in claim 7, wherein, according to the preset standard code format to the target source code into Row format inspection, comprising:
If it is determined that code format be application format, and the location character string be left brace, the preset standard of acquisition Code format be if (or else if or while or for or switch) sentence after newline followed by, or for if (or Else if or while or for or switch) logical anchor after sentence use and package, then the format checking word that will acquire Symbol string is matched with the preset standard code format, when matching unsuccessful, provides the unsanctioned prompt letter of format checking Breath.
10. a kind of inspection equipment of source code format, which includes the memory and use for storing computer program instructions In the processor executed program instructions, wherein when the computer program instructions are executed by the processor, make the equipment right of execution Benefit require any one of 1 to 9 described in method.
11. a kind of computer-readable medium, is stored thereon with computer-readable instruction, the computer-readable instruction can be processed Device is executed to realize method as claimed in any one of claims 1-9 wherein.
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 true CN109471634A (en) 2019-03-15
CN109471634B 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)

Cited By (7)

* 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
CN110096442A (en) * 2019-04-25 2019-08-06 深圳市码上趣学科技有限公司 Code debugging method, user equipment, storage medium and device
CN111552513A (en) * 2020-04-30 2020-08-18 中国银行股份有限公司 Character set replacing 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
CN112817876A (en) * 2021-04-19 2021-05-18 阿里云计算有限公司 Code diagnosis method, device, server, user equipment and storage medium
CN113590131A (en) * 2021-08-02 2021-11-02 中国银行股份有限公司 COBOL program code review method and device

Citations (11)

* 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
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

Patent Citations (11)

* 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
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

Cited By (9)

* 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
CN110096442A (en) * 2019-04-25 2019-08-06 深圳市码上趣学科技有限公司 Code debugging method, user equipment, storage medium and device
CN111552513A (en) * 2020-04-30 2020-08-18 中国银行股份有限公司 Character set replacing method 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
CN112817876A (en) * 2021-04-19 2021-05-18 阿里云计算有限公司 Code diagnosis method, device, server, user equipment and storage medium
CN112817876B (en) * 2021-04-19 2022-02-01 阿里云计算有限公司 Code diagnosis method, device, server, user equipment and storage medium
CN113590131A (en) * 2021-08-02 2021-11-02 中国银行股份有限公司 COBOL program code review method and device

Also Published As

Publication number Publication date
CN109471634B (en) 2021-11-16

Similar Documents

Publication Publication Date Title
CN109471634A (en) The inspection method and equipment of source code format
US11494287B2 (en) Scalable execution tracing for large program codebases
US8887135B2 (en) Generating test cases for functional testing of a software application
US20170132119A1 (en) Method and device for retrieving test case based on code coverage
US20180150742A1 (en) Source code bug prediction
US8458681B1 (en) Method and system for optimizing the object code of a program
US8719797B2 (en) System and method for debugging dynamically generated code of an application
US10945040B1 (en) Generating and providing topic visual elements based on audio content and video content of a digital video
CN107885501B (en) Method and device for obtaining mutual reference relationship of components in Android
US9311077B2 (en) Identification of code changes using language syntax and changeset data
US11327722B1 (en) Programming language corpus generation
US10203953B2 (en) Identification of duplicate function implementations
US20170054790A1 (en) System and Method for Object Compression and State Synchronization
US20150331783A1 (en) Debugging data format conversion
US11922168B2 (en) Stack traces using shadow stack
US9043803B2 (en) Converting dependency relationship information representing task border edges to generate a parallel program
CN110990346A (en) File data processing method, device, equipment and storage medium based on block chain
US20150278231A1 (en) System and method for customizing archive of a device driver generator tool for a user
US10853224B2 (en) Indexing and searching a time-travel trace for arbitrary length/arbitrary alignment values
CN114816816A (en) Collapse stack information processing method, device, equipment and storage medium
CN109426496A (en) Method, storage medium, electronic equipment and the system of program log write-in file
US20110246966A1 (en) Embedding source files into program symbol files
US9064042B2 (en) Instrumenting computer program code by merging template and target code methods
US8527481B2 (en) Methods and systems for obtaining and correcting an index record for a virtual storage access method keyed sequential data set
US10824587B2 (en) Integrated universal file converter

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