pawn-lang / compiler

Pawn compiler for SA-MP with bug fixes and new features - runs on Windows, Linux, macOS
Other
306 stars 72 forks source link

directory defaults #295

Open Y-Less opened 6 years ago

Y-Less commented 6 years ago

Is this a BUG REPORT, FEATURE REQUEST or QUESTION?:

What happened:

The file default.inc is automatically included when you compile. It would be nice to extend this to other directories - similar to the index.js feature in JS 6:

Current file structure in YSI:

- YSI_Coding
    - y_hooks
        - impl.inc
        - macros.inc
        - tests.inc
    - y_hooks.inc
- YSI_Data
    - y_foreach
        - impl.inc
        - iterators.inc
        - macros.inc
        - tests.inc
        - warning.inc
        - yield.inc
    - y_iterate.inc

What you expected to happen:

If doing #include <directory> looked for a default.inc in that directory the code could change to:

- YSI_Coding
    - y_hooks
        - impl.inc
        - macros.inc
        - tests.inc
        - default.inc
- YSI_Data
    - y_iterate
        - impl.inc
        - iterators.inc
        - macros.inc
        - tests.inc
        - warning.inc
        - yield.inc
        - default.inc

Which would put less stuff in the root directory.

In terms of -Z, the guard should be generated as if the filename was purely the containing directory.

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

YashasSamaga commented 6 years ago
  1. Consider the following directory structure:

    - ABCDE
       - default.inc
    - ABCDE.inc

    What should happen if someone tries to do #include <ABCDE>?

  2. When a user tries #include <ABC>, the compiler looks for a file in the following order:

    • ABC
    • ABC.inc
    • ABC.p
    • 'ABC.pawn`

    Should the same rule be applied for default?

  3. Should this work for current path (using #include "ABC")?


I think for (1), the file ABCDE.inc should be included because the library developer has intentionally kept ABCDE.inc when there's a folder ABCDE. Moreover, this will not break old codebases (where there are folders and files with the same name and the file is included).

For (2), I think the same rules should be followed for consistency. So when searching for default file, the compiler should first check for default followed by default.inc and so on.

Y-Less commented 6 years ago

Yes, check all files first, then defaults in directories.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity.