]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - lexer.c
call ir_function_finalize on array accessors otherwise they'll blow up stuff
[xonotic/gmqcc.git] / lexer.c
diff --git a/lexer.c b/lexer.c
index 4d184d083d67afdfa1527173d237ba3059590e7b..a550ed0b2dd3bd4b92f27248e10ed9a434117b93 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -381,21 +381,21 @@ static int lex_skipwhite(lex_file *lex)
             if (ch == '/')
             {
                 /* one line comment */
-                haswhite = true;
                 ch = lex_getch(lex);
 
                 if (lex->flags.preprocessing) {
-                    if (!lex_tokench(lex, ' ') ||
-                        !lex_tokench(lex, ' '))
+                    haswhite = true;
+                    if (!lex_tokench(lex, '/') ||
+                        !lex_tokench(lex, '/'))
                     {
                         return TOKEN_FATAL;
                     }
                 }
 
                 while (ch != EOF && ch != '\n') {
-                    ch = lex_getch(lex);
-                    if (lex->flags.preprocessing && !lex_tokench(lex, ' '))
+                    if (lex->flags.preprocessing && !lex_tokench(lex, ch))
                         return TOKEN_FATAL;
+                    ch = lex_getch(lex);
                 }
                 if (lex->flags.preprocessing) {
                     lex_ungetch(lex, '\n');
@@ -408,10 +408,10 @@ static int lex_skipwhite(lex_file *lex)
             if (ch == '*')
             {
                 /* multiline comment */
-                haswhite = true;
                 if (lex->flags.preprocessing) {
-                    if (!lex_tokench(lex, ' ') ||
-                        !lex_tokench(lex, ' '))
+                    haswhite = true;
+                    if (!lex_tokench(lex, '/') ||
+                        !lex_tokench(lex, '*'))
                     {
                         return TOKEN_FATAL;
                     }
@@ -424,8 +424,8 @@ static int lex_skipwhite(lex_file *lex)
                         ch = lex_getch(lex);
                         if (ch == '/') {
                             if (lex->flags.preprocessing) {
-                                if (!lex_tokench(lex, ' ') ||
-                                    !lex_tokench(lex, ' '))
+                                if (!lex_tokench(lex, '*') ||
+                                    !lex_tokench(lex, '/'))
                                 {
                                     return TOKEN_FATAL;
                                 }
@@ -434,8 +434,6 @@ static int lex_skipwhite(lex_file *lex)
                         }
                     }
                     if (lex->flags.preprocessing) {
-                        if (ch != '\n')
-                            ch = ' ';
                         if (!lex_tokench(lex, ch))
                             return TOKEN_FATAL;
                     }
@@ -552,7 +550,7 @@ static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
         if (ch == quote)
             return TOKEN_STRINGCONST;
 
-        if (ch == '\\') {
+        if (!lex->flags.preprocessing && ch == '\\') {
             ch = lex_getch(lex);
             if (ch == EOF) {
                 lexerror(lex, "unexpected end of file");
@@ -854,6 +852,7 @@ int lex_do(lex_file *lex)
     /* single-character tokens */
     switch (ch)
     {
+        case '[':
         case '(':
             if (!lex_tokench(lex, ch) ||
                 !lex_endtoken(lex))
@@ -868,7 +867,6 @@ int lex_do(lex_file *lex)
         case ';':
         case '{':
         case '}':
-        case '[':
         case ']':
 
         case '#':
@@ -1056,7 +1054,8 @@ int lex_do(lex_file *lex)
                 !strcmp(v, "struct") ||
                 !strcmp(v, "union")  ||
                 !strcmp(v, "break")  ||
-                !strcmp(v, "continue"))
+                !strcmp(v, "continue") ||
+                !strcmp(v, "var"))
             {
                 lex->tok.ttype = TOKEN_KEYWORD;
             }
@@ -1068,8 +1067,12 @@ int lex_do(lex_file *lex)
     if (ch == '"')
     {
         lex->flags.nodigraphs = true;
+        if (lex->flags.preprocessing && !lex_tokench(lex, ch))
+            return TOKEN_FATAL;
         lex->tok.ttype = lex_finish_string(lex, '"');
-        while (lex->tok.ttype == TOKEN_STRINGCONST)
+        if (lex->flags.preprocessing && !lex_tokench(lex, ch))
+            return TOKEN_FATAL;
+        while (!lex->flags.preprocessing && lex->tok.ttype == TOKEN_STRINGCONST)
         {
             /* Allow c style "string" "continuation" */
             ch = lex_skipwhite(lex);
@@ -1093,23 +1096,28 @@ int lex_do(lex_file *lex)
          * Likewise actual unescaping has to be done by the parser.
          * The difference is we don't allow 'char' 'continuation'.
          */
-         lex->tok.ttype = lex_finish_string(lex, '\'');
-         if (!lex_endtoken(lex))
-              return (lex->tok.ttype = TOKEN_FATAL);
+        if (lex->flags.preprocessing && !lex_tokench(lex, ch))
+            return TOKEN_FATAL;
+        lex->tok.ttype = lex_finish_string(lex, '\'');
+        if (lex->flags.preprocessing && !lex_tokench(lex, ch))
+            return TOKEN_FATAL;
+        if (!lex_endtoken(lex))
+            return (lex->tok.ttype = TOKEN_FATAL);
 
          /* It's a vector if we can successfully scan 3 floats */
 #ifdef WIN32
-         if (sscanf_s(lex->tok.value, " %f %f %f ",
-                    &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
+        if (sscanf_s(lex->tok.value, " %f %f %f ",
+                   &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
 #else
-         if (sscanf(lex->tok.value, " %f %f %f ",
-                    &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
+        if (sscanf(lex->tok.value, " %f %f %f ",
+                   &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
 #endif
-         {
-              lex->tok.ttype = TOKEN_VECTORCONST;
-         }
 
-         return lex->tok.ttype;
+        {
+             lex->tok.ttype = TOKEN_VECTORCONST;
+        }
+
+        return lex->tok.ttype;
     }
 
     if (isdigit(ch))