Skip to content

Commit

Permalink
Merge pull request #161 from ChAoSUnItY/master
Browse files Browse the repository at this point in the history
Support empty alias, and refine include guard tests
  • Loading branch information
jserv authored Nov 8, 2024
2 parents 005956a + 3dadc70 commit affa4fc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* file "LICENSE" for information on usage and redistribution of this file.
*/

#ifndef SHECC_DEFS_H
#define SHECC_DEFS_H

/* definitions */

/* Limitations */
Expand Down Expand Up @@ -425,3 +428,5 @@ typedef struct {
var_t *var;
int polluted;
} regfile_t;

#endif
4 changes: 4 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ bool read_preproc_directive()

macro->start_source_idx = source_idx;
skip_macro_body();
} else {
/* Empty alias, may be dummy alias serves as include guard */
value[0] = 0;
add_alias(alias, value);
}

return true;
Expand Down
42 changes: 41 additions & 1 deletion tests/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,49 @@ try_ 0 << EOF
#else
#define A 1
#endif
#ifndef A
#define B 1
#else
#define B 0
#endif
int main()
{
return A;
return A + B;
}
EOF

# include guard test, simulates inclusion of a file named defs.h and global.c
try_ 0 << EOF
/* #include "defs.h" */
#ifndef DEFS_H
#define DEFS_H
#define A 1
#endif
/* end if "defs.h" inclusion */
/* #include "global.c" */
#ifndef GLOBAL_C
#define GLOBAL_C
#define B 1
/* [global.c] #include "defs.h" */
#ifndef DEFS_H
#define DEFS_H
#define A 2
#endif
/* end if "defs.h" inclusion */
#endif
/* end if "global.c" inclusion */
int main()
{
return A - B;
}
EOF

Expand Down

0 comments on commit affa4fc

Please sign in to comment.