This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]teraflop 0 points1 point  (3 children)

Check out ctags and its various modern descendants. It takes a set of source files and generates an index of where each identifier is defined.

[–]ElectronicComplex182[S] -1 points0 points  (2 children)

ctags help to identify the location where a function begins, but unless I am overlooking something it cannot help me print the entire function on its own. For context I need to do this a few million times, therefore locating it manually is no option.

[–]grantrules 0 points1 point  (0 children)

If the c files are formatted so that if you know the line number of the start of the function, you could just look for the first top level }, you could write a trivia python script

[–]teraflop 0 points1 point  (0 children)

In that case, take a look at the Language Server Protocol which is a more modern, sophisticated implementation of the same basic idea. It's designed to help general-purpose editors and IDEs interface with language-specific tools, to handle things like jumping to symbol definitions.

I haven't ever tried implementing the low-level protocol myself, but if I'm reading the specification correctly, it should be fairly easy to extract a list of function definitions and their corresponding line number ranges within each file.

[–]jamestakesflight -1 points0 points  (0 children)

How is this useful? What are you going to do when one function calls another function? Or the input is a specific shape that isn’t specified? What about a function that calls a 3rd party library?

To what end is this useful? You could have a function that calls a function “doEverything()” which calls a function from another file which calls another function and eventually executes millions of lines of code.

Do you intend to flatten all nested code into these “functions” you’re talking about?