-- | Common definitions for the modules of the C backend.

module BNFC.Backend.C.Common
  ( memName
  , posixC
  ) where

import Prelude
import BNFC.Backend.Common.NamedVariables

-- | Switch C to language variant that has @strdup@.

posixC :: [String]
posixC :: [[Char]]
posixC =
  [ [Char]
"/* strdup was not in the ISO C standard before 6/2019 (C2x), but in POSIX 1003.1."
  , [Char]
" * See: https://en.cppreference.com/w/c/experimental/dynamic/strdup"
  , [Char]
" * Setting _POSIX_C_SOURCE to 200809L activates strdup in string.h."
  , [Char]
" */"
  , [Char]
"#define _POSIX_C_SOURCE 200809L"
  ]

-- | Variant names in unions.

memName :: String -> String
memName :: [Char] -> [Char]
memName [Char]
s = [Char] -> [Char]
firstLowerCase [Char]
s [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"_"