Skip to content

Implement function-like macros#89

Merged
nanonyme merged 5 commits intomainfrom
copilot/design-function-like-macros
Feb 19, 2026
Merged

Implement function-like macros#89
nanonyme merged 5 commits intomainfrom
copilot/design-function-like-macros

Conversation

Copy link
Contributor

Copilot AI commented Feb 19, 2026

The preprocessor supported only object-like macros (#define FOO value). This adds function-like macros with parameters.

Changes

Core implementation:

  • Added FunctionLikeMacro class to represent macros with parameters and body
  • Modified process_define to detect function-like macros (immediate ( after name) and parse parameter lists
  • Enhanced TokenExpander to:
    • Detect macro invocations (name followed by ()
    • Extract arguments with parenthesis depth tracking
    • Expand arguments recursively before substitution
    • Maintain recursion guards per-expander instance

Behavior:

  • Arguments are fully expanded before substitution into macro body (enables nested calls)
  • Macro name without () is not expanded (treated as identifier)
  • Malformed definitions fall back to object-like behavior

Example

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define SQUARE(x) ((x) * (x))

MAX(1, 2)           // expands to: ((1) > (2) ? (1) : (2))
SQUARE(SQUARE(3))   // expands to: ((((3) * (3))) * (3))
MAX                 // not expanded (no parentheses)

Documentation

Updated README to document function-like macro support, including limitations (no stringification # or token pasting ## operators).

Original prompt

This section details on the original issue you should resolve

<issue_title>Function-like macros</issue_title>
<issue_description>- [ ] Design system for expanding function-like macros

  • Update readme to align with current capabilities </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.90%. Comparing base (1ef46e6) to head (98e6df8).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #89      +/-   ##
==========================================
+ Coverage   97.53%   97.90%   +0.37%     
==========================================
  Files           7        7              
  Lines         648      763     +115     
  Branches      127      160      +33     
==========================================
+ Hits          632      747     +115     
  Misses         10       10              
  Partials        6        6              
Files with missing lines Coverage Δ
simplecpreprocessor/core.py 96.40% <100.00%> (+0.51%) ⬆️
simplecpreprocessor/tokens.py 97.80% <100.00%> (+1.47%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI and others added 4 commits February 19, 2026 09:06
Co-authored-by: nanonyme <348449+nanonyme@users.noreply.github.com>
Co-authored-by: nanonyme <348449+nanonyme@users.noreply.github.com>
Co-authored-by: nanonyme <348449+nanonyme@users.noreply.github.com>
Co-authored-by: nanonyme <348449+nanonyme@users.noreply.github.com>
Copilot AI changed the title [WIP] Design system for function-like macros Implement function-like macros Feb 19, 2026
Copilot AI requested a review from nanonyme February 19, 2026 09:16
@nanonyme nanonyme marked this pull request as ready for review February 19, 2026 09:17
@nanonyme nanonyme merged commit bf78817 into main Feb 19, 2026
6 checks passed
@nanonyme nanonyme deleted the copilot/design-function-like-macros branch February 19, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Function-like macros

2 participants