Embodiments of the present invention relate to the field of computer software. More particularly, embodiments of the present invention relate to a software designing tool.
A coding standard is a set of rules or guidelines used when writing source code for a computer program. A coding standard according to a particular programming style may help programmers to read and understand source code conforming to the programming style, and help to avoid introducing errors.
There are many applications which come with a standard set of rules for auditing source code for a particular programming language. Although the applications may be helpful in auditing commonly known violations in the source code, they may not cater to individual needs. Furthermore, some of the applications may not allow adding additional rules to the standard set of rules. Even for those which allow the addition, the additional rules may have to be hard coded as a part of those applications or as a plug-in to those applications.
A method and apparatus for auditing source code are disclosed. In one aspect, a method for auditing source code includes generating on a display of a computing device a flowchart of a customized rule for auditing source code of a programming language using a rules builder of the computing device in response to at least one node of the programming language and at least one command associated with the customized rule applied to the flowchart, wherein the rules builder includes a graphics editor configured to generate the flowchart. The method also includes converting the customized rule into a specified data format in the computing device in response to an export command for the customized rule using the rules builder. The method further includes analyzing candidate source code of the programming language using a rules engine of the computing device based on the customized rule in response to an audit command for the candidate source code.
In another aspect, an apparatus for auditing source code includes a processor and a memory for temporarily storing a set of instructions, when executed by the processor, causes the processor to perform the method described above.
The methods and apparatuses disclosed herein may be implemented in any means for achieving various aspects, and other features will be apparent from the accompanying drawings and from the detailed description that follow.
Various preferred embodiments are described herein with reference to the drawings, wherein:
The drawings described herein are for illustration purposes only and are not intended to limit the scope of the present invention in any way.
A method and apparatus for auditing source code are disclosed. In the following detailed description of the embodiments of the invention, reference is made to the accompanying drawings that form a part hereof, and in which are shown by way of illustration specific embodiments in which the invention may be practiced. These embodiments are described in sufficient detail to enable those skilled in the art to practice the invention, and it is to be understood that other embodiments may be utilized and that changes may be made without departing from the scope of the present invention. The following detailed description is, therefore, not to be taken in a limiting sense, and the scope of the present invention is defined only by the appended claims.
The terms “analyzing” and “auditing” are used interchangeably throughout the document. Also, in the document, the term “candidate source code” refers to any source code being audited using a customized rule.
The computing device 100 may be an electronic device and includes a processor 102, a memory 104, a system storage 106 storing an operating system 108, an application storage 110 storing a graphical user interface (GUI) 112, an application 114, data 116, an input control 118 for a keyboard 120 and a mouse 122, a modem 124, a network interface 126, a display 128, etc. The processor 102 controls each component of the computing device 100 to audit source code based on one or more customized rules. The memory 104 temporarily stores instructions and data and provides the stored instructions and data to the processor 102 so that the processor 102 operates the computing device 100 to generate the customized rule(s) (e.g., using a rules builder 130 of the application 114) and auditing source code based on the customized rule(s) (e.g., using a rules engine 132 of the application 114).
The system storage 106 includes code for the OS 108 of the computing device 100. The application storage 110 includes code for the application 114 running on the OS 108 which generates the customized rule(s) and the audit source code based on the customized rule(s) as well as the data 116 associated with the customized rule(s). In one example implementation, the system storage 106 and the application storage 110 may be implemented using a single storage. In another example implementation, the GUI 112, the application 114, and the data 116 may be stored in different storage devices.
The input control 118 may interface with the keyboard 120, the mouse 122, and other input devices. The computing device 100 may receive, through the input control 118, input data necessary for creating the customized rule(s). The computing device 100 may display user interfaces in the display 128 for users to create, edit and reuse the customized rule(s). Moreover, the application storage 110 may interface with the computing device 100 directly with the bus of the computing device 100 or via the network interface 126.
In one embodiment, the computing device 100 or an apparatus for auditing source code includes the processor 102 and the memory 104 for temporarily storing a set of instructions. The set of instructions, when executed by the processor 102, causes the processor 102 to perform a method comprising generating on the display 128 of the computing device 100 a flowchart of a customized rule for auditing source code of a programming language using the rules builder 130 of the computing device 100 in response to at least one node of the programming language and at least one command associated with the customized rule applied to the flowchart, wherein the rules builder 130 includes a graphics editor configured to generate the flowchart. The method also includes converting the customized rule into a specified data format in the computing device 100 in response to an export command for the customized rule using the rules builder 130. The method further includes analyzing candidate source code of the programming language using the rules engine 132 of the computing device 100 based on the customized rule in response to an audit command for the candidate source code.
The network interface 126 and the modem 124 of the computing device 100 enable the server 204 to communicate with the clients 206 and 208 through the network 202. The network 202 may include Internet, intranet, LAN (Local Area Network), WAN (Wide Area Network), MAN (Metropolitan Area Network), etc. The communication facilities can support the distributed implementations of the present invention.
In the network environment 210 the server 204 may provide the clients 206 and 208 with software components or products under a particular condition, such as a license agreement. The software components or products may include those for generating and reusing the customized rule(s) as illustrated in
The network interface 126 and the modem 124 of the computing device 100 enable the application server 214 to communicate with the handheld device 216 through the network 212. In one embodiment of the network environment 220, the handheld device 216 may be configured to run the application 114 independently if the handheld device 216 is equipped with the application storage 110 which includes the GUI 112, the application 114, and the data 116. In another embodiment of the network environment 220, the handheld device 216 may be configured to run the application 114 using the data 116 residing in a data store 218 via the network 212 if the handheld device 216 is equipped with an application storage which includes the GUI 112 and the application 114. In yet another embodiment of the network environment 220, the handheld device 216 may be configured to run the application 114 serviced by the application server 214 using the data 116 stored in the data store 218 via the network 212 if the handheld device 216 is equipped with the GUI 112 only.
As shown in
In the example embodiment illustrated in
It is appreciated that, the constant node type may include nodes such as integer, real, string, bool enum, and template parameter. The declaration node type may include nodes such as friend, functions (e.g., global function, member function, etc.), parameter, and variables (e.g., global variable, local variable, member variable, etc.). The expression node type may include nodes such as assignment (e.g., a=b, â=b, a%=b, etc.), bitwise (e.g., a&b, ˜a, âb, etc.), comparison (e.g., a>b, a==b, etc.), logical (e.g., !a, a&&b, etc.), numerical (e.g., +a, −a, %a, a*b, etc.), and miscellaneous (e.g., a(b), a,b, a.b, etc.).
The statement node type may include nodes such as if, goto, block, try, break, empty, simple, catch, while, do while, continue, label, for, and switch. The name space node type may include nodes such as name space and using. The type node type may include nodes such as complex (e.g., template parameter, array, class, enum, function, etc.) and primitive (e.g., bool char, double, float, int, etc.). The general node type may include nodes such as base type, argument, file, and template argument
As illustrated in
The rule ID field 416 allows the user to assign a unique rule ID for the customized rule. The rule label field 418 allows the user to assign a name for the customized rule. The author field 420 allows the user to provide an author name or a group name associated with generating of the customized rule. The severity field 422 facilitates the user to choose a severity category (e.g., recommendation, warning, severe, etc.) based on which the customized rule is classified.
In the example embodiment illustrated in
For example, the command may be a modify, an output, a delete, a delete child, a create logic and a change logic in type. For example, the modify command allows the user to modify one or more nodes displayed in the flowchart 424. The output command allows the user to configure an error message to be displayed if the customized rule is violated. The delete command enables the user to delete selected one or more nodes in the flowchart 424. The delete child command enables the user to delete selected child node(s) 428 in the flowchart 424.
The create logic command enables the user to create logic in the flowchart 424 while generating the child nodes 428. The change logic command enables the user to change the type of logic operator used in a particular node in the flowchart 424. For example, the user can change an AND operator to an XOR operator using the change logic command. In one exemplary implementation, the command 436 is captured using the MDR. The node property 438 may be arguments, body, catch, condition, constructor initialization list, context, default, dimension, else, entity, FalseChoice, filename, HasElse, HasForwardDecl, HasMultipleParents, HasVoid, etc.
In the example embodiment illustrated in
Further, the first child node 430 is generated for filtering all assignment statements inside condition of the “if” statement. The first child node 430 is generated by applying the command “create logic” and the node property “condition”, and in response to selection of a node “a=b” from the node type “expression” based on the node property “condition”. Furthermore, the second child node 432 is generated for filtering a variable of a left hand side part of the assignment statement. The second child node 432 is generated by applying the command “create logic” and the node property “left hand side”, and in response to selection of a node “variable” from the node type “declaration” based on the node property “left hand side”.
Moreover, as illustrated in
In one embodiment, the GUI 502 enables the user to analyze the candidate source code 604 based on the customized rule 602 in response to the selection of the audit command button 606. In the example embodiment illustrated in
Further, based on the analysis of the candidate source code 604, the GUI 502 outputs a result of analysis of the candidate source code 604 with respect to the customized rule 602. In one embodiment, the GUI 502 displays a violation by the candidate source code 604 if the customized rule 602 is violated by the candidate source code 604. For example, the GUI 502 displays the violation as an error message (e.g., configured by the user using “output” command while generating the flowchart 424).
In one embodiment, the flowchart of the customized rule is generated by generating a parent node on the flowchart in response to a selection of a first one of the node and respective properties applied to the first one of the node. Further, the flowchart of the customized rule is generated by generating a child node dependant on the parent node, and applying a command and a node property to each of the child node.
In step 704, the customized rule is converted into a specified data format using the rules builder in response to an export command for the customized rule. Further, in step 706, candidate source code of the programming language is analyzed using a rules engine of the computing device based on the customized rule in response to an audit command for the candidate source code. Moreover, in one example embodiment, a computer readable medium, for generating a customized rule for auditing source code, has instructions that, when executed by a computer, cause the computer to perform the method illustrated in
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present disclosure is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and features disclosed herein.