~sircmpwn/annotatec

a3b8fab62e5d45d1b7f67fd8501a9b1e6220be8b — Drew DeVault 7 months ago 8357cab
Implement parser logic for stdarg.h
3 files changed, 18 insertions(+), 4 deletions(-)

M lang.l
M lang.y
M main.c
M lang.l => lang.l +9 -2
@@ 94,7 94,8 @@ void lexreset(const char *fn, FILE *input) {
"_Noreturn" 		{ _lineno(); return CZ_NORETURN; }
"_Static_assert" 	{ _lineno(); return CZ_STATIC_ASSERT; }
"_Thread_local" 	{ _lineno(); return CZ_THREAD_LOCAL; }
"__builtin_va_list" { _lineno(); return CZ_BUILTIN_VA_LIST; }
"__builtin_va_list"	{ _lineno(); return CZ_BUILTIN_VA_LIST; }
"__builtin_va_arg"	{ _lineno(); return CZ_BUILTIN_VA_ARG; }

"__restrict"		{ _lineno(); return CZ_RESTRICT; } /* GNU extensions */
"__inline"			{ _lineno(); return CZ_INLINE; }


@@ 206,9 207,15 @@ static void _lineno(void) {
	}
}

bool preprocessed_linenos = false;

static void linemarker(void) {
	char *endptr;
	lineno = strtol(&yytext[1], &endptr, 10) - 1;
	if (preprocessed_linenos) {
		strtol(&yytext[1], &endptr, 10);
	} else {
		lineno = strtol(&yytext[1], &endptr, 10) - 1;
	}
	while (*endptr && *endptr++ != '"') {
		/* This space deliberately left blank */
	}

M lang.y => lang.y +4 -1
@@ 54,7 54,7 @@ struct parse_state parse_state = { 0 };
/* tokens for reverse parsing */
%token CZ_ONELINE_COMMENT CZ_MULTILINE_COMMENT CZ_WHITESPACE
/* implementation details */
%token CZ_BUILTIN_VA_LIST CZ_LINEMARKER
%token CZ_BUILTIN_VA_LIST CZ_BUILTIN_VA_ARG CZ_BUILTIN_VA_COPY
/* GNU extensions (fuck you GNU) */
%token CZ_GNU_ATTRIBUTE CZ_GNU_ASM



@@ 102,6 102,9 @@ primary_expression
	| generic_selection {
		$$.name = NULL;
	}
	| CZ_BUILTIN_VA_ARG '(' CZ_IDENTIFIER ',' type_name ')' {
		$$.name = NULL;
	}
	;

constant

M main.c => main.c +5 -1
@@ 55,12 55,13 @@ static void postprocess(const char *file) {
}

extern int yydebug;
extern bool preprocessed_linenos;

int main(int argc, char **argv) {
	char *cppcmd = "cpp -std=c11";

	int c;
	while ((c = getopt(argc, argv, "dC:")) != -1) {
	while ((c = getopt(argc, argv, "dDC:g")) != -1) {
		switch (c) {
		case 'C':
			cppcmd = optarg;


@@ 68,6 69,9 @@ int main(int argc, char **argv) {
		case 'd':
			yydebug = 1;
			break;
		case 'D':
			preprocessed_linenos = true;
			break;
		}
	}