MCPcopy Create free account
hub / github.com/alecazam/kram / GetExpressionValue

Method GetExpressionValue

hlslparser/src/HLSLTree.cpp:260–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260bool HLSLTree::GetExpressionValue(HLSLExpression *expression, int &value)
261{
262 ASSERT(expression != NULL);
263
264 // Expression must be constant.
265 if ((expression->expressionType.flags & HLSLTypeFlag_Const) == 0) {
266 return false;
267 }
268
269 // We are expecting an integer scalar.
270 // TODO: Add support for type conversion from uint scalar types.
271 if (expression->expressionType.baseType != HLSLBaseType_Long &&
272 expression->expressionType.baseType != HLSLBaseType_Short &&
273 expression->expressionType.baseType != HLSLBaseType_Int &&
274
275 expression->expressionType.baseType != HLSLBaseType_Bool) {
276 return false;
277 }
278
279 if (expression->expressionType.array) {
280 return false;
281 }
282
283 if (expression->nodeType == HLSLNodeType_BinaryExpression) {
284 HLSLBinaryExpression *binaryExpression = (HLSLBinaryExpression *)expression;
285
286 int value1, value2;
287 if (!GetExpressionValue(binaryExpression->expression1, value1) ||
288 !GetExpressionValue(binaryExpression->expression2, value2)) {
289 return false;
290 }
291
292 switch (binaryExpression->binaryOp) {
293 case HLSLBinaryOp_And:
294 value = value1 && value2;
295 return true;
296 case HLSLBinaryOp_Or:
297 value = value1 || value2;
298 return true;
299 case HLSLBinaryOp_Add:
300 value = value1 + value2;
301 return true;
302 case HLSLBinaryOp_Sub:
303 value = value1 - value2;
304 return true;
305 case HLSLBinaryOp_Mul:
306 value = value1 * value2;
307 return true;
308 case HLSLBinaryOp_Div:
309 value = value1 / value2;
310 return true;
311 case HLSLBinaryOp_Less:
312 value = value1 < value2;
313 return true;
314 case HLSLBinaryOp_Greater:
315 value = value1 > value2;
316 return true;
317 case HLSLBinaryOp_LessEqual:

Callers 2

OutputStatementsMethod · 0.80
GetTypeCastRankFunction · 0.80

Calls 4

IsIntegerTypeFunction · 0.85
IsScalarTypeFunction · 0.85
IsFloatingTypeFunction · 0.85
GetVectorDimensionFunction · 0.85

Tested by

no test coverage detected