-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Enable inp_include.c test + feat: ifndef, fixes #60
- Loading branch information
Showing
5 changed files
with
117 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,11 @@ | ||
void printf(char *, ...); | ||
|
||
#define DEBUG 1 | ||
#define DEBUG | ||
|
||
#ifdef DEBUG | ||
int function() { | ||
return 69; | ||
} | ||
#endif | ||
|
||
#ifdef RELEASE | ||
int function() { | ||
return 13; | ||
} | ||
int main() | ||
{ | ||
#ifndef DEBUG | ||
printf("Debug disabled!\n"); | ||
#endif | ||
|
||
#ifndef RELEASE | ||
int function2() { | ||
return 99; | ||
} | ||
#endif | ||
|
||
int main() { | ||
printf("function(): %d\n", function()); | ||
printf("function2(): %d\n", function2()); | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include "macro_ifndef.h" | ||
#include "preprocess.h" | ||
#include <string.h> | ||
|
||
seg_ifndef *parse_ifndef(prep_ctx *ctx, typed_token **tkns_ptr) | ||
{ | ||
typed_token *tkn = *tkns_ptr; | ||
if (tkn->type_id == TKN_DIRECTIVE) | ||
{ | ||
typed_token *inner_tkn = (typed_token *)tkn->data; | ||
tkn = tkn->next; | ||
if (inner_tkn->type_id == TKN_ID) | ||
{ | ||
if (strcmp((char *)inner_tkn->data, "ifndef") == 0) | ||
{ | ||
inner_tkn = inner_tkn->next; | ||
if (inner_tkn->type_id == TKN_ID) | ||
{ | ||
char *def = (char *)inner_tkn->data; | ||
inner_tkn = inner_tkn->next; | ||
|
||
if (inner_tkn->type_id == TKN_EOF) | ||
{ | ||
*tkns_ptr = tkn; | ||
seg_ifndef *ret = malloc(sizeof(seg_ifndef)); | ||
ret->def = def; | ||
return ret; | ||
} | ||
else | ||
{ | ||
return NULL; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return NULL; | ||
} | ||
|
||
int is_endif(typed_token *tkn) | ||
{ | ||
if (tkn->type_id == TKN_DIRECTIVE) | ||
{ | ||
typed_token *inner_tkn = (typed_token *)tkn->data; | ||
if (inner_tkn->type_id == TKN_ID) | ||
{ | ||
if (strcmp((char *)inner_tkn->data, "endif") == 0) | ||
{ | ||
inner_tkn = inner_tkn->next; | ||
if (inner_tkn->type_id == TKN_EOF) | ||
{ | ||
return 1; | ||
} | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef MACRO_IFNDEF_H | ||
#define MACRO_IFNDEF_H | ||
|
||
#include "../linked_list.h" | ||
#include "preprocess.h" | ||
|
||
typedef struct | ||
{ | ||
char *def; | ||
} seg_ifndef; | ||
|
||
seg_ifndef *parse_ifndef(prep_ctx *ctx, typed_token **tkns_ptr); | ||
int is_endif(typed_token *tkn); | ||
|
||
#endif |
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