Skip to content

Commit 15171eb

Browse files
committed
C++: Un-nest the if-then-else sequence.
1 parent d6f9eb2 commit 15171eb

File tree

1 file changed

+75
-113
lines changed

1 file changed

+75
-113
lines changed

cpp/ql/lib/semmle/code/cpp/valuenumbering/HashCons.qll

Lines changed: 75 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -148,119 +148,81 @@ class HashCons extends HCBase {
148148

149149
/** Gets the kind of the HC. This can be useful for debugging. */
150150
string getKind() {
151-
if this instanceof HC_IntLiteral
152-
then result = "IntLiteral"
153-
else
154-
if this instanceof HC_EnumConstantAccess
155-
then result = "EnumConstantAccess"
156-
else
157-
if this instanceof HC_FloatLiteral
158-
then result = "FloatLiteral"
159-
else
160-
if this instanceof HC_StringLiteral
161-
then result = "StringLiteral"
162-
else
163-
if this instanceof HC_Nullptr
164-
then result = "Nullptr"
165-
else
166-
if this instanceof HC_Variable
167-
then result = "Variable"
168-
else
169-
if this instanceof HC_FieldAccess
170-
then result = "FieldAccess"
171-
else
172-
if this instanceof HC_Deref
173-
then result = "Deref"
174-
else
175-
if this instanceof HC_ThisExpr
176-
then result = "ThisExpr"
177-
else
178-
if this instanceof HC_Conversion
179-
then result = "Conversion"
180-
else
181-
if this instanceof HC_BinaryOp
182-
then result = "BinaryOp"
183-
else
184-
if this instanceof HC_UnaryOp
185-
then result = "UnaryOp"
186-
else
187-
if this instanceof HC_ArrayAccess
188-
then result = "ArrayAccess"
189-
else
190-
if this instanceof HC_Unanalyzable
191-
then result = "Unanalyzable"
192-
else
193-
if this instanceof HC_NonmemberFunctionCall
194-
then result = "NonmemberFunctionCall"
195-
else
196-
if this instanceof HC_MemberFunctionCall
197-
then result = "MemberFunctionCall"
198-
else
199-
if this instanceof HC_NewExpr
200-
then result = "NewExpr"
201-
else
202-
if this instanceof HC_NewArrayExpr
203-
then result = "NewArrayExpr"
204-
else
205-
if this instanceof HC_SizeofType
206-
then result = "SizeofTypeOperator"
207-
else
208-
if this instanceof HC_SizeofExpr
209-
then result = "SizeofExprOperator"
210-
else
211-
if this instanceof HC_AlignofType
212-
then result = "AlignofTypeOperator"
213-
else
214-
if this instanceof HC_AlignofExpr
215-
then result = "AlignofExprOperator"
216-
else
217-
if this instanceof HC_UuidofOperator
218-
then result = "UuidofOperator"
219-
else
220-
if this instanceof HC_TypeidType
221-
then result = "TypeidType"
222-
else
223-
if this instanceof HC_TypeidExpr
224-
then result = "TypeidExpr"
225-
else
226-
if this instanceof HC_ArrayAggregateLiteral
227-
then result = "ArrayAggregateLiteral"
228-
else
229-
if this instanceof HC_ClassAggregateLiteral
230-
then result = "ClassAggregateLiteral"
231-
else
232-
if this instanceof HC_DeleteExpr
233-
then result = "DeleteExpr"
234-
else
235-
if this instanceof HC_DeleteArrayExpr
236-
then result = "DeleteArrayExpr"
237-
else
238-
if this instanceof HC_ThrowExpr
239-
then result = "ThrowExpr"
240-
else
241-
if this instanceof HC_ReThrowExpr
242-
then result = "ReThrowExpr"
243-
else
244-
if this instanceof HC_ExprCall
245-
then result = "ExprCall"
246-
else
247-
if
248-
this instanceof
249-
HC_ConditionalExpr
250-
then result = "ConditionalExpr"
251-
else
252-
if
253-
this instanceof
254-
HC_NoExceptExpr
255-
then result = "NoExceptExpr"
256-
else
257-
if
258-
this instanceof
259-
HC_AllocatorArgZero
260-
then
261-
result =
262-
"AllocatorArgZero"
263-
else result = "error"
151+
result = this.getKind0()
152+
or
153+
not exists(this.getKind0()) and result = "error"
154+
}
155+
156+
private string getKind0() {
157+
this instanceof HC_IntLiteral and result = "IntLiteral"
158+
or
159+
this instanceof HC_EnumConstantAccess and result = "EnumConstantAccess"
160+
or
161+
this instanceof HC_FloatLiteral and result = "FloatLiteral"
162+
or
163+
this instanceof HC_StringLiteral and result = "StringLiteral"
164+
or
165+
this instanceof HC_Nullptr and result = "Nullptr"
166+
or
167+
this instanceof HC_Variable and result = "Variable"
168+
or
169+
this instanceof HC_FieldAccess and result = "FieldAccess"
170+
or
171+
this instanceof HC_Deref and result = "Deref"
172+
or
173+
this instanceof HC_ThisExpr and result = "ThisExpr"
174+
or
175+
this instanceof HC_Conversion and result = "Conversion"
176+
or
177+
this instanceof HC_BinaryOp and result = "BinaryOp"
178+
or
179+
this instanceof HC_UnaryOp and result = "UnaryOp"
180+
or
181+
this instanceof HC_ArrayAccess and result = "ArrayAccess"
182+
or
183+
this instanceof HC_Unanalyzable and result = "Unanalyzable"
184+
or
185+
this instanceof HC_NonmemberFunctionCall and result = "NonmemberFunctionCall"
186+
or
187+
this instanceof HC_MemberFunctionCall and result = "MemberFunctionCall"
188+
or
189+
this instanceof HC_NewExpr and result = "NewExpr"
190+
or
191+
this instanceof HC_NewArrayExpr and result = "NewArrayExpr"
192+
or
193+
this instanceof HC_SizeofType and result = "SizeofTypeOperator"
194+
or
195+
this instanceof HC_SizeofExpr and result = "SizeofExprOperator"
196+
or
197+
this instanceof HC_AlignofType and result = "AlignofTypeOperator"
198+
or
199+
this instanceof HC_AlignofExpr and result = "AlignofExprOperator"
200+
or
201+
this instanceof HC_UuidofOperator and result = "UuidofOperator"
202+
or
203+
this instanceof HC_TypeidType and result = "TypeidType"
204+
or
205+
this instanceof HC_TypeidExpr and result = "TypeidExpr"
206+
or
207+
this instanceof HC_ArrayAggregateLiteral and result = "ArrayAggregateLiteral"
208+
or
209+
this instanceof HC_ClassAggregateLiteral and result = "ClassAggregateLiteral"
210+
or
211+
this instanceof HC_DeleteExpr and result = "DeleteExpr"
212+
or
213+
this instanceof HC_DeleteArrayExpr and result = "DeleteArrayExpr"
214+
or
215+
this instanceof HC_ThrowExpr and result = "ThrowExpr"
216+
or
217+
this instanceof HC_ReThrowExpr and result = "ReThrowExpr"
218+
or
219+
this instanceof HC_ExprCall and result = "ExprCall"
220+
or
221+
this instanceof HC_ConditionalExpr and result = "ConditionalExpr"
222+
or
223+
this instanceof HC_NoExceptExpr and result = "NoExceptExpr"
224+
or
225+
this instanceof HC_AllocatorArgZero and result = "AllocatorArgZero"
264226
}
265227

266228
/**

0 commit comments

Comments
 (0)