windelbouwman / ppci

A compiler for ARM, X86, MSP430, xtensa and more implemented in pure Python
https://ppci.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
337 stars 36 forks source link

ppci-cc: switch/case statements should be better tested in the front-end #111

Open tstreiff opened 4 years ago

tstreiff commented 4 years ago

All switch/case contraints are not tested by the front-end, and this makes the code generator crash or generate wrong code:

Side remarks The compiler ensures that no case value is duplicated, but this is done in the IR code generator, it seems more logical to do this during the semantics checking.

In nodes/types.py some type predicates are a bit confusing because they do not follow the C standards:

tstreiff commented 4 years ago

I am writing a fix for this issue.

I am fighting with the notion of "constant expression" (which appears at several places in the C grammar). It looks as if "parse_constant_expression()" does not ensure that the expression is really constant and it returns the found expression unchanged. I haven't found any easy way to compute the value of an expression such as 2+3 or even -1 in the parsing/semantics pass. Did I miss something obvious?