]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parse.c
More cleanups
[xonotic/gmqcc.git] / parse.c
diff --git a/parse.c b/parse.c
index 3cbde9ef5009df31a33d2a76d2e539d38963ee39..a218e6337af340beb095a16df62ecc91d2b4a508 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -54,11 +54,7 @@ void compile_constant_debug() {
  */
 int parse_gen(struct lex_file *file) { 
        int     token = 0;
-       while ((token = lex_token(file)) != ERROR_LEX      && \
-                   token                    != ERROR_COMPILER && \
-                   token                    != ERROR_INTERNAL && \
-                   token                    != ERROR_PARSE    && \
-                   token                    != ERROR_PREPRO   && file->length >= 0) {
+       while ((token = lex_token(file)) != ERROR_LEX && file->length >= 0) {
                switch (token) {
                        case TOKEN_TYPEDEF: {
                                char *f; /* from */
@@ -69,7 +65,7 @@ int parse_gen(struct lex_file *file) {
                                token = lex_token(file); 
                                token = lex_token(file); t = util_strdup(file->lastok);
                                
-                               typedef_add(f, t);
+                               typedef_add(file, f, t);
                                mem_d(f);
                                mem_d(t);
                                
@@ -78,7 +74,7 @@ int parse_gen(struct lex_file *file) {
                                        token = lex_token(file);
                                        
                                if (token != ';')
-                                       error(ERROR_PARSE, "%s:%d Expected a `;` at end of typedef statement\n", file->name, file->line);
+                                       error(file, ERROR_PARSE, "Expected a `;` at end of typedef statement");
                                        
                                token = lex_token(file);
                                break;
@@ -120,12 +116,12 @@ int parse_gen(struct lex_file *file) {
                                        /* strings are in file->lastok */
                                        switch (type) {
                                                case TOKEN_VOID:
-                                                       return error(ERROR_PARSE, "%s:%d Cannot assign value to type void\n", file->name, file->line);
+                                                       error(file, ERROR_PARSE, "Cannot assign value to type void\n");
                                                        
                                                /* TODO: Validate (end quote), strip quotes for constant add, name constant */
                                                case TOKEN_STRING:
                                                        if (*file->lastok != '"')
-                                                               error(ERROR_PARSE, "%s:%d Expected a '\"' (quote) for string constant\n", file->name, file->line);
+                                                               error(file, ERROR_PARSE, "Expected a '\"' (quote) for string constant\n");
                                                        /* add the compile-time constant */
                                                        compile_constants_add((constant){
                                                                .name   = util_strdup(name),
@@ -146,55 +142,55 @@ int parse_gen(struct lex_file *file) {
                                                        char *compile_eval = compile_data;
                                                        
                                                        if (token != '{')
-                                                               error(ERROR_PARSE, "%s:%d Expected initializer list `{`,`}` for vector constant\n", file->name, file->line);    
+                                                               error(file, ERROR_PARSE, "Expected initializer list {} for vector constant\n"); 
                                                        
                                                        /*
                                                         * This parses a single vector element: x,y & z.  This will handle all the
                                                         * complicated mechanics of a vector, and can be extended as well.  This
                                                         * is a rather large macro, and is #undef'd after it's use below.
                                                         */
-                                                       #define PARSE_VEC_ELEMENT(NAME, BIT)                                                                                                                                   \
-                                                           token = lex_token(file);                                                                                                                                           \
-                                                           if (token == ' ')                                                                                                                                                  \
-                                                               token = lex_token(file);                                                                                                                                       \
-                                                           if (token == '.')                                                                                                                                                  \
-                                                               compile_calc_d = 1;                                                                                                                                            \
-                                                           if (!isdigit(token) && !compile_calc_d && token != '+' && token != '-')                                                                                            \
-                                                               error(ERROR_PARSE,"%s:%d Invalid constant initializer element %c for vector, must be numeric\n", file->name, file->line, NAME);                                \
-                                                           if (token == '+')                                                                                                                                                  \
-                                                               compile_calc_s = '+';                                                                                                                                          \
-                                                           if (token == '-' && !compile_calc_s)                                                                                                                               \
-                                                               compile_calc_s = '-';                                                                                                                                          \
-                                                           while (isdigit(token) || token == '.' || token == '+' || token == '-') {                                                                                           \
-                                                               *compile_eval++ = token;                                                                                                                                       \
-                                                               token           = lex_token(file);                                                                                                                             \
-                                                               if (token == '.' && compile_calc_d) {                                                                                                                          \
-                                                                   error(ERROR_PARSE, "%s:%d Invalid constant initializer element %c for vector, must be numeric.\n", file->name, file->line, NAME);                          \
-                                                                   token = lex_token(file);                                                                                                                                   \
-                                                               }                                                                                                                                                              \
-                                                               if ((token == '-' || token == '+') && compile_calc_s) {                                                                                                        \
-                                                                   error(ERROR_PARSE, "%s:%d Invalid constant initializer sign for vector element %c\n", file->name, file->line, NAME);                                       \
-                                                                   token = lex_token(file);                                                                                                                                   \
-                                                               }                                                                                                                                                              \
-                                                               else if (token == '.' && !compile_calc_d)                                                                                                                      \
-                                                                   compile_calc_d = 1;                                                                                                                                        \
-                                                               else if (token == '-' && !compile_calc_s)                                                                                                                      \
-                                                                   compile_calc_s = '-';                                                                                                                                      \
-                                                               else if (token == '+' && !compile_calc_s)                                                                                                                      \
-                                                                   compile_calc_s = '+';                                                                                                                                      \
-                                                           }                                                                                                                                                                  \
-                                                           if (token == ' ')                                                                                                                                                  \
-                                                               token = lex_token(file);                                                                                                                                       \
-                                                           if (NAME != 'z') {                                                                                                                                                 \
-                                                               if (token != ',' && token != ' ')                                                                                                                              \
-                                                                   error(ERROR_PARSE, "%s:%d invalid constant initializer element %c for vector (missing spaces, or comma delimited list?)\n", file->name, file->line, NAME); \
-                                                           } else if (token != '}') {                                                                                                                                         \
-                                                               error(ERROR_PARSE, "%s:%d Expected `}` on end of constant initialization for vector\n", file->name, file->line);                                               \
-                                                           }                                                                                                                                                                  \
-                                                           compile_calc_##BIT = atof(compile_data);                                                                                                                           \
-                                                           compile_calc_d = 0;                                                                                                                                                \
-                                                           compile_calc_s = 0;                                                                                                                                                \
-                                                           compile_eval   = &compile_data[0];                                                                                                                                 \
+                                                       #define PARSE_VEC_ELEMENT(NAME, BIT)                                                                                                           \
+                                                           token = lex_token(file);                                                                                                                   \
+                                                           if (token == ' ')                                                                                                                          \
+                                                               token = lex_token(file);                                                                                                               \
+                                                           if (token == '.')                                                                                                                          \
+                                                               compile_calc_d = 1;                                                                                                                    \
+                                                           if (!isdigit(token) && !compile_calc_d && token != '+' && token != '-')                                                                    \
+                                                               error(file, ERROR_PARSE,"Invalid constant initializer element %c for vector, must be numeric\n", NAME);                                \
+                                                           if (token == '+')                                                                                                                          \
+                                                               compile_calc_s = '+';                                                                                                                  \
+                                                           if (token == '-' && !compile_calc_s)                                                                                                       \
+                                                               compile_calc_s = '-';                                                                                                                  \
+                                                           while (isdigit(token) || token == '.' || token == '+' || token == '-') {                                                                   \
+                                                               *compile_eval++ = token;                                                                                                               \
+                                                               token           = lex_token(file);                                                                                                     \
+                                                               if (token == '.' && compile_calc_d) {                                                                                                  \
+                                                                   error(file, ERROR_PARSE, "Invalid constant initializer element %c for vector, must be numeric.\n", NAME);                          \
+                                                                   token = lex_token(file);                                                                                                           \
+                                                               }                                                                                                                                      \
+                                                               if ((token == '-' || token == '+') && compile_calc_s) {                                                                                \
+                                                                   error(file, ERROR_PARSE, "Invalid constant initializer sign for vector element %c\n", NAME);                                       \
+                                                                   token = lex_token(file);                                                                                                           \
+                                                               }                                                                                                                                      \
+                                                               else if (token == '.' && !compile_calc_d)                                                                                              \
+                                                                   compile_calc_d = 1;                                                                                                                \
+                                                               else if (token == '-' && !compile_calc_s)                                                                                              \
+                                                                   compile_calc_s = '-';                                                                                                              \
+                                                               else if (token == '+' && !compile_calc_s)                                                                                              \
+                                                                   compile_calc_s = '+';                                                                                                              \
+                                                           }                                                                                                                                          \
+                                                           if (token == ' ')                                                                                                                          \
+                                                               token = lex_token(file);                                                                                                               \
+                                                           if (NAME != 'z') {                                                                                                                         \
+                                                               if (token != ',' && token != ' ')                                                                                                      \
+                                                                   error(file, ERROR_PARSE, "invalid constant initializer element %c for vector (missing spaces, or comma delimited list?)\n", NAME); \
+                                                           } else if (token != '}') {                                                                                                                 \
+                                                               error(file, ERROR_PARSE, "Expected `}` on end of constant initialization for vector\n");                                               \
+                                                           }                                                                                                                                          \
+                                                           compile_calc_##BIT = atof(compile_data);                                                                                                   \
+                                                           compile_calc_d = 0;                                                                                                                        \
+                                                           compile_calc_s = 0;                                                                                                                        \
+                                                           compile_eval   = &compile_data[0];                                                                                                         \
                                                            memset(compile_data, 0, sizeof(compile_data))
                                                        
                                                        /*
@@ -211,7 +207,7 @@ int parse_gen(struct lex_file *file) {
                                                        if (token == ' ')
                                                                token = lex_token(file);
                                                        if (token != ';')
-                                                               error(ERROR_PARSE, "%s:%d Expected `;` on end of constant initialization for vector\n", file->name, file->line);
+                                                               error(file, ERROR_PARSE, "Expected `;` on end of constant initialization for vector\n");
                                                                
                                                        /* add the compile-time constant */
                                                        compile_constants_add((constant){
@@ -230,7 +226,7 @@ int parse_gen(struct lex_file *file) {
                                                case TOKEN_ENTITY:
                                                case TOKEN_FLOAT: /*TODO: validate, constant generation, name constant */
                                                        if (!isdigit(token))
-                                                               error(ERROR_PARSE, "%s:%d Expected numeric constant for float constant\n");
+                                                               error(file, ERROR_PARSE, "Expected numeric constant for float constant\n");
                                                        compile_constants_add((constant){
                                                                .name   = util_strdup(name),
                                                                .type   = TOKEN_FLOAT,
@@ -268,13 +264,13 @@ int parse_gen(struct lex_file *file) {
                                        while (*file->lastok != '"' && token != '\n')
                                                token = lex_token(file);
                                        if (token == '\n')
-                                               return error(ERROR_PARSE, "%d: Invalid use of include preprocessor directive: wanted #include \"file.h\"\n", file->line-1);
+                                               return error(file, ERROR_PARSE, "Invalid use of include preprocessor directive: wanted #include \"file.h\"\n");
                                                
                                        char            *copy = util_strdup(file->lastok);
                                        struct lex_file *next = lex_include(file,   copy);
                                        
                                        if (!next) {
-                                               error(ERROR_INTERNAL, "Include subsystem failure\n");
+                                               error(file, ERROR_INTERNAL, "Include subsystem failure\n");
                                                exit (-1);
                                        }
                                        compile_constants_add((constant) {