ianh / owl

A parser generator for visibly pushdown languages.
MIT License
746 stars 21 forks source link

Compiler warning in generated code #34

Closed WarrenWeckesser closed 1 year ago

WarrenWeckesser commented 1 year ago

FYI: I just tried re-building this owl experiment

https://github.com/WarrenWeckesser/experiments/tree/master/c/gufunc-out-expr

using 93a6b7c0cf47391f4c917fc8d5810d9ca0938e55. I get the following compiler warning (converted to an error because of -Werror):

$ make
gcc -Wall -Werror -pedantic -std=c99 main.c -lm -o main
In file included from main.c:9:
dim-expr-parser.h: In function ‘owl_default_tokenizer_advance’:
dim-expr-parser.h:787:25: error: variable ‘string’ set but not used [-Werror=unused-but-set-variable]
  787 |             const char *string = text + content_offset;
      |                         ^~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:5: main] Error 1

The following is the generated code around line 787:

        else if (token == 4294967295U) {
            size_t content_offset = offset + 1;
            size_t content_length = token_length - 2;
            const char *string = text + content_offset;  // <<< line 787
            size_t string_length = content_length;
            if (has_escapes) {
                for (size_t i = 0;
                i < content_length;
                ++i) {
                    if (text[content_offset + i] == '\\') {
                        string_length--;
                        i++;
                    }
                }
                char *unescaped = allocate_string_contents(string_length, tokenizer->info);
                size_t j = 0;
                for (size_t i = 0;
                i < content_length;
                ++i) {
                    if (text[content_offset + i] == '\\') i++;
                    unescaped[j++] = ESCAPE_CHAR(text[content_offset + i], tokenizer->info);
                }
                string = unescaped;
            }
            IGNORE_TOKEN_WRITE(offset, token_length, string, string_length, has_escapes, tokenizer->info);
        }

This is not a major issue for me, since this is still just an experiment with owl, but I thought you'd like to know.

ianh commented 1 year ago

Thanks for the report! This should be fixed in bb2ea147.

WarrenWeckesser commented 1 year ago

That works, thanks!