sctincman / freeocl

OpenCL 1.2 implementation targeting CPUs, utilizing an external C++ compiler
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Parser errors on unions as struct members #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run luxmark 
2. Select "Mode->OpenCL CPUs-only"
3. "syntax error, '}' expected"

What is the expected output? What do you see instead?

Luxmark should succeed, but the parser errors out on the first struct that 
defines a union as a member.

This seems to be the offending struct (though there are more further down in 
the source):

typedef struct {
        TextureMapping2DType type;
        union {
                UVMappingParam uvMapping2D;
        };
} TextureMapping2D;

The struct parsing routine that is throwing the error seems to have trouble 
with the union definition, but I am having difficulty finding a way to amend 
the parser and/or confirm it is the union causing the syntax error.

Original issue reported on code.google.com by sctinc...@gmail.com on 2 Mar 2015 at 5:14

GoogleCodeExporter commented 9 years ago
The problem comes from the union is unnamed.
The method responsible for parsing unions/structs which should handle this is 
parser::__struct_declaration() in parser.cpp but it contains a single rule:
MATCH3(specifier_qualifier_list, struct_declarator_list, token<';'>)

In the case of an unnamed union there is no struct_declarator_list. When only 1 
or 2 elements are matched, it doesn't quit with an error and rolls back to the 
"union" word which doesn't match the '}' expected to end the struct definition.

There are 2 things to be fixed here:
* handle the case where struct_declarator_list is missing
* when only specifier_qualifier_list is matched quit with an error

struct_type doesn't handle unnamed unions, it needs to be implemented (using 
empty member names should work without too much troubles).

Original comment by zuzu...@gmail.com on 2 Mar 2015 at 10:13