X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=lexer.c;h=6bd47b065eb3f96220c65417e98fab3c4fa7beb2;hb=797ceb9e0463c1a03bcbf3270ba3bd94fe118e0b;hp=10a00914c1071bf65abbd71d644e2b890e94eb3c;hpb=9a9ecd574e0cf548febc9dfc85920d4f746e2cd3;p=xonotic%2Fgmqcc.git diff --git a/lexer.c b/lexer.c index 10a0091..6bd47b0 100644 --- a/lexer.c +++ b/lexer.c @@ -47,7 +47,8 @@ static const char *keywords_fg[] = { "switch", "case", "default", "struct", "union", "break", "continue", - "typedef" + "typedef", + "goto" }; static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]); @@ -318,6 +319,11 @@ static int lex_try_digraph(lex_file *lex, int ch) { int c2; c2 = lex_fgetc(lex); + /* we just used fgetc() so count lines + * need to offset a \n the ungetch would recognize + */ + if (!lex->push_line && c2 == '\n') + lex->line++; if (ch == '<' && c2 == ':') return '['; else if (ch == ':' && c2 == '>') @@ -445,7 +451,8 @@ static bool lex_try_pragma(lex_file *lex) if (!strcmp(command, "push")) { if (!strcmp(param, "line")) { lex->push_line++; - --line; + if (lex->push_line == 1) + --line; } else goto unroll; @@ -454,7 +461,8 @@ static bool lex_try_pragma(lex_file *lex) if (!strcmp(param, "line")) { if (lex->push_line) lex->push_line--; - --line; + if (lex->push_line == 0) + --line; } else goto unroll; @@ -768,6 +776,7 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote) case 't': ch = '\t'; break; case 'f': ch = '\f'; break; case 'v': ch = '\v'; break; + case '\n': ch = '\n'; break; default: lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch); /* so we just add the character plus backslash no matter what it actually is */ @@ -883,14 +892,14 @@ int lex_do(lex_file *lex) continue; } - lex->sline = lex->line; - lex->tok.ctx.line = lex->sline; - lex->tok.ctx.file = lex->name; - if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) { return (lex->tok.ttype = ch); } + lex->sline = lex->line; + lex->tok.ctx.line = lex->sline; + lex->tok.ctx.file = lex->name; + if (lex->eof) return (lex->tok.ttype = TOKEN_FATAL); @@ -1076,8 +1085,10 @@ int lex_do(lex_file *lex) */ switch (ch) { + /* case '+': case '-': + */ case '*': case '/': case '<': @@ -1266,6 +1277,7 @@ int lex_do(lex_file *lex) lex_tokench(lex, ch); lex_endtoken(lex); + lex->tok.ttype = TOKEN_CHARCONST; /* It's a vector if we can successfully scan 3 floats */ #ifdef WIN32 if (sscanf_s(lex->tok.value, " %f %f %f ", @@ -1278,6 +1290,14 @@ int lex_do(lex_file *lex) { lex->tok.ttype = TOKEN_VECTORCONST; } + else + { + if (!lex->flags.preprocessing && strlen(lex->tok.value) > 1) { + if (lexwarn(lex, WARN_MULTIBYTE_CHARACTER, "multibyte character: `%s`", lex->tok.value)) + return (lex->tok.ttype = TOKEN_ERROR); + } + lex->tok.constval.i = lex->tok.value[0]; + } return lex->tok.ttype; }