Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camlp4MacroParser executes "DEFINE" directives in the "false" branch of an IFDEF; other Camlp4MacroParser improvements #4262

Closed
vicuna opened this issue Apr 17, 2007 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Apr 17, 2007

Original bug ID: 4262
Reporter: nogin
Assigned to: ertai
Status: closed (set by @xavierleroy on 2010-04-29T12:18:08Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.10+dev
Fixed in version: 3.10+dev
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues
Monitored by: nogin

Bug description

As I wrote to the Caml list yesterday, I have noticed that the Camlp4MacroParser in 3.10.0+beta has an unfortunate problem - when processing an "IFDEF" (or "IFNDEF") directive, it will execute the "DEFINE"s in both branches, regardless of whether the test is true or not (this was caused by the fact that the DEFINE directives would be executed eagerly at parse-time).

Attached is a corrected and improved version of the Camlp4MacroParser:

  • Fixes the above problem; now the execution of the "DEFINE" directives inside IFDEF/IFNDEF is correct.

  • Adds support for "local" definitions
    DEFINE = IN
    This is particularly useful for things like

    DEFINE body =
    ...
    IN
    IFDEF DEBUG
    let result = body in
    print_debug result;
    result
    ELSE
    body

  • Adds an ability to omit the "ELSE" part of the IFDEF/IFNDEF expressions (the "ELSE" branch is then taken to default to unit expression "()").

  • Adds an ability to use the macro argument as a pattern (provided the argument is a sufficiently simple expression)

  • Adds a special macro "NOTHING" that can be used to "wipe out" unneeded function arguments. This is useful to be able to generate functions of different arity using the same macro.

The improved Camlp4MacroParser.ml is attached.

Aleksey

File attachments

@vicuna
Copy link
Author

vicuna commented Apr 17, 2007

Comment author: ertai

Fixed in CVS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant