MATLAB Answers

Custom Rule polyspace: typedef errors not being detected when custom types are being defined

2 views (last 30 days)
Alex Torrubia
Alex Torrubia on 1 Jul 2021
Commented: Alex Torrubia on 2 Jul 2021
Hello,
I'm having an issue with Polyspace custom rules, it doesn't detect when I try to do a typedef from a custom defined type to the type I want to define, but the regex works fine when I swap from the custom defined type to an int/char.
I have defined in a header file:
/* Platform_types.h*/
typedef signed char sint8;
typedef unsigned char uint8;
typedef signed short sint16;
typedef unsigned short uint16;
typedef signed long sint32;
typedef unsigned long uint32;
typedef sint8 SInt8;
typedef uint8 UInt8;
typedef sint16 SInt16;
typedef uint16 UInt16;
typedef sint32 SInt32;
typedef uint32 UInt32;
Then, I want to test my regex code for this type definitions:
/* Typesdef check */
/* Correct typedef */
typedef UInt8 Spi_ChannelType;
typedef UInt8 Spi_VariousWordsType;
typedef UInt8 I2c_ErrorReturnType;
/* Incorrect typedef */
typedef UInt8 Spi_CHANNEL_TYPE;
typedef UInt8 I2C_CHaNNelType;
typedef UInt8 CAN_ChannelType;
typedef UInt8 SpiChannelType;
typedef UInt16 t_channel;
typedef UInt8 Several__Underscores;
typedef UInt8 camel_CaseType;
The issue I have here, is that using the previously defined UIntX types, the incorrect typedef is not detected, but when I use the normal types (u/s int i.e.) All the incorrect typedefs are detected.
The typedef rules only work with int/float types on the left or am I missing something?
Thank you for your time.

Answers (1)

Anirban
Anirban on 1 Jul 2021
Edited: Anirban on 1 Jul 2021
I am assuming that you are using custom rules of group 3. I think, the way the checker works, it looks at each typedef of the form:
typedef type1 type2
and parses type1 to determine if the type is an integer type, a floating point type, a pointer, an array or a function pointer. The parsing happens before any type resolution. So, if type1 is itself a derived type, this parsing does not tell the checker what something like UInt8 means, and so the custom rules fail to apply.
I don't think you want the parsing to happen after type resolution either. That is, for instance, you do not want all typedef-s of unsigned char to follow your regex. You probably want only typedefs of UInt8 to follow your regex.
Depending on your exact needs, there might be workarounds. Please contact MathWorks Technical Support: https://www.mathworks.com/support/contact_us.html

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by