@@ -130,12 +130,17 @@ EssentialTypeCategory getEssentialTypeCategory(Type type) {
130130 essentialType .( IntegralType ) .isSigned ( ) and
131131 not essentialType instanceof PlainCharType
132132 or
133+ // Anonymous enums are considered to be signed
134+ result = EssentiallySignedType ( ) and
135+ essentialType instanceof AnonymousEnumType and
136+ not essentialType instanceof MisraBoolType
137+ or
133138 result = EssentiallyUnsignedType ( ) and
134139 essentialType .( IntegralType ) .isUnsigned ( ) and
135140 not essentialType instanceof PlainCharType
136141 or
137142 result = EssentiallyEnumType ( ) and
138- essentialType instanceof Enum and
143+ essentialType instanceof NamedEnumType and
139144 not essentialType instanceof MisraBoolType
140145 or
141146 result = EssentiallyFloatingType ( ) and
@@ -348,16 +353,51 @@ class EssentialBinaryArithmeticExpr extends EssentialExpr, BinaryArithmeticOpera
348353 }
349354}
350355
356+ /**
357+ * A named Enum type, as per D.5.
358+ */
359+ class NamedEnumType extends Enum {
360+ NamedEnumType ( ) {
361+ not isAnonymous ( )
362+ or
363+ exists ( Type useOfEnum | this = useOfEnum .stripType ( ) |
364+ exists ( TypedefType t | t .getBaseType ( ) = useOfEnum )
365+ or
366+ exists ( Function f | f .getType ( ) = useOfEnum or f .getAParameter ( ) .getType ( ) = useOfEnum )
367+ or
368+ exists ( Struct s | s .getAField ( ) .getType ( ) = useOfEnum )
369+ or
370+ exists ( Variable v | v .getType ( ) = useOfEnum )
371+ )
372+ }
373+ }
374+
375+ /**
376+ * An anonymous Enum type, as per D.5.
377+ */
378+ class AnonymousEnumType extends Enum {
379+ AnonymousEnumType ( ) { not this instanceof NamedEnumType }
380+ }
381+
382+ /**
383+ * The EssentialType of an EnumConstantAccess, which may be essentially enum or essentially signed.
384+ */
351385class EssentialEnumConstantAccess extends EssentialExpr , EnumConstantAccess {
352- override Type getEssentialType ( ) { result = getTarget ( ) .getDeclaringEnum ( ) }
386+ override Type getEssentialType ( ) {
387+ exists ( Enum e | e = getTarget ( ) .getDeclaringEnum ( ) |
388+ if e instanceof NamedEnumType then result = e else result = stlr ( this )
389+ )
390+ }
353391}
354392
355393class EssentialLiteral extends EssentialExpr , Literal {
356394 override Type getEssentialType ( ) {
357395 if this instanceof BooleanLiteral
358- then result instanceof MisraBoolType
396+ then
397+ // This returns a multitude of types - not sure if we really want that
398+ result instanceof MisraBoolType
359399 else (
360- if this . ( CharLiteral ) . getCharacter ( ) . length ( ) = 1
400+ if this instanceof CharLiteral
361401 then result instanceof PlainCharType
362402 else
363403 exists ( Type underlyingStandardType |
0 commit comments