Help me!


I think that this is a bug:

When I create a new variable with the type of an old variable,
normally everything works fine.  Things get funny when the old type is a pointer
to a function.  The new variable is declared to be of the type of the
function, not to be a function of that type.  

Heh heh.

I think the following example will be more illustrative than my tangled tongue:

Original file:

    		int original1;
    		int *original2;
    		int (*original3)();
    		int original4();
The new file, where I created copies of every variable that is declared:

       		int original4_copy;
       		int  *original3_copy;
       		int  *original2_copy;
       		int original1_copy;
       		int original1;
       		int  *original2;
       		int  (*original3)();
       		int original4();

original3_copy and original4_copy shoud be declared

	int original4_copy();
	int (*original3_copy)();

Yikers.   I have looked and looked and cannot find the problem.  It seems
that the T_FUNCTION is in the type of the new declaration, but it is not being
printed out.  Of course, Tool_Unparse2_LLnode() (or whatever it is called)
must be able to handle it, since it is printing out the original3 variable

Help me please!  Here is the source code for this example:

------------- Source Code Begins Here ---------------------
#include <stdio.h>
#include <strings.h>
#include <malloc.h>
#include "sage++user.h"

extern "C" {
    int exit(int);

make_new_decls(SgStatement *first_stmt) {

    SgStatement *current_stmt = first_stmt;
    SgStatement *current_scope = first_stmt;
    SgVarDeclStmt *var_decl;
    SgType *type;

    int variant;

    char *new_symbol_name;
    char *old_symbol_name;

    SgVariableSymb *new_symbol;
    while (current_stmt) {
	variant = current_stmt->variant();
	if (variant == FUNC_HEDR) {
	    current_scope = current_stmt;
	if (variant == VAR_DECL) {
	    var_decl = (SgVarDeclStmt *) current_stmt;

	    /* Get the type using Maur's trueType().  The function */
	    /* problem still happens with type() alone.            */
	    type = var_decl->symbol(0)->type()->getTrueType();

	    /* Make a name oldname_copy */
	    old_symbol_name = var_decl->symbol(0)->identifier();
	    new_symbol_name = (char *) malloc (strlen(old_symbol_name) + 6);

	    /* Make the new symbol, and then declare it */
	    new_symbol = new SgVariableSymb(new_symbol_name,



main(int argc, char *argv[])
    SgProject *P;
    SgFile *current_file;
    FILE *output_file;
    char *output_file_name;
    char *last_period;

    int num_files;
    int num_functions;
    int i,j;
    if (argc < 2) {
	fprintf(stderr, "Syntax : bug projectname\n");

    fprintf(stdout,"Opening and initializing project : %s\n", argv[1]);
    P = new SgProject(argv[1]);

    num_files = P->numberOfFiles();

    fprintf(stdout,"Here are the files in %s : \n",argv[1]);

    for (i = 0; i < num_files ; i++) {

	current_file = &(P->file(i));

	/* Put the code in a simpler form to make instrumentation easy */

	make_new_decls(current_file -> firstStatement());

	fprintf(stdout,"\t\tRestructured code... \n");

	output_file_name = (char *) malloc (strlen(P->fileName(i)) + 7);

	/* copy up to the last period */
	last_period = strrchr(P->fileName(i),'.') ;

		last_period - P->fileName(i));

	output_file = fopen(output_file_name,"w");

	/* Unparse the scanned program to the output file */
	fprintf(stdout,"\t\tUnparsing to %s\n\n",output_file_name);
------------- Source Code Ends Here ---------------------

"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety."
		-- Benjamin Franklin, 1759