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

Ignore #ifd out unknown directives. #427

Merged
merged 1 commit into from
Jun 29, 2019

Conversation

Y-Less
Copy link
Member

@Y-Less Y-Less commented Jun 16, 2019

Fixes #426

Makes the compiler slightly more future-proof by allowing us to do something like:

#if __Pawn >= 0x03AB
    #message You're on a nice new compiler.
#endif

Currently to do that you need to do:

#message You're on a nice new compiler.
#if __Pawn >= 0x03AB
    #include "message.inc"
#endif

Or you get an error that #message (or anything else) is an unknown directive if the compiler doesn't recognise it, even if it is disabled.

The only downside to this is that it makes it slightly harder to add new #if-like directives:

#if __Pawn >= 0x03AB
    #message You're on a nice new compiler.
#elif SHOW_ERROR
    #error You've got an error.
#endif

A compiler that fails the first check AND doesn't recognise #elif will simply skip it and go all the way to #endif. It will not evaluate it as #elseif and potentially run the code within. It should somehow recognise #elif as a #if-like directive it just doesn't know and give an error. That would require some sort of hard convention we don't yet have. That, or we just define all possible ones now (even if they aren't implemented):

#if
#else
#elseif
#elif
#ifdef
#elifdef
#elseifdef
#endif
#fi
#el
#ifndef
#elseifndef
#elifndef

Can't think of any more, but that doesn't mean there aren't any (does iff make any sense here?)

Makes the compiler slightly more future-proof by allowing us to do something like:

```pawn
#if __Pawn >= 0x03AB
    #message You're on a nice new compiler.
#endif
```

Currently to do that you need to do:

```pawnc
#message You're on a nice new compiler.
```

```pawn
#if __Pawn >= 0x03AB
    #include "message.inc"
#endif
```

Or you get an error that `#message` (or anything else) is an unknown directive if the compiler doesn't recognise it, even if it is disabled.

The only downside to this is that it makes it slightly harder to add new `#if`-like directives:

```pawn
#if __Pawn >= 0x03AB
    #message You're on a nice new compiler.
#elif SHOW_ERROR
    #error You've got an error.
#endif
```

A compiler that fails the first check AND doesn't recognise `#elif` will simply skip it and go all the way to `#endif`.  It will not evaluate it as `#elseif` and potentially run the code within.  It should somehow recognise `#elif` as a `#if`-like directive it just doesn't know and give an error.  That would require some sort of hard convention we don't yet have.  That, or we just define all possible ones now (even if they aren't implemented):

```pawn
#if
#else
#elseif
#elif
#ifdef
#elifdef
#elseifdef
#endif
#fi
#el
#ifndef
#elseifndef
#elifndef
```

Can't think of any more, but that doesn't mean there aren't any (does `iff` make any sense here?)
@Y-Less Y-Less requested a review from a team as a code owner June 16, 2019 00:44
@Zeex Zeex merged commit b2eca92 into pawn-lang:dev Jun 29, 2019
@Zeex
Copy link
Contributor

Zeex commented Jun 29, 2019

Merged, but there is one issue - unknown directives cause an assertion failure (it was like this in earlier versions too, not due to this change). I'll push a separate fix for that.

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.

2 participants