Skip to content

Implement Advanced Function Call Detection for C Language Parser #118

@RedTanny

Description

@RedTanny

Title

Enhance search_for_called_function to support macro expansion and indirect function calls

Current implementation covers most common cases, this would add advanced edge cases

Description

The current search_for_called_function method in c_lang_function_parsers.py handles basic function call detection but skips advanced patterns that are common in real-world C codebases. Section 5 of the method is currently marked as "advanced, skip for now" but should be implemented to provide comprehensive function call analysis.

Current Implementation Status

The method currently supports:

  1. ✅ Direct function calls: callee_function(
  2. ✅ Struct member calls: obj->callee_function( or obj.callee_function(
  3. ✅ Function pointer variable calls: foo_ptr(
  4. Macro expansion and indirect calls (Section 5 - NOT IMPLEMENTED)

1. Macro Function Call Detection

Problem: Macros that expand to function calls are not detected.

Examples:

#define CALL_FUNC(func, arg) func(arg)
#define SAFE_CALL(func) if(func) func()
#define DEBUG_CALL(func) func()

void example() {
    CALL_FUNC(printf, "Hello");     // Should detect: printf
    SAFE_CALL(my_callback);         // Should detect: my_callback
    DEBUG_CALL(debug_print);        // Should detect: debug_print
}

2. Function Pointer Array Access

Problem: Function calls through arrays are not detected.

Examples:

typedef int (*func_ptr_t)(int, int);
func_ptr_t funcs[] = {add, subtract, multiply};

void example() {
    int result = funcs[0](5, 3);        // Should detect: add
    int result2 = funcs[1](10, 5);      // Should detect: subtract
}

3. Struct with Function Pointer Arrays

Problem: Function calls through struct member arrays are not detected.

Examples:

typedef struct {
    int (*ops[3])(int, int);
    int (*handler)(void);
} calculator_t;

void example() {
    calculator_t calc = {{add, subtract, multiply}, error_handler};
    int result = calc.ops[1](10, 5);    // Should detect: subtract
    calc.handler();                     // Should detect: error_handler
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions