Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to unparse type declarations? #237

Open
david-c-wong opened this issue Jul 11, 2023 · 2 comments
Open

How to unparse type declarations? #237

david-c-wong opened this issue Jul 11, 2023 · 2 comments
Assignees

Comments

@david-c-wong
Copy link

I have written an outliner for a code region to a new source file with that code region put in a function. In order for this new source file to be compilable, I need to include all type declarations needed for that code region. I have successfully collected all the types referenced.

Are there some utilities I can use to unparse the type declaration taking care of the order of type declaration in the presences of various C/C++ language features like namespace, typedef, nested type declaration, etc?

Thanks a lot!

@chunhualiao
Copy link
Contributor

Hi, we already have an outliner. It has some support of moving dependent declarations into the newly generated source file containing the outlined code region enclosed in a function. We have a development branch which has even better support for this feature but there is no timeline to merge it.

The relevant function is:
SageInterface::appendStatementWithDependentDeclaration(func,glob_scope,func_orig,exclude_headers);

The example use in line 636 of https://github.com/rose-compiler/rose/blob/weekly/src/midend/programTransformation/astOutlining/Transform.cc

For more information about the outliner, please check: https://en.wikibooks.org/wiki/ROSE_Compiler_Framework/outliner

@chunhualiao chunhualiao self-assigned this Jul 18, 2023
@david-c-wong
Copy link
Author

Thanks for the suggestion. Since there is an Outliner already implemented by you all, I am thinking of using that for my work. I may need to customize it a bit to insert a few function calls before and after the outlined function. Is it easy to do?

I also tested a simple program (adapted from the array1.c) and encountered an issue. Below is the code:

typedef struct {
        int x;
} MyType;

void foo()
{
  int i,j=100, sum[100];
  MyType bar;
#pragma rose_outline
  for (i=0;i<100;i++)
  {
    sum[i] =i*2+j + bar.x;
  }

#pragma rose_outline
  for (i=0;i<100;i++)
  {
    sum[i] =i*2+j;
  }

}

Then I run the outliner using the following command
/usr/rose/bin/outline -rose:outline:new_file -rose:outline:exclude_headers array1.c

and got some error due to type declaration of second outlined code:

void OUT__2__2158__(int *ip__,int *jp__,int (*sump__)[100],void *barp__);
/* REQUIRED CPP DIRECTIVES */
/* REQUIRED DEPENDENT DECLARATIONS */
typedef struct {}MyType;

struct 
{
  int x;
}
;
/* OUTLINED FUNCTION */

void OUT__2__2158__(int *ip__,int *jp__,int (*sump__)[100],void *barp__)
{
  int *i = (int *)ip__;
  int *j = (int *)jp__;
  int (*sum)[100] = (int (*)[100])sump__;
  MyType *bar = (MyType *)barp__;
  for ( *i = 0;  *i < 100; ( *i)++) {
    ( *sum)[ *i] =  *i * 2 +  *j + ( *bar) . x;
  }
}

Is this issue fixed already? I am running ROSE 0.11.125.0.

Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@chunhualiao @david-c-wong and others