Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbcf8ae9

Browse files
committed
BuiltInTypeRules: Rename getRealSize to getBuiltInSize
1 parent8be7b3c commitbcf8ae9

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

‎cpp/misra/src/codingstandards/cpp/misra/BuiltInTypeRules.qll‎

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,36 @@ newtype Signedness =
8585
Signed()or
8686
Unsigned()
8787

88-
classCharacterTypeextendsType{
89-
// The actual character type, which is either a plain char or a wide char
88+
/**
89+
* A `Type` which is considered to be a built-in type by MISRA.
90+
*
91+
* It differs from `BuiltInType` in that includes:
92+
* - Built in types with specifiers (e.g., `const`, `volatile`, `restrict`).
93+
* - Typedefs to built in types
94+
* - References to built in types
95+
* - Enum types with an explicit underlying type that is a built-in type.
96+
*/
97+
classMisraBuiltInTypeextendsType{
98+
// The built in type underlying this MISRA built in type
9099
BuiltInTypebuiltInType;
91100

92-
CharacterType(){
93-
// A type whose type category is character
94-
getBuiltInTypeCategory(builtInType)=Character()and
95-
builtInType=getBuiltInType(this)
96-
}
101+
MisraBuiltInType(){builtInType=getBuiltInType(this)}
97102

98103
privateBuiltInTypegetBuiltInType(){result=builtInType}
99104

100-
predicateisSameType(CharacterTypeother){this.getBuiltInType()=other.getBuiltInType()}
105+
/** Gets the size of the underlying built in type. */
106+
intgetBuiltInSize(){result=builtInType.getSize()}
107+
108+
TypeCategorygetTypeCategory(){result=getBuiltInTypeCategory(builtInType)}
109+
110+
predicateisSameType(MisraBuiltInTypeother){this.getBuiltInType()=other.getBuiltInType()}
111+
}
112+
113+
classCharacterTypeextendsMisraBuiltInType{
114+
CharacterType(){
115+
// A type whose type category is character
116+
getBuiltInTypeCategory(builtInType)=Character()
117+
}
101118
}
102119

103120
/**
@@ -108,25 +125,16 @@ class CharacterType extends Type {
108125
* - Typedef'd types that are numeric types.
109126
* - Numeric types with specifiers (e.g., `const`, `volatile`, `restrict`).
110127
*/
111-
classNumericTypeextendsType{
112-
// The actual numeric type, which is either an integral or a floating-point type.
113-
BuiltInTypebuiltInType;
114-
128+
classNumericTypeextendsMisraBuiltInType{
115129
NumericType(){
116130
// A type whose type category is either integral or a floating-point
117-
getBuiltInTypeCategory(builtInType)=[Integral().(TypeCategory),FloatingPoint()]and
118-
builtInType=getBuiltInType(this)
131+
getBuiltInTypeCategory(builtInType)=[Integral().(TypeCategory),FloatingPoint()]
119132
}
120133

121134
SignednessgetSignedness(){
122135
ifbuiltInType.(IntegralType).isUnsigned()thenresult=Unsigned()elseresult=Signed()
123136
}
124137

125-
/** Gets the size of the actual numeric type. */
126-
intgetRealSize(){result=builtInType.getSize()}
127-
128-
TypeCategorygetTypeCategory(){result=getBuiltInTypeCategory(builtInType)}
129-
130138
/**
131139
* Gets the integeral upper bound of the numeric type, if it represents an integer type.
132140
*/
@@ -136,10 +144,6 @@ class NumericType extends Type {
136144
* Gets the integeral lower bound of the numeric type, if it represents an integer type.
137145
*/
138146
QlBuiltins::BigIntgetIntegralLowerBound(){integralTypeBounds(builtInType,result, _)}
139-
140-
privateBuiltInTypegetBuiltInType(){result=builtInType}
141-
142-
predicateisSameType(NumericTypeother){this.getBuiltInType()=other.getBuiltInType()}
143147
}
144148

145149
predicateisSignedType(NumericTypet){t.getSignedness()=Signed()}
@@ -300,7 +304,7 @@ CanonicalIntegerNumericType getBitFieldType(BitField bf) {
300304
other.getSize()*8>=bf.getNumBits()and
301305
other.getSignedness()=result.getSignedness()
302306
|
303-
other.getSize()<result.getRealSize()
307+
other.getSize()<result.getBuiltInSize()
304308
)
305309
)
306310
}

‎cpp/misra/src/rules/RULE-7-0-5/NoSignednessChangeFromPromotion.ql‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ class IntegerPromotion extends IntegerPromotionOrUsualArithmeticConversionAsCast
8989
// Only consider cases where the integer promotion is the last conversion applied
9090
exists(Expre|e.getFullyConverted()=this)and
9191
// Integer promotion occurs where the from type is smaller than int
92-
fromType.getRealSize()<sizeOfInt()and
92+
fromType.getBuiltInSize()<sizeOfInt()and
9393
// To type is bigger than or equal to int
94-
toType.getRealSize()>=sizeOfInt()and
94+
toType.getBuiltInSize()>=sizeOfInt()and
9595
// An integer promotion is a conversion from an integral type to an integral type
9696
//
9797
// This deliberately excludes integer promotions from `bool` and unscoped enums which do not
@@ -152,7 +152,7 @@ class ImpliedIntegerPromotion extends IntegerPromotionOrUsualArithmeticConversio
152152
fromType=this.getType()and
153153
fromType.getTypeCategory()=Integral()and
154154
// If the size is less than int, then it is an implied integer promotion
155-
fromType.getRealSize()<sizeOfInt()
155+
fromType.getBuiltInSize()<sizeOfInt()
156156
}
157157

158158
overrideNumericTypegetFromType(){result=fromType}

‎cpp/misra/src/rules/RULE-7-0-6/NumericAssignmentTypeMismatch.ql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ predicate isValidTypeMatch(NumericType sourceType, NumericType targetType) {
5757
// Same type category, signedness and size
5858
sourceType.getTypeCategory()=targetType.getTypeCategory()and
5959
sourceType.getSignedness()=targetType.getSignedness()and
60-
sourceType.getRealSize()=targetType.getRealSize()
60+
sourceType.getBuiltInSize()=targetType.getBuiltInSize()
6161
}
6262

6363
/**
@@ -118,7 +118,7 @@ predicate isValidWidening(Expr source, NumericType sourceType, NumericType targe
118118
)and
119119
sourceType.getTypeCategory()=targetType.getTypeCategory()and
120120
sourceType.getSignedness()=targetType.getSignedness()and
121-
sourceType.getRealSize()<targetType.getRealSize()
121+
sourceType.getBuiltInSize()<targetType.getBuiltInSize()
122122
}
123123

124124
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp