Giter VIP home page Giter VIP logo

koknat / callgraph Goto Github PK

View Code? Open in Web Editor NEW
197.0 7.0 25.0 612 KB

A multi-language tool which parses source code for function definitions and calls

License: GNU General Public License v3.0

Perl 94.15% Awk 0.24% C++ 0.24% Go 0.37% Java 0.34% JavaScript 0.28% PHP 0.29% Python 0.25% Ruby 0.22% Swift 0.29% Tcl 0.34% MATLAB 0.28% R 0.24% Kotlin 0.19% Rust 0.19% Shell 0.22% Dart 0.23% Scala 0.13% Lua 1.21% BASIC 0.32%
callgraph basic fortran golang lua javascript kotlin matlab r rakulang

callgraph's People

Contributors

cosmojg avatar dhaizei avatar dimitripapadopoulos avatar koknat avatar thegoatinthemachine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

callgraph's Issues

Scan all files in (sub)folder(s)

It seems a nice tool with the graph and all.
Would it be an interesting feature to scan all files (of a certain language) in a folder (and if wished all subfolders?).
It would require to generate a list of all functions per file per folder, as well as a list of all function-calls per function.
I was thinking of programming something like that my self but i am still in the phase of "make or find".

Does not recognise all R function definitions

When scanning code in R files, callGraph searches for function definitions using the regex

 ^(\s*)()(\w+)\s+<-\s+function\s*\(.*\)

Newlines between arguments

The . wildcard doesn't match newlines, so this fails to detect function definitions like:

example_function <- function(a_long_argument_name,
                             another_rather_long_argument_name,
                             a_third_argument)...

An alternative would be to replace . with the character set matching everything except closing parentheses ([^\)]):

 ^(\s*)()(\w+)\s+<-\s+function\s*\([^\)]*\) 

Use of = instead of ->

Whilst using <- for assignment is preferred, = may be used. Any functions defined in this way will not be recognised.

This could be fixed by replacing the <- with (<-|=).

javascript's fat arrow functions support

Hi,
it doesn't seem to support fat arrow functions in javascript.
My code looks like this:

const setOrderItems = (formItems) => {

callGraph: ERROR: Could not find any function definitions in your file

Specify path + function name with -start option

Hello @koknat thank you very much for this tool!

Is it somehow possible to specify the path to the file in combination with the function name in the -start option?
e.g. ./callGraph . -start 'src/subfolder/main.go#update' -language 'go'

I would like to generate a call graph for a specific function but the same name is used in different files of my application.

language fortran is not supported

ERROR:  Language '' not recognized.  Specify it with  -language <language>
        For example:  -language pl
        For example:  -language py
        For example:  -language tcl
        Supported languages are:  awk bas c cpp dart for go java jl js kt lua m pas php pl py r rb rs sc sh swift tcl ts v

class question

i find it couldn't find class,
such as
class A:
def init(self):
pass
def forward(self):
pass
only identity functions,

[Python] functions with the same name but different classes

it is currently not possible to differentiate methods with the same name but from different classes in the same file.

Example:

class ClassA:
    def method_name(self):
        return 0
    
class ClassB:
    def method_name(self):
        return 0


if __name__ == '__main__':
    ClassA.method_name()
    ClassB.method_name()

callGraph output:

{
    "teste/multiple_functions.py:method_name": {
        "called_by": {
            "teste/multiple_functions.py:__MAIN__": 1
        }
    },
    "teste/multiple_functions.py:__MAIN__": {
        "calls": {
            "teste/multiple_functions.py:method_name": 1
        }
    }
}

Could it generate file level dependency?

Hi, I have two questions around the tool, thanks for your info.

  1. Does it generate json or xml format output that could be consumed by code?
  2. Does it generate file level dependency with corresponding file path info? For example flask repo has a test file tests/test_appctx.py that has the following import statements:
import pytest
import flask
from flask.globals import app_ctx
from flask.globals import request_ctx

I am looking for output of file level dependency like the following:

"tests.test_appctx": {
    "imports": [
      "flask",
      "flask.globals",
      "pytest"
    ],
    "name": "tests.test_appctx",
    "path": "/Users/myuserid/python/flask/tests/test_appctx.py"
  },

Can't install dependencies (GraphViz)

root@6f38527114dc:/# cpan install GraphViz
Loading internal logger. Log::Log4perl recommended for better logging
Reading '/root/.cpan/Metadata'
Database was generated on Tue, 29 Nov 2022 08:41:02 GMT

(error): Could not expand [GraphViz]. Check the module name.
(info): I can suggest names if you install one of Text::Levenshtein::XS, Text::Levenshtein::Damerau::XS, Text::Levenshtein, and Text::Levenshtein::Damerau::PP
(info): and you provide the -x option on invocation.
(error): Skipping GraphViz because I couldn't find a matching namespace.

Use GraphViz2 rather than GraphViz Perl module?

I just learned of this project today, and it's really cool!

Thought you'd be interested to know of the GraphViz2 module, which may make things easier/better in this script. Example usage:

From https://github.com/PDLPorters/pdl/blob/master/perldl#L335-L338:

  my $g = PDL::Core::pdumpgraph(PDL::Core::pdumphash($pdl));
  require GraphViz2;
  my $gv = GraphViz2->from_graph(PDL::Core::pdumpgraphvizify($g));
  $gv->run(format => $format, output_file => $file);

The general idiom is you make a Graph object, then annotate it (e.g. with a graphvizify procedure such as https://github.com/PDLPorters/pdl/blob/ac270e21cafeda8726dd64fa4b90e4a6e686c8c2/Basic/Core/Core.pm#L2394-L2439), then GraphViz2 can run with it.

Running callGraph on mac

Hi there,

This is a very useful looking tool, but I'm having trouble running it on mac.

I've run brew install graphviz as well as sudo cpan install GraphViz, copied callGraph's executable into /usr/local/Cellar/graphviz/2.48.0/bin, and called it like so, with the following error:

macbook ~ % callgraph /Users/username/Developer/Project/FileToGraph.swift
ERROR: Install GraphViz and the CPAN GraphViz module to create the call graph
sudo apt-get install Graphviz
and
sudo cpan install GraphViz

Am I doing something wrong? Is it possible to use callGraph on macOS?

Thanks,
Luke

-ymlOut and -ymlIn produce different results than a normally targeted run

Expected behavior: using -ymlOut and -ymlIn should produce a .dot graph which has the same features as running callGraph against a file or directory.

Actual behavior: callGraph -ymlIn $previously_produced_yml produces a .dot graph whose nodes lack the filenames where the referenced functions exist.

I cannot run call graph on my mac

Hi,

I am a rookie in this, but I want to get this tool works.
I saw the issue of luke: #1.
I tried following his advice but that don't work.

  1. brew install graphviz. I get this error:

Warning: No available formula with the name "graphviz".
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
It was migrated from homebrew/cask to homebrew/core.

  1. sudo cpan install GraphViz. I get this message:

Configuring R/RS/RSAVAGE/GraphViz-2.24.tgz with Makefile.PL
Can't exec "dot": No such file or directory at Makefile.PL line 21.
Please install Graphviz from http://www.graphviz.org/.
No 'Makefile' created RSAVAGE/GraphViz-2.24.tgz
/usr/bin/perl Makefile.PL -- NOT OK

  1. I downloaded the github from callGraph, perl_call_graph, graphviz-perl, and IPC-Run but don't know what to do with them.

Is someone that can help me?

Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.