Determining Equivalence of C/C++ Function Prototypes
Original Publication Date: 1994-Apr-01
Included in the Prior Art Database: 2005-Mar-27
Publishing Venue
IBM
Related People
Acker, LE: AUTHOR [+2]
Abstract
Disclosed is a technique for determining whether two C or C++ function prototypes are equivalent except for embedded comments and parameter names.
Determining Equivalence of C/C++ Function Prototypes
Disclosed is
a technique for determining whether two C or C++
function prototypes are equivalent except for embedded comments and
parameter names.
System Object
Model (SOM) is a technology for object-oriented
programming whereby the programmer specifies the interface to a class
of objects in one language (IDL) and the implementation of the class
in his/her preferred programming language (e.g., C or C++). The SOM
Compiler generates from the IDL interface specification a template
implementation file, a C or C++ module consisting of "stub" method
functions for each of the class's methods.
The programmer adds
application-specific code to each of the method functions in the
template, yielding a complete class implementation.
After a class
implementation has been constructed by a
programmer, the interfaces to existing methods may be modified. For
example, the types or number of parameters may be changed. When this
occurs, the SOM Compiler generates a new implementation template and
automatically merges it with the existing implementation file,
modifying the prototypes of existing method functions as needed. In
order to merge an existing implementation file with a newly
generated template implementation file, the SOM Compiler (actually
the c and xc emitter back-ends of the SOM Compiler) must be able to
determine when two method function prototypes (for the same method)
are equivalent in all respects except for embedded comments and
parameter names.
The invention
presented here consists of an algorithm for
determining whether two function prototypes are equivalent in all
respects except for embedded comments and parameter names (i.e.,
whether they represent functions have the same signature). To be
considered equivalent, the prototypes must have the same number of
parameters, the same return types, and each of the parameters must be
of the same type. The basic approach is
as follows:
Remove the comments from both prototypes (in a working copy).
Find the beginning
of the parameter lists of each of the prototypes
(the checkpoints):
Find the rightmost right
parenthesis of the prototype.
Find the matching left parenthesis
for the right parenthesis,
skipping over any intermediate
nested parenthesis, by
maintaining a count of parentheses
encountered (incrementing
the
count for each right parenthesis
and decrementing it for each
left
parenthesis; when the count becomes
zero, the matching left
parenthesis has been found).
If the
portions of the prototypes up to the start of the
parameter lists are not
equivalent except for whitespace,
then the prototypes are not
equivalent.
Repeat
get the next parameter
name from prototype 1
get the next param...