Add macro directives to token_list

- change the lexer to not remove preprocessor directives
- preprocess() removes any lines starting with a macro directive that it
  doesn't understand (which is currently all of them)
This commit is contained in:
Sanne Wouda 2021-01-05 19:53:06 +00:00
parent 7b8a99db3c
commit cd96f65a23
5 changed files with 48 additions and 18 deletions

View File

@ -1845,6 +1845,7 @@ new_type:
}
else
{
require('#' != global_token->s[0], "unhandled macro directive\n");
require(!match("\n", global_token->s), "unexpected newline token\n");
type_size = type_name();
if(NULL == type_size)

View File

@ -17,6 +17,8 @@
#include "cc.h"
#include "gcc_req.h"
void require(int bool, char* error);
/* point where we are currently modifying the global_token list */
struct token_list* macro_token;
@ -54,7 +56,44 @@ void eat_newline_tokens()
}
}
void macro_directive()
{
/* unhandled macro directive; let's eat until a newline; om nom nom */
while (TRUE)
{
eat_current_token();
if (NULL == macro_token)
return;
if ('\n' == macro_token->s[0])
return;
}
}
void preprocess()
{
int start_of_line = TRUE;
macro_token = global_token;
while (NULL != macro_token)
{
if (start_of_line && '#' == macro_token->s[0])
{
macro_directive();
if (macro_token)
require('\n' == macro_token->s[0], "newline expected at end of macro directive\n");
}
else if ('\n' == macro_token->s[0])
{
start_of_line = TRUE;
macro_token = macro_token->next;
}
else
{
start_of_line = FALSE;
macro_token = macro_token->next;
}
}
}

View File

@ -74,16 +74,6 @@ int preserve_keyword(int c, char* S)
return c;
}
int purge_macro(int ch)
{
while(10 != ch)
{
ch = fgetc(input);
require(EOF != ch, "Hit EOF inside macro\n");
}
return ch;
}
void reset_hold_string()
{
int i = string_index + 2;
@ -111,8 +101,8 @@ reset:
}
else if('#' == c)
{
c = purge_macro(c);
goto reset;
c = consume_byte(c);
c = preserve_keyword(c, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_");
}
else if(in_set(c, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"))
{

View File

@ -169,8 +169,8 @@ a2a83f42119e646b389b98647cf6cf2aa9597185997c9453db746178c8c4c0bf test/results/t
698853b79efb30865a663c4863c050639eb21c7400008f7840830503928973d4 test/results/test0106-knight-native-binary
45c2ba61dc209d7ffa39de9ff0f0a7f8f3ea4d7e38598c72f982fcaf9a05c84a test/results/test0106-knight-posix-binary
944580ff4aae38aafac139faf6eed5bfe4ff68b01a7a3adfa346de8803101182 test/results/test0106-x86-binary
1cd2d00f69473be2a88d80442e04c90bc3bbeae38144ee20df51a77ccb54c777 test/results/test1000-aarch64-binary
f7f32de24e8aa269fd6c90539aae84fea37d36638d069b9d7710e9491e9c467d test/results/test1000-amd64-binary
f1f6a4b5827ec9ef319ea6a7ebb6ddce9677bb7a5111a6517c67d86cd0aea550 test/results/test1000-armv7l-binary
0296515603b07ad2e28ec43cd19e89385a59af838c305fd99dd74d9f0c3879e3 test/results/test1000-knight-posix-binary
0002f0bea9345bb4c5bc712154ddf39038bd9a8300c51ddd1c97d086c74ba497 test/results/test1000-x86-binary
206905afbcc1ef41d5b241fb72381c0854792fedbbd467ea33c52728cc8946b6 test/results/test1000-aarch64-binary
85a238be594b0bbd3d2613872cc15315f5ad79f4491c424f006f1e98dc6234ef test/results/test1000-amd64-binary
27bf47331a04a42cae324da6862f21625c093ee27e9cf2504b1c6c80b98e814a test/results/test1000-armv7l-binary
e5102501c6939447a87084fd3853d55dcc32b80142efaa72b5f9305d80026b84 test/results/test1000-knight-posix-binary
c0c649496e3c5738667d3bef74a917253471e192b3e550152c083d1ccf579d09 test/results/test1000-x86-binary

View File

@ -1 +1 @@
e5309b1a65e0627f3011fbd68aed1f6585cd9f30c620b8398841908c6730ab1a test/test1000/proof
21f64ec000afd8b05c10532c51806c04eee2120ece05141fa7c0c6fab5e56869 test/test1000/proof