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

Feature Request: Limit the usage of defines to specific variables #384

Open
PowerfulBacon opened this issue Apr 16, 2024 · 1 comment
Open

Comments

@PowerfulBacon
Copy link

PowerfulBacon commented Apr 16, 2024

In most cases of DM, flags are implemented using defines. This is fine, however it can be hard to tell if a flag is being used correctly or not.
This feature requests requests for any method to be able to limit the usage of specific defines down to certain usecases, however it is implemented.

This is particularly tricky to define a nice example of, since this needs to catch the names of defines before they are sent through to the preprocessor, so I'm not exactly sure how this would look.

Potential option 1: Limit the usage to specific variables, by having something before the define

// Rejects any uses that aren't in a variable called "flags"
DEFINE_USAGE(flags)
#define EXAMPLE (1<<0)

DEFINE_USAGE(flags)
#define TESTXAMPLE (1<<1)

/datum/test
  // Accepted
  var/flags = EXAMPLE

  //! Error: EXAMPLE cannot be used in flags1
  var/flags1 = EXAMPLE

/datum/other
  // Accepted
  var/flags = EXAMPLE

Potential option 2: Introduce enum types, by having something before the define

// Also would be nice to allow this for syntax too
// Anything with a define type would be rejected if you attempt to store it in a variable that doesn't have an ACCEPT_TYPE for that type.
DEFINE_TYPE(basic_flags) #define EXAMPLE (1<<0)
DEFINE_TYPE(basic_flags) #define TESTXAMPLE (1<<1)

/datum
  // Accepted
  ACCEPT_TYPE(basic_flags)
  var/flags = EXAMPLE

  // Accepted
  ACCEPT_TYPE(basic_flags)
  var/flags1 = EXAMPLE
  
  //! Error, attempting to use define in a variable that doesn't explicitly accept that definition.
  var/other = TESTXAMPLE 

In the above cases, the DM implementation of these defines is just a noop.

@LemonInTheDark
Copy link
Contributor

Ideally we would have a special case for flags, since flags should not conflict against each other

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

3 participants