Skip to content

Commit affa4fc

Browse files
authored
Merge pull request #161 from ChAoSUnItY/master
Support empty alias, and refine include guard tests
2 parents 005956a + 3dadc70 commit affa4fc

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/defs.h

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* file "LICENSE" for information on usage and redistribution of this file.
66
*/
77

8+
#ifndef SHECC_DEFS_H
9+
#define SHECC_DEFS_H
10+
811
/* definitions */
912

1013
/* Limitations */
@@ -425,3 +428,5 @@ typedef struct {
425428
var_t *var;
426429
int polluted;
427430
} regfile_t;
431+
432+
#endif

src/parser.c

+4
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ bool read_preproc_directive()
409409

410410
macro->start_source_idx = source_idx;
411411
skip_macro_body();
412+
} else {
413+
/* Empty alias, may be dummy alias serves as include guard */
414+
value[0] = 0;
415+
add_alias(alias, value);
412416
}
413417

414418
return true;

tests/driver.sh

+41-1
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,49 @@ try_ 0 << EOF
465465
#else
466466
#define A 1
467467
#endif
468+
469+
#ifndef A
470+
#define B 1
471+
#else
472+
#define B 0
473+
#endif
468474
int main()
469475
{
470-
return A;
476+
return A + B;
477+
}
478+
EOF
479+
480+
# include guard test, simulates inclusion of a file named defs.h and global.c
481+
try_ 0 << EOF
482+
/* #include "defs.h" */
483+
#ifndef DEFS_H
484+
#define DEFS_H
485+
486+
#define A 1
487+
488+
#endif
489+
/* end if "defs.h" inclusion */
490+
491+
/* #include "global.c" */
492+
#ifndef GLOBAL_C
493+
#define GLOBAL_C
494+
495+
#define B 1
496+
497+
/* [global.c] #include "defs.h" */
498+
#ifndef DEFS_H
499+
#define DEFS_H
500+
501+
#define A 2
502+
503+
#endif
504+
/* end if "defs.h" inclusion */
505+
#endif
506+
/* end if "global.c" inclusion */
507+
508+
int main()
509+
{
510+
return A - B;
471511
}
472512
EOF
473513

0 commit comments

Comments
 (0)