How to find out where a function is defined?
You could also do this in PHP itself:
$reflFunc = new ReflectionFunction('function_name');
print $reflFunc->getFileName() . ':' . $reflFunc->getStartLine();
How to find the file where a function is defined?
The environment()-function will return the package in which a function is "located" after it is loaded.
> environment(facet_grid)
<environment: namespace:ggplot2>
After downloading ggplot2_version_whatever.tag.gz from CRAN (or perhaps github) and expanding it, you can find (using your system text search facilities) a file named facet-grid.r that has this definiton starting at line 125:
facet_grid <- function(facets, margins = FALSE, scales = "fixed", space = "fixed", shrink = TRUE, labeller = "label_value", as.table = TRUE, switch = NULL, drop = TRUE) {
You should find more comments. Comments are dropped during compiling unless you make special efforts to retain them.
Finding out where a function is defined
It is defined in this file.
See line 64:
int name##_RemoveIndex(name##_p name, int index);
For the definition of name##
you need to dig the linked file and the documentation.
determine from which file a function is defined in python
func.__module__
Will return the module in witch it is defined
func.__globals__['__file__']
will return the whole path of the file where it is defined.Only for user defined functions
Finding out where a function was defined in zsh
Well, zsh stores the functions internally, but I guess you want to know where zsh read the function from. This can be shown by:
whence -v FUNCTIONNAME
Find out where a function comes from?
Get yourself a good IDE such as netbeans or eclipse. They have functionality to find function declarations, and also find the usages of those functions (under refactoring).
Personally I use netbeans. I simply have to ctrl-click
on a function name & netbeans will find where the function is defined, and automatically open the file for me.
Find where a python function is defined
So I've been in this exact scenario, and my process was as follows:
Scenario where file2.py includes statements like from file1 import *
.
- In file1.py, I would copy all the import statements, and paste them in file2.py
- I would copy all the top-level function/class names, and set them up as comma-delimited, and replace the
*
in file2.py:from file1 import file1_method1, file1_method2, file1_class1
.
I don't have VS Code, but I'm sure there's a way to look at the File Structure view and copy the list and reformat it into the import statement.- Repeat steps 1-2 for every
from x import *
, it's best to start from core files, and then work your way out to dependent files (reduce work for nestedimport *
statements)- Search file2.py for any
eval()
statements which may reference other modules, and manually import those. If noeval()
, then skip.- Optional: Sort the import statements (yay OCD!)
- Once this is done, I let the linter work, and remove all unused references (including duplicate imports) except those needed by
eval
, perhaps add comment for linter to ignore these.- Run your code, and pray you didn't make mistakes (nothing to worry if you didn't!)
- Repeat 1-7 for every file in your application!
- ???
- Profit!
This has been tough, but really has been worth it after all that work to trace what is being used and where in each file.
Find function definition in C++
The easiest solution would be to use grep (with find to get results very fast) like this:
find srcDir -name "*.c" -o -name "*.cpp" -print0 | xargs -0 grep "functionName"
The Makefile based solution is to change the linking so you ask for a verbose location of a function definition like this (if you use GCC) (you can also do that on the command line with "make LDFLAGS=...seebelow...")
# In your makefile, locate this:
LDFLAGS:= ...
# Replace by this
LDFLAGS:= -Wl,--trace-symbol=functionName
This results in:
$ gcc -o test main.o -Wl,--trace-symbol=main
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o: reference to main
main.o: definition of main
This solution is useful if you have plenty of similar function name, and you actually want the one that's used in the final binary.
Related Topics
Include PHP Inside JavaScript (.Js) Files
How to Only Allow Certain Filetypes on Upload in PHP
Passing JavaScript Array to PHP Through Jquery $.Ajax
PHP Mail() Function on Localhost
Run a PHP File in a Cron Job Using Cpanel
Difference Between JavaScript and PHP
: Operator (The 'Elvis Operator') in PHP
Execute PHP Scripts Within Node.Js Web Server
On Delete Cascade With Doctrine2
Pass a Variable to a PHP Script Running from the Command Line
How to Install a Specific Version of Package Using Composer
How to List All Months Between Two Dates
How to Replace Special Characters With the Ones They'Re Based on in PHP