Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Call relation among functions/methods
Call relation among functions/methods [message #121943] Tue, 28 September 2004 06:04 Go to next message
Eclipse UserFriend
Hi,
I'm new to Eclipse CDT. I'm trying to develop a small tool that can
extract call relation among functions/methods. Can anybody help me on this
?. Thanks for your time
Re: Call relation among functions/methods [message #122182 is a reply to message #121943] Wed, 29 September 2004 14:28 Go to previous messageGo to next message
Eclipse UserFriend
You can implement ISourceElementRequestor and do a complete parse and watch
for the enter/exit function/method callbacks along with the acceptReference
callback.

Look at MatchLocator to see how search does something similar.

-Andrew

"ganesan" <ganesan@iese.fhg.de> wrote in message
news:cjbcv7$cq7$1@eclipse.org...
> Hi,
> I'm new to Eclipse CDT. I'm trying to develop a small tool that can
> extract call relation among functions/methods. Can anybody help me on this
> ?. Thanks for your time
>
Re: Call relation among functions/methods [message #124983 is a reply to message #122182] Mon, 25 October 2004 09:48 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
Thanks for your reply. I tried your suggestion to extract call graph from
a c file. I have a few problems in extracting call graph for a small piece
of "C" code, placed below. I have commented the problem within the code
itself. Ofcourse, my Java code which queries the Parser is also placed
below. Please let me know whether this is a problem in CDT or in my Java
code.

To extract call graph, I store the currently entered function and keep
track of list of functions that were referenced. But, I miss a few calls
(Please refer my "C" code).



class CMySourceElementRequestor extends StructuralParseCallback {

private String inputFileName = null; // file to be parsed
private String currentlyEnteredFunction = null; // name of function that
is currently entered


public CMySourceElementRequestor(File inputFileName){

this.inputFileName = inputFileName.getAbsolutePath();
}


public void acceptFunctionReference( IASTFunctionReference reference ) {

// function calls other functions
System.out.println("call " + currentlyEnteredFunction + " " +
reference.getName());
}

public void enterFunctionBody(IASTFunction function) {

currentlyEnteredFunction = function.getName();
}

public void exitFunctionBody(IASTFunction function) {

System.out.println("**** Exiting function body: " + function.getName());
function.setHasFunctionBody(true);
}

public boolean parserTimeout() {

return false;
}

public boolean acceptProblem( IProblem problem ) {

System.out.println("Parsing problem: " + problem.getMessage());
System.out.println("Problem at line: " + problem.getSourceLineNumber());
String src = new String(problem.getOriginatingFileName());
System.out.println("Originating problem in file: " + src);


return true;
}
}


public class TestCallGraph {

private final static String[] incPaths = getIncludePaths();

private File srcFile; // C file to be parsed
private CMySourceElementRequestor mySourceElementRequestor;

public TestCallGraph(File srcFile) {

this.srcFile = srcFile;
mySourceElementRequestor = new CMySourceElementRequestor(srcFile);
}

private static String[] getIncludePaths() {

String[] incPaths = new String[2];

incPaths[0] = "C:\\cygwin\\usr\\include";
incPaths[1] = "C:\\cygwin\\lib\\gcc-lib\\i686-pc-cygwin\\3.3.1\\include";

return incPaths;
}

public void printCallGraph() {

IScanner myIScanner;
IParser myIParser;

/* Create a Scanner */
myIScanner = ParserFactory.createScanner(
InternalParserUtil.createFileReader(srcFile.getAbsolutePath( )),
srcFile.getAbsolutePath(), new ScannerInfo(null, incPaths),
ParserMode.COMPLETE_PARSE, ParserLanguage.C,
mySourceElementRequestor, null, null);

/* Create a Parser */
myIParser = ParserFactory.createParser(myIScanner,
mySourceElementRequestor, ParserMode.COMPLETE_PARSE,
ParserLanguage.C, null);

if (myIParser.parse() == true) {
System.out.println("Parse successful for file: " +
srcFile.getAbsolutePath());
} else {
System.out.println("Parse unsuccessful for file: " +
srcFile.getAbsolutePath());
}
}

/* Main program */
public static void main(String[] args) {

if(args.length < 1) {
System.out.println("Usage: java TestCallGraph <absolute path to a .c
file>");
}

TestCallGraph callGraph = new TestCallGraph(new File(args[0]));
callGraph.printCallGraph();
}

}





/* Test case for call graph extractor */
#include <string.h>

typedef char ECHAR;

void myFunction()
{
ECHAR * str = (ECHAR *)"X";
ECHAR * str2 = (ECHAR *)"XX";
char * cStr = "Y";

/* myFunction calling strlen - This works correctly */
strlen(str);

/* myFunction calling strlen using ECHAR is completely missing - NOT
Working*/
if(strlen(str) + strlen(str2) <= 3) { };

/* myFunction calling strlen using cStr - This works correctly */
//if (strlen(cStr) + strlen(cStr)) { };
}

------------------------------------------------------------ ------------------


Thanks for your time.

Dharma

Andrew Niefer wrote:

> You can implement ISourceElementRequestor and do a complete parse and watch
> for the enter/exit function/method callbacks along with the acceptReference
> callback.

> Look at MatchLocator to see how search does something similar.

> -Andrew

> "ganesan" <ganesan@iese.fhg.de> wrote in message
> news:cjbcv7$cq7$1@eclipse.org...
> > Hi,
> > I'm new to Eclipse CDT. I'm trying to develop a small tool that can
> > extract call relation among functions/methods. Can anybody help me on this
> > ?. Thanks for your time
> >
Re: Call relation among functions/methods [message #125009 is a reply to message #124983] Mon, 25 October 2004 11:56 Go to previous message
Eclipse UserFriend
Hi Dharma,
It looks like there is a bug in the parser that is causing ECHAR * str =
(ECHAR *) "X";
to be parsed as an expression instead of as a declaration.
Until this is fixed, you can get around this problem by changing your
declaration of ECHAR:
typedef char * ECHAR;
.......
ECHAR str = (ECHAR)"X";

-Andrew

"dharmalingam ganesan" <ganesan@iese.fhg.de> wrote in message
news:clj06r$51q$1@eclipse.org...
> Hi,
> Thanks for your reply. I tried your suggestion to extract call graph from
> a c file. I have a few problems in extracting call graph for a small piece
> of "C" code, placed below. I have commented the problem within the code
> itself. Ofcourse, my Java code which queries the Parser is also placed
> below. Please let me know whether this is a problem in CDT or in my Java
> code.
>
> To extract call graph, I store the currently entered function and keep
> track of list of functions that were referenced. But, I miss a few calls
> (Please refer my "C" code).
>
>
>
> class CMySourceElementRequestor extends StructuralParseCallback {
>
> private String inputFileName = null; // file to be parsed
> private String currentlyEnteredFunction = null; // name of function that
> is currently entered
>
>
> public CMySourceElementRequestor(File inputFileName){
>
> this.inputFileName = inputFileName.getAbsolutePath();
> }
>
>
> public void acceptFunctionReference( IASTFunctionReference reference ) {
>
> // function calls other functions
> System.out.println("call " + currentlyEnteredFunction + " " +
> reference.getName());
> }
>
> public void enterFunctionBody(IASTFunction function) {
>
> currentlyEnteredFunction = function.getName();
> }
>
> public void exitFunctionBody(IASTFunction function) {
>
> System.out.println("**** Exiting function body: " + function.getName());
> function.setHasFunctionBody(true);
> }
>
> public boolean parserTimeout() {
>
> return false;
> }
>
> public boolean acceptProblem( IProblem problem ) {
>
> System.out.println("Parsing problem: " + problem.getMessage());
> System.out.println("Problem at line: " + problem.getSourceLineNumber());
> String src = new String(problem.getOriginatingFileName());
> System.out.println("Originating problem in file: " + src);
>
>
> return true;
> }
> }
>
>
> public class TestCallGraph {
>
> private final static String[] incPaths = getIncludePaths();
>
> private File srcFile; // C file to be parsed
> private CMySourceElementRequestor mySourceElementRequestor;
>
> public TestCallGraph(File srcFile) {
>
> this.srcFile = srcFile;
> mySourceElementRequestor = new CMySourceElementRequestor(srcFile);
> }
>
> private static String[] getIncludePaths() {
>
> String[] incPaths = new String[2];
>
> incPaths[0] = "C:\\cygwin\\usr\\include";
> incPaths[1] = "C:\\cygwin\\lib\\gcc-lib\\i686-pc-cygwin\\3.3.1\\include";
>
> return incPaths;
> }
>
> public void printCallGraph() {
>
> IScanner myIScanner;
> IParser myIParser;
>
> /* Create a Scanner */
> myIScanner = ParserFactory.createScanner(
> InternalParserUtil.createFileReader(srcFile.getAbsolutePath( )),
> srcFile.getAbsolutePath(), new ScannerInfo(null, incPaths),
> ParserMode.COMPLETE_PARSE, ParserLanguage.C,
> mySourceElementRequestor, null, null);
>
> /* Create a Parser */
> myIParser = ParserFactory.createParser(myIScanner,
> mySourceElementRequestor, ParserMode.COMPLETE_PARSE,
> ParserLanguage.C, null);
>
> if (myIParser.parse() == true) {
> System.out.println("Parse successful for file: " +
> srcFile.getAbsolutePath());
> } else {
> System.out.println("Parse unsuccessful for file: " +
> srcFile.getAbsolutePath());
> }
> }
>
> /* Main program */
> public static void main(String[] args) {
>
> if(args.length < 1) {
> System.out.println("Usage: java TestCallGraph <absolute path to a .c
> file>");
> }
>
> TestCallGraph callGraph = new TestCallGraph(new File(args[0]));
> callGraph.printCallGraph();
> }
>
> }
>
>
>
>
>
> /* Test case for call graph extractor */
> #include <string.h>
>
> typedef char ECHAR;
>
> void myFunction()
> {
> ECHAR * str = (ECHAR *)"X";
> ECHAR * str2 = (ECHAR *)"XX";
> char * cStr = "Y";
>
> /* myFunction calling strlen - This works correctly */
> strlen(str);
>
> /* myFunction calling strlen using ECHAR is completely missing - NOT
> Working*/
> if(strlen(str) + strlen(str2) <= 3) { };
>
> /* myFunction calling strlen using cStr - This works correctly */
> //if (strlen(cStr) + strlen(cStr)) { };
> }
>
> ------------------------------------------------------------ --------------
----
>
>
> Thanks for your time.
>
> Dharma
>
> Andrew Niefer wrote:
>
> > You can implement ISourceElementRequestor and do a complete parse and
watch
> > for the enter/exit function/method callbacks along with the
acceptReference
> > callback.
>
> > Look at MatchLocator to see how search does something similar.
>
> > -Andrew
>
> > "ganesan" <ganesan@iese.fhg.de> wrote in message
> > news:cjbcv7$cq7$1@eclipse.org...
> > > Hi,
> > > I'm new to Eclipse CDT. I'm trying to develop a small tool that can
> > > extract call relation among functions/methods. Can anybody help me on
this
> > > ?. Thanks for your time
> > >
>
>
>
Previous Topic:Call relation among functions/methods
Next Topic:Just my C++ projects in the C/C++ Projects
Goto Forum:
  


Current Time: Sat Jul 19 09:14:09 EDT 2025

Powered by FUDForum. Page generated in 0.03410 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top