CODE SEQUENCE DETECTION

Abstract: Software clones in a large software package, e.g. DMS operating software are identified from the physical layout of the source code and/or from the occurrence frequency and distribution of keywords in the code. These features are used to define multicomponent vectors which are input to a neural network. The output of the network comprises a histogram analysis of the various code sequences (potential clones) in the source code.

Description: CODESEQUENCEDETECTION This invention relates to a method and apparatus for software code sequence, e.g. for the detection of software clones. Current software packages for system control, e.g. for the control of a digital telephone system, are becoming increasingly complex. Packages incorporating millions of lines of code are not unusual. A particular problem that has been experienced with such system control packages is that of identifying particular sequences or 'lumps' of code which may have been prepared by cloning a corresponding sequence. This form of analysis is desirable for a number of reasons. Firstly it may be possible to replace a number of substantially identical code sequences by a single sequence thus achieving an overall code reduction. This can save both on storage space and running time. Secondly, coding errors or bugs may manifest themselves in software from which cloned sequences have been derived. The more obvious coding errors can often be identified and corrected before the software is installed, but more subtle errors can remain undetected, sometimes for several years, until a particular set of service conditions brings them to light. This may have catastrophic results leading to a crash of the entire system with consequential loss both of service revenue and customer confidence. Current source code software development generally involves re¬ use of existing utility sized portions or lumps of existing code. These existing software lumps may comprise anything from a single line to a large number of lines and may provide e.g. a function or a group of functions. The re-use of source code is generally referred to as cloning wherein:- 1. An identical copy is made. 2. Changes in variable names are made. 3. Lines of code are added/deleted. 4. Recombinations of existing software lumps are produced. This list is not, of course, exhaustive but it includes the more commonly produced clones. If for example a software fault is subsequently identified in one of these cloned packages it is of course important that all the clones of that package can be identified so that appropriate remedial action can be taken. It will be appreciated that searching for clones in a large software package can be a very difficult and time consuming operation, particularly if significant modification of a clone has been effected. As software is developed, it is a common occurrence for a particular package to be written in a more compact and efficient form. If the package has been previously cloned, the benefits of code reduction cannot be passed on to the clone until these have been identified. In a large software package containing many clones there may be a considerable benefit to be obtained by code reduction. The object of the present invention is to provide an improved method and apparatus for the analysis of software packages. According to one aspect of the invention there is provided a method of analysing a software package comprising a plurality of code sequences, the method including providing a neural network adapted to examine the code sequences whereby to identify said code sequences. According to the invention there is further provided a method of analysing a software package comprising a plurality of code sequences, the method comprising generating for each said code sequence a corresponding vector having a predetermined number of components, and providing a neural network having inputs one for each said vector component, said neural network being adapted to provide an output, responsive to each said input vector, indicative of the code sequence from which that vector is generated. According to another aspect of the invention there is provided apparatus for analysis of a software source code package comprising a plurality of code sequences, the apparatus including a neural network having a plurality of inputs and outputs, and means for generating vectors one for each said code sequence and each said vector having a plurality of components equal to the number of inputs of the neural network, wherein the neural network us adapted to provide an output responsive to each said vector and indicative of the code sequence from which that vector has been generated. The neural network examines the source code sequence whereby to identify sequences of similar or identical construction. The technique has the advantage that there is no need for any prior knowledge of which particular sequences are to be searched for. An embodiment of the invention will now be described with reference to the accompanying drawings in which:- Fig. 1 is a schematic diagram of a neural network arrangement; Fig. 2 shows in highly schematic form an apparatus for source code sequence analysis; Figs. 3 and 4 illustrate a procedure for preliminary analysis of a source code sequence by examination of the pattern or layout of the code; Fig. 5 is a histogram diagram illustrating a typical output for the apparatus of Fig. 5; and Fig. 6 shows a further apparatus for source code sequence analysis. Referring to Fig. 1 , this illustrates in schematic form the general construction of a neural network. The arrangement shown is of the type known. as a self organising map (SOM) although it will be appreciated that other types of network may be employed. The network comprises a matrix of neurons (11 the Kohonen layer) each of which neuron is coupled to the network inputs IP1 to IP3. For simplicity only three neurons and three inputs are shown, but it will be appreciated that in practise the network will be far more extensive. Each neuron performs a computational operation on the inputs that it receives. Typically this operation comprises the evaluation of a unique weighted run of the inputs. The network then performs a 'voting' process such that one neuron, i.e. the neuron with the highest weighted sum, is activated to generate a signal at the corresponding output. Referring now to Fig. 2, this illustrates an apparatus for the analysis of a source code sequence. The apparatus operates on successive sections of the source code to generate, for each section, a multicomponent vector characteristic of some feature of that section of code. The derivation of this vector will be described in further detail below. The components of this vector are fed each to a corresponding input of a neural network, e.g. a self organising map. In response to this input vector, one neuron of the network is activated to enable one of the network outputs, that output being indicative of the nature of the particular code sequence being examined. As discussed above, we prefer to employ a self organising map in the neural network. This has a topology preserving property such that input vectors that are near to each other in a Euclidean sense are mapped near to each other by the network. In addition, no programming of the network is required as it organises itself without any need to 'know' what the required answer may be. The characteristic vector may be generated from the source code sequence in a number of ways. One example is illustrated in Fig. 3 and 4 which illustrate the way in which a vector may be derived from the physical layout or pattern of line lengths of the code. Referring first to Fig. 3, the left hand portion shows a typical code sequence forming part of a large software package. The right hand portion of Fig. 3 is an abstract representation of that sequence in which each symbol is replaced e.g. by an asterisk. This abstract procedure is then used to derive a vector from its physical pattern. The derivation of the vector may be effected by one or more of the following characteristics of the abstract procedure:- 1. Change in indentation direction from line to line of the source code. 2. Indentation direction for each line. 3. Absolute line indentation. 4. Absolute line length. Other features of the code pattern or layout may also be employed. When a particular sequence is too long or too short to be accommodated, this mismatch may be overcome by truncation or by the insertion of padding components respectively. Characteristic vectors may also be derived from other features of the code sequence. For example, the frequency of occurrence of particular keywords may be determined. Thus, in the actual procedure of Fig. 3, one might determine the occurrence frequency and distribution of keywords such as 'coding-string', '.fwui' and so on. Depending on the software involved, each vector generation technique may be used alone or together with other techniques to determine the particular vector of the software. The output of the apparatus of Fig. 2, i.e. the cumulative results of the vecting operation of the neural network for each successive input vector, is illustrated in the histogram of Fig. 5. In effect the apparatus of Fig. 2 clarifies the various code sequences in the software package into groups (A, B, C ...) of similar or identical sequences. Within each group, each identical sequence can be regarded as a potential clone of a particular code sequence. It should be noted that the neural network performs this classification operation without any prior knowledge of the type of clone for which it may be searching. A further, somewhat more complex apparatus for analysing a software package is shown schematically in Fig. 6 of the drawings. In this arrangement two vectors are derived from each code sequence, one from the layout and the other from keywords as described above. Each vector is fed to a corresponding self-organising map (SOM-layout and SOM- keywords). The outputs from each self-organising maps are then fed to a further self-organising map (SOM-Network) the output of which is of the histogram form illustrated in Fig. 5.

Claims: CLAIMS: 1. A method of analysing a software package comprising a plurality of code sequences, the method comprising generating for each said code sequence a corresponding vector having a predetermined number of components, and providing a neural network having inputs one for each said vector component, said neural network being adapted to provide an output, responsive to each said input vector, indicative of the code sequence from which that vector is generated. 2. A method as claimed in claim 1 , wherein each said vector corresponds to the physical layout of the code sequence. 3. A method as claimed in claim 1 , wherein said vector corresponds to the frequency and distribution of keywords in said code sequence. 4. A method as claimed in claim 2 or 3, wherein said neural network comprises a self-organising map. 5. Apparatus for analysis of a software source code package comprising a plurality of code sequences, the apparatus including a neural network having a plurality of inputs and outputs, and means for generating vectors one for each said code sequence and each said vector having a plurality of components equal to the number of inputs of the neural network, wherein the neural network is adapted to provide an output responsive to each said vector and indicative of the code sequence from which that vector has been generated. 6. An apparatus as claimed in claim 5, wherein said vector generation means is adapted to generate vectors corresponding each to the physical layout of a said source code sequence. 7. An apparatus as claimed in claim 5, wherein said vector generation means is adapted to generate vectors corresponding to the frequency and distribution of keywords in a said source code sequence. 8. An apparatus as claimed in claim 6 or 7, wherein the neural network comprises a self-organising map.

Inventors: CARTER SUSAN, TANSLEY DENNIS STEWART WILLIAM, CARTER, SUSAN, TANSLEY, DENNIS, STEWART, WILLIAM
Applicants: CARTER SUSAN, NORTHERN TELECOM LTD, TANSLEY DENNIS STEWART WILLIAM, CARTER, SUSAN, NORTHERN TELECOM LIMITED, TANSLEY, DENNIS, STEWART, WILLIAM
Application year: 1994
Main classification: G06F11
IPC codes: G06F9, G06F11, G06F15, G06N1