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 __nodiscard__ and DBResidueMask() use cases and cleanup #377

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions database/DBtcontact.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,24 +953,22 @@ DBFullResidueMask(type, rmask)
TileType type;
TileTypeBitMask *rmask;
{
TileType t;
TileTypeBitMask *lmask;
LayerInfo *li, *lr;

li = &dbLayerInfo[type];
lmask = &li->l_residues;
TTMaskZero(rmask);
LayerInfo *li = &dbLayerInfo[type];
const TileTypeBitMask *lmask = &li->l_residues;

if (type < DBNumUserLayers)
{
TTMaskSetMask(rmask, &li->l_residues);
TTMaskCopy(rmask, lmask);
}
else
{
for (t = TT_TECHDEPBASE; t < DBNumUserLayers; t++)
TileType t;
const int tt_last = DBNumUserLayers;
TTMaskZero(rmask);
for (t = TT_TECHDEPBASE; t < tt_last; t++)
if (TTMaskHasType(lmask, t))
{
lr = &dbLayerInfo[t];
LayerInfo *lr = &dbLayerInfo[t];
TTMaskSetMask(rmask, &lr->l_residues);
}
}
Expand Down
2 changes: 1 addition & 1 deletion database/database.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ extern TileType DBTechFindStacking();
extern bool DBIsContact();
extern PlaneMask DBLayerPlanes();

extern TileTypeBitMask *DBResidueMask();
extern __nodiscard__ TileTypeBitMask *DBResidueMask(TileType type);
extern void DBFullResidueMask();

/* Miscellaneous */
Expand Down
4 changes: 4 additions & 0 deletions scripts/makedbh.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ add_generated_mask_macro(
"TTMaskZero(m)",
"(m)->tt_words[{i}] = 0",
)
add_generated_mask_macro(
"TTMaskCopy(m, n)",
"(m)->tt_words[{i}] = (n)->tt_words[{i}]",
)
add_generated_mask_macro(
"TTMaskIsZero(m)",
"(m)->tt_words[{i}] == 0",
Expand Down
17 changes: 17 additions & 0 deletions utils/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,21 @@ extern char AbortMessage[];
/* looking to squash excessive -Wpedantic warnings ? add into defs.mak: CPPFLAGS += -Wno-variadic-macros */
#define ANALYSER_NONNULL(n...) __attribute__((nonnull(n)))
#define ANALYSER_RETURNS_NONNULL __attribute__((returns_nonnull))

/* These have keyword like behaviour so __nodiscard__ looks more like a keyword and is recognisable as such
* the historic use of __inline__ set a precedent on how backward compatibiliy maybe achieved for such things
*/

#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L))
/* since C23 but maybe some compilers supported it before their official C23 releases */
#define __nodiscard__ [[nodiscard]]
#elif (defined(__GNUC__) && (__GNUC__ >= 4))
#define __nodiscard__ __attribute__((warn_unused_result))
#elif (defined(__clang__) && (__clang_major__ >= 1))
#define __nodiscard__ __attribute__((warn_unused_result))
#else
#define __nodiscard__ /* */
#endif
#else
#define ATTR_FORMAT_PRINTF_1 /* */
#define ATTR_FORMAT_PRINTF_2 /* */
Expand All @@ -217,6 +232,8 @@ extern char AbortMessage[];
#define ANALYSER_MALLOC(dealloc, idx) /* */
#define ANALYSER_NONNULL(n...) /* */
#define ANALYSER_RETURNS_NONNULL /* */

#define __nodiscard__ /* */
#endif

/* ---------------- Start of Machine Configuration Section ----------------- */
Expand Down
Loading