xref: /libCEED/rust/libceed-sys/c-src/include/ceed-fortran-name.h (revision d4cc18453651bd0f94c1a2e078b2646a92dafdcc)
1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
304822c1eSjeremylt //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
504822c1eSjeremylt //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
704822c1eSjeremylt 
894b7b29bSJeremy L Thompson #ifndef CEED_FORTRAN_NAME_H
994b7b29bSJeremy L Thompson #define CEED_FORTRAN_NAME_H
10734e90feSThilina Rathnayake 
11734e90feSThilina Rathnayake /* establishes some macros to establish
12734e90feSThilina Rathnayake    * the FORTRAN naming convention
13734e90feSThilina Rathnayake      default      gs_setup, etc.
14734e90feSThilina Rathnayake      -DUPCASE     GS_SETUP, etc.
15734e90feSThilina Rathnayake      -DUNDERSCORE gs_setup_, etc.
16ea61e9acSJeremy L Thompson    * a prefix for all external (non-FORTRAN) function names for example, -DPREFIX=jl_   transforms fail -> jl_fail
17ea61e9acSJeremy L Thompson    * a prefix for all external FORTRAN function names for example, -DFPREFIX=jlf_ transforms gs_setup_ -> jlf_gs_setup_
18734e90feSThilina Rathnayake */
19734e90feSThilina Rathnayake 
20ea61e9acSJeremy L Thompson /* the following macro functions like a##b, but will expand a and/or b if they are themselves macros */
21734e90feSThilina Rathnayake #define TOKEN_PASTE_(a, b) a##b
22734e90feSThilina Rathnayake #define TOKEN_PASTE(a, b) TOKEN_PASTE_(a, b)
23734e90feSThilina Rathnayake 
24734e90feSThilina Rathnayake #ifdef PREFIX
25734e90feSThilina Rathnayake #define PREFIXED_NAME(x) TOKEN_PASTE(PREFIX, x)
26734e90feSThilina Rathnayake #else
27734e90feSThilina Rathnayake #define PREFIXED_NAME(x) x
28734e90feSThilina Rathnayake #endif
29734e90feSThilina Rathnayake 
30734e90feSThilina Rathnayake #ifdef FPREFIX
31734e90feSThilina Rathnayake #define FPREFIXED_NAME(x) TOKEN_PASTE(FPREFIX, x)
32734e90feSThilina Rathnayake #else
33734e90feSThilina Rathnayake #define FPREFIXED_NAME(x) x
34734e90feSThilina Rathnayake #endif
35734e90feSThilina Rathnayake 
36734e90feSThilina Rathnayake #if defined(UPCASE)
37734e90feSThilina Rathnayake #define FORTRAN_NAME(low, up) FPREFIXED_NAME(up)
38734e90feSThilina Rathnayake #define FORTRAN_UNPREFIXED(low, up) up
39734e90feSThilina Rathnayake #elif defined(UNDERSCORE)
40734e90feSThilina Rathnayake #define FORTRAN_NAME(low, up) FPREFIXED_NAME(TOKEN_PASTE(low, _))
41734e90feSThilina Rathnayake #define FORTRAN_UNPREFIXED(low, up) TOKEN_PASTE(low, _)
42734e90feSThilina Rathnayake #else
43734e90feSThilina Rathnayake #define FORTRAN_NAME(low, up) FPREFIXED_NAME(low)
44734e90feSThilina Rathnayake #define FORTRAN_UNPREFIXED(low, up) low
45734e90feSThilina Rathnayake #endif
46734e90feSThilina Rathnayake 
4794b7b29bSJeremy L Thompson #endif  // CEED_FORTRAN_NAME_H
48