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

Add '#cmdline "args..."' directive #341

Merged
merged 17 commits into from Sep 5, 2021
Merged

Add '#cmdline "args..."' directive #341

merged 17 commits into from Sep 5, 2021

Conversation

jayrm
Copy link
Member

@jayrm jayrm commented Sep 5, 2021

This update adds a #cmdline directive to allow specifying command line arguments in the freebasic source file.

#cmdline directives are processed from the first source module only. (The reason I did it this way is command line options are global and affect all source modules. fbc does not support per-module command line options and that kind of feature would be better done with #pragma's some other time).

For example:

$ fbc somefile.bas

'' always compile for multi thread, extra errors checks, and debugging...
#cmdline "-mt -exx -g"
...

All command line arguments are allowed except for -print and -help. Most arguments have been tested. There are no added tests in the test suite. Not well tested are interactions between #lang and -pp processing.

How it works:

  • fbc initializes as usual with whatever read command line arguments are given.
  • the first source (.bas) is parsed as usual.
  • if any #cmdline directives are processed, then fbc will restart the parser or fbc depending on what arguments were given.
  • example: no restart after #cmdline "-mt"
  • example: parser restart after #cmdline "-gen gcc"
  • example: fbc restart after #cmdline "-target win64"

fbc has no clever way of knowing that all the #cmdline directives are processed, or a point when none should be allowed.
#cmdline "-end" will trigger a restart if needed to merge in the given command line arguments
`#cmdline "-restart" will always trigger an fbc restart

#cmdline directives are only processd in the first source module and ignored after restart and ignored in other modules.

Compiling with warning -w all will show all locations of ignore #cmdline directives.

To take full control from the real command line and ignore all #cmdline directives even in the first source module
$ fbc source.bas -z nocmdline
will disable #cmdline processing

…ithin source files

- refactor parseArgsFromFile() and add parseArgsFromString()
- #cmdline "args..." will invoke parseArgsFromString( "args..." )
…with cmdlineOptionTB()

- cmdlineOptionTB() has type of FB_CMDLINE_OPTION

type FBC_CMDLINE_OPTION
	takes_argument as boolean          '' true = option requires argument
	allowed_in_source as boolean       '' true = can be used with #cmdline directive
	restart_required as boolean        '' true = restart of parser is required when used with #cmdline directive
end type

- WIP: initially set 'allowed_in_source' to FALSE for all options
- WIP: initially set 'restart_required' to FALSE for all options
- rename parseArgsFromString() to fbcParseArgsFromString(), it's a public re-entry point in to fbc main module
- add is_source and is_file parameters to handleArg()
- add is_source and is_file parameters to fbcParseArgsFromString()
- add is_source parameter parseArgsFromFile()
…ives - allows overriding source directives with real fbc command line
- track the module count and only process #cmdline directives in the first module
- modules other than the first will ignore #cmdline directives with a warning
- add #cmdline "-end" to trigger a restart of the parser - fbc doesn't know how to detect the end of all #cmdline directives to automatically trigger a restart
- #cmdline "-end" will trigger a restart of the parser
- remaining !!!TODO!!!'s should only be for special cases and major restarts
- error if #cmdline is used anywhere but module level
…restart count

- add 'enum FB_RESTART_FLAGS' to track restart requests and restart history
- FB_RESTART_FLAGS tracks if the restart is due to #cmdline or #lang
- fbInit() expects a FB_RESTART_FLAGS argument instead of restart counts
- in cmdlineOptionTB() add a member to indicate if fbc needs to be restarted for each option
  which would be the case for some options that need to be initialized even before the parser
  (currently not used)
- if #cmdline "-end" was never given, then detect that a restart is required at the end of parsing the source
- change the warning level for ignored #cmdline's - by default not shown but will show with '-w all'
- rename the 'restart' procedures
- declare sub fbRestartBeginRequest( byval flags as FB_RESTART_FLAGS )
- declare sub fbRestartAcceptRequest( byval flags as FB_RESTART_FLAGS )
- declare sub fbRestartCloseRequest( byval flags as FB_RESTART_FLAGS )

This should provide a readable sequence for restarting the parser or fbc:
- Begin / Accept / Close
- the underlying state for request/action/status to be updated through this interface
- all command line options are allowed with #cmdline except '-help' and '-print'
- not all options have been tested with #cmdline in a real test
- added #cmdline "-restart" just in case #cmdline "-end" gives troubles
- #cmdline "-end" will restart the parser or fbc if needed
- #cmdline "-restart" will always restart fbc with the new command line options
- github freebasic#341: fbc: #cmdline "args..." directive to specify command line arguments within source files, restarting the parser from some options
- github freebasic#341: fbc: #cmdline "-end" will trigger a parser or fbc restart if needed.  fbc can't detect the end of reading all the #cmdlines to do this automatically
- github freebasic#341: fbc: #cmdline "-restart" will always trigger an fbc restart
- github freebasic#341: fbc: only process #cmdline in the first source module (which must be specified on the real command line)
- github freebasic#341: fbc: add '-z nocmdline' command line option to ignore #cmdline directives - allows overriding source directives with real fbc command line
@jayrm jayrm merged commit 56121f9 into freebasic:master Sep 5, 2021
@jayrm jayrm deleted the cmdline branch September 6, 2021 11:40
@jayrm jayrm mentioned this pull request Sep 11, 2021
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.

None yet

1 participant