X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=lexer.c;h=8a339aa110058836c6f208ad7eb15f9eaa34232f;hb=6f8db408325831c25558eaa99b1d291562f7f65a;hp=88cb4465df0fbbcf6b37a23088016c886a431adf;hpb=dd83a43ff683498acbd213b153d02e4eaf8de82c;p=cparser diff --git a/lexer.c b/lexer.c index 88cb446..8a339aa 100644 --- a/lexer.c +++ b/lexer.c @@ -19,6 +19,7 @@ */ #include +#include "adt/strutil.h" #include "input.h" #include "diagnostic.h" #include "lexer.h" @@ -323,8 +324,8 @@ finish_suffix: } obstack_1grow(&symbol_obstack, '\0'); - size_t size = obstack_object_size(&symbol_obstack); - char *string = obstack_finish(&symbol_obstack); + size_t size = obstack_object_size(&symbol_obstack) - 1; + char *string = obstack_finish(&symbol_obstack); lexer_token.number.suffix = identify_string(string, size); } @@ -897,7 +898,24 @@ static void parse_line_directive(void) } if (pp_token.kind == T_STRING_LITERAL) { lexer_pos.input_name = pp_token.string.string.begin; + lexer_pos.is_system_header = false; next_pp_token(); + + /* attempt to parse numeric flags as outputted by gcc preprocessor */ + while (pp_token.kind == T_INTEGER) { + /* flags: + * 1 - indicates start of a new file + * 2 - indicates return from a file + * 3 - indicates system header + * 4 - indicates implicit extern "C" in C++ mode + * + * currently we're only interested in "3" + */ + if (streq(pp_token.number.number.begin, "3")) { + lexer_pos.is_system_header = true; + } + next_pp_token(); + } } eat_until_newline(); @@ -1306,6 +1324,6 @@ static __attribute__((unused)) void dbg_pos(const source_position_t source_position) { fprintf(stdout, "%s:%u:%u\n", source_position.input_name, - source_position.lineno, source_position.colno); + source_position.lineno, (unsigned)source_position.colno); fflush(stdout); }