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

Method OutputExpression

hlslparser/src/HLSLGenerator.cpp:294–539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

292}
293
294void HLSLGenerator::OutputExpression(HLSLExpression* expression)
295{
296 if (expression->nodeType == HLSLNodeType_IdentifierExpression) {
297 HLSLIdentifierExpression* identifierExpression = static_cast<HLSLIdentifierExpression*>(expression);
298 const char* name = identifierExpression->name;
299
300 m_writer.Write("%s", name);
301 }
302 else if (expression->nodeType == HLSLNodeType_CastingExpression) {
303 HLSLCastingExpression* castingExpression = static_cast<HLSLCastingExpression*>(expression);
304 m_writer.Write("(");
305 // OutputDeclaration(castingExpression->type, ""); // old - adds space after type
306 OutputDeclarationType(castingExpression->type, true /*isTypeCast*/); // new
307 m_writer.Write(")");
308
309 // These parens may not be needed
310 m_writer.Write("(");
311 OutputExpression(castingExpression->expression);
312 m_writer.Write(")");
313 }
314 else if (expression->nodeType == HLSLNodeType_ConstructorExpression) {
315 HLSLConstructorExpression* constructorExpression = static_cast<HLSLConstructorExpression*>(expression);
316 m_writer.Write("%s(", GetTypeName(constructorExpression->type));
317 OutputExpressionList(constructorExpression->argument);
318 m_writer.Write(")");
319 }
320 else if (expression->nodeType == HLSLNodeType_LiteralExpression) {
321 HLSLLiteralExpression* literalExpression = static_cast<HLSLLiteralExpression*>(expression);
322
323 HLSLBaseType type = literalExpression->type;
324 if (m_options.treatHalfAsFloat && IsHalf(type))
325 type = HLSLBaseType_Float;
326
327 switch (type) {
328 case HLSLBaseType_Half:
329 case HLSLBaseType_Float:
330 case HLSLBaseType_Double: {
331 // Don't use printf directly so that we don't use the system locale.
332 char buffer[64];
333 String_FormatFloat(buffer, sizeof(buffer), literalExpression->fValue);
334 String_StripTrailingFloatZeroes(buffer);
335 m_writer.Write("%s%s", buffer, type == HLSLBaseType_Half ? "h" : "");
336 } break;
337
338 case HLSLBaseType_Short:
339 case HLSLBaseType_Ulong:
340 case HLSLBaseType_Int:
341 m_writer.Write("%d", literalExpression->iValue);
342 break;
343 // TODO: missing uint, u/short, u/long double
344
345 case HLSLBaseType_Bool:
346 m_writer.Write("%s", literalExpression->bValue ? "true" : "false");
347 break;
348 default:
349 Error("Unhandled literal");
350 //ASSERT(false);
351 }

Callers

nothing calls this directly

Calls 5

IsHalfFunction · 0.85
String_FormatFloatFunction · 0.85
WriteMethod · 0.80
NeedsParenthesisFunction · 0.70

Tested by

no test coverage detected