-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This commit takes a large first step towards getting rid of 'union Value' altogether, by turning the nvalue member of the Namval_t struct into a void pointer instead of a union Value pointer. (Also, it is now defined entirely in nval.h, eliminating the _NV_PRIVATE part from name.h). So, for all those Namval_t* pointers such as np, instead of np->nvalue.cp, np->nvalue.lp, etc., we now simply use np->nvalue. The code everywhere is correspondingly updated to do local typecasts where the nvalue pointer is dereferenced. Sometimes, explicit typecasts seemed the most practical, other times I've preferred implicit typecasts through assigning np->nvalue to an appropriately typed local pointer variable and dereferencing that. On the other hand, this change has alllowed getting rid of many explicit typecasts as well, as C90 void pointers are typeless and cna be implicitly typecast to any type. In my view, this change is already increasing the consistency, legibility and transparency of the name-value handling in the code. When I was new to this code base (and still pretty new to C), I found the nvalue union usage one of the most mystifying aspects. The code now shows more explicitly what is being done.
- Loading branch information
Showing
25 changed files
with
365 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,16 +16,12 @@ | |
* hyenias <[email protected]> * | ||
* * | ||
***********************************************************************/ | ||
#ifndef _NV_PRIVATE | ||
#ifndef name_h_defined | ||
#define name_h_defined | ||
/* | ||
* This is the implementation header file for name-value pairs | ||
*/ | ||
|
||
#define _NV_PRIVATE \ | ||
Namfun_t *nvfun; /* pointer to trap functions */ \ | ||
union Value nvalue; /* value field */ \ | ||
void *nvmeta; /* pointer to any of various kinds of type-dependent data */ | ||
|
||
#include <ast.h> | ||
#include <cdt.h> | ||
|
||
|
@@ -135,21 +131,21 @@ struct Ufunction | |
#define nv_isref(n) (nv_isattr((n),NV_REF|NV_TAGGED|NV_FUNCT)==NV_REF) | ||
#define is_abuiltin(n) (nv_isattr(n,NV_BLTIN|NV_INTEGER)==NV_BLTIN) | ||
#define is_afunction(n) (nv_isattr(n,NV_FUNCTION|NV_REF)==NV_FUNCTION) | ||
#define nv_funtree(n) ((n)->nvalue.rp->ptree) | ||
#define nv_funtree(n) (((struct Ufunction*)(n)->nvalue)->ptree) | ||
|
||
/* NAMNOD MACROS */ | ||
/* ... for attributes */ | ||
|
||
#define nv_setattr(n,f) ((n)->nvflag = (f)) | ||
#define nv_context(n) ((void*)(n)->nvfun) /* for builtins */ | ||
/* The following are for name references */ | ||
#define nv_refnode(n) ((n)->nvalue.nrp->np) | ||
#define nv_reftree(n) ((n)->nvalue.nrp->root) | ||
#define nv_reftable(n) ((n)->nvalue.nrp->table) | ||
#define nv_refsub(n) ((n)->nvalue.nrp->sub) | ||
#define nv_refnode(n) (((struct Namref*)(n)->nvalue)->np) | ||
#define nv_reftree(n) (((struct Namref*)(n)->nvalue)->root) | ||
#define nv_reftable(n) (((struct Namref*)(n)->nvalue)->table) | ||
#define nv_refsub(n) (((struct Namref*)(n)->nvalue)->sub) | ||
#if SHOPT_FIXEDARRAY | ||
# define nv_refindex(n) ((n)->nvalue.nrp->curi) | ||
# define nv_refdimen(n) ((n)->nvalue.nrp->dim) | ||
# define nv_refindex(n) (((struct Namref*)(n)->nvalue)->curi) | ||
# define nv_refdimen(n) (((struct Namref*)(n)->nvalue)->dim) | ||
#endif /* SHOPT_FIXEDARRAY */ | ||
|
||
/* ... etc */ | ||
|
@@ -158,7 +154,7 @@ struct Ufunction | |
#undef nv_size | ||
#define nv_size(np) ((np)->nvsize) | ||
#define _nv_hasget(np) ((np)->nvfun && (np)->nvfun->disc && nv_hasget(np)) | ||
#define nv_isnull(np) (!(np)->nvalue.cp && !_nv_hasget(np)) | ||
#define nv_isnull(np) (!(np)->nvalue && !_nv_hasget(np)) | ||
|
||
/* ... for arrays */ | ||
|
||
|
@@ -262,4 +258,4 @@ extern const char e_typecompat[]; | |
extern const char e_globalref[]; | ||
extern const char e_tolower[]; | ||
extern const char e_toupper[]; | ||
#endif /* _NV_PRIVATE */ | ||
#endif /* name_h_defined */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.