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

Method GetMemberType

hlslparser/src/HLSLParser.cpp:4575–4703  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4573}
4574
4575bool HLSLParser::GetMemberType(const HLSLType& objectType, HLSLMemberAccess* memberAccess)
4576{
4577 const char* fieldName = memberAccess->field;
4578
4579 HLSLBaseType baseType = objectType.baseType;
4580
4581 // pull field from struct
4582 if (baseType == HLSLBaseType_UserDefined) {
4583 const HLSLStruct* structure = FindUserDefinedType(objectType.typeName);
4584 ASSERT(structure != NULL);
4585 if (structure == NULL)
4586 return false;
4587
4588 const HLSLStructField* field = structure->field;
4589 while (field != NULL) {
4590 if (field->name == fieldName) {
4591 memberAccess->expressionType = field->type;
4592 return true;
4593 }
4594 field = field->nextField;
4595 }
4596
4597 return false;
4598 }
4599
4600 if (baseTypeDescriptions[objectType.baseType].numericType == NumericType_NaN) {
4601 // Currently we don't have an non-numeric types that allow member access.
4602 return false;
4603 }
4604
4605 int swizzleLength = 0;
4606
4607 if (IsScalarType(baseType) || IsVectorType(baseType)) {
4608 // Check for a swizzle on the scalar/vector types.
4609 for (int i = 0; fieldName[i] != 0; ++i) {
4610 if (!IsSwizzle(fieldName[i])) {
4611 m_tokenizer.Error("Invalid swizzle '%s'", fieldName);
4612 return false;
4613 }
4614 ++swizzleLength;
4615 }
4616 ASSERT(swizzleLength > 0);
4617 if (swizzleLength == 0)
4618 return false;
4619 }
4620 else if (IsMatrixType(baseType)) {
4621 // Check for a matrix element access (e.g. _m00 or _11)
4622
4623 const char* n = fieldName;
4624 while (n[0] == '_') {
4625 ++n;
4626 int base = 1;
4627 if (n[0] == 'm') {
4628 base = 0;
4629 ++n;
4630 }
4631 if (!isdigit(n[0]) || !isdigit(n[1])) {
4632 m_tokenizer.Error("Invalid matrix digit");

Callers

nothing calls this directly

Calls 5

IsScalarTypeFunction · 0.85
IsVectorTypeFunction · 0.85
IsSwizzleFunction · 0.85
IsMatrixTypeFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected