MCPcopy Create free account
hub / github.com/csyonghe/Spire / ExtractExternComponentInfo

Method ExtractExternComponentInfo

Source/SpireCore/CLikeCodeGen.cpp:843–919  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

841 }
842
843 ExternComponentCodeGenInfo CLikeCodeGen::ExtractExternComponentInfo(const ILObjectDefinition & input)
844 {
845 auto type = input.Type.Ptr();
846 auto recType = ExtractRecordType(type);
847 ExternComponentCodeGenInfo info;
848 info.Type = type;
849 Token bindingVal;
850 if (input.Attributes.TryGetValue("Binding", bindingVal))
851 info.Binding = StringToInt(bindingVal.Content);
852 if (recType)
853 {
854 if (auto genType = dynamic_cast<ILGenericType*>(type))
855 {
856 if (genType->GenericTypeName == "Patch")
857 {
858 type = genType->BaseType.Ptr();
859 info.DataStructure = ExternComponentCodeGenInfo::DataStructureType::Patch;
860 }
861 }
862 if (auto arrType = dynamic_cast<ILArrayType*>(type))
863 {
864 if (info.DataStructure != ExternComponentCodeGenInfo::DataStructureType::StandardInput &&
865 info.DataStructure != ExternComponentCodeGenInfo::DataStructureType::Patch)
866 {
867 errWriter->diagnose(input.Position, Diagnostics::cannotGenerateCodeForExternComponentType, type);
868 }
869 type = arrType->BaseType.Ptr();
870 info.IsArray = true;
871 info.ArrayLength = arrType->ArrayLength;
872 }
873 if (type != recType)
874 {
875 errWriter->diagnose(input.Position, Diagnostics::cannotGenerateCodeForExternComponentType, type);
876 }
877 }
878 else
879 {
880 // check for attributes
881 if (input.Attributes.ContainsKey("TessCoord"))
882 {
883 info.SystemVar = ExternComponentCodeGenInfo::SystemVarType::TessCoord;
884 if (!(input.Type->IsFloatVector() && input.Type->GetVectorSize() <= 3))
885 getSink()->diagnose(input.Position, Diagnostics::invalidTessCoordType);
886 }
887 else if (input.Attributes.ContainsKey("FragCoord"))
888 {
889 info.SystemVar = ExternComponentCodeGenInfo::SystemVarType::FragCoord;
890 if (!(input.Type->IsFloatVector() && input.Type->GetVectorSize() == 4))
891 getSink()->diagnose(input.Position, Diagnostics::invalidFragCoordType);
892 }
893 else if (input.Attributes.ContainsKey("InvocationId"))
894 {
895 info.SystemVar = ExternComponentCodeGenInfo::SystemVarType::InvocationId;
896 if (!input.Type->IsInt())
897 getSink()->diagnose(input.Position, Diagnostics::invalidInvocationIdType);
898 }
899 else if (input.Attributes.ContainsKey("ThreadId"))
900 {

Callers

nothing calls this directly

Calls 9

ExtractRecordTypeFunction · 0.85
StringToIntFunction · 0.85
diagnoseMethod · 0.80
IsFloatVectorMethod · 0.80
GetVectorSizeMethod · 0.80
IsIntMethod · 0.80
PtrMethod · 0.45
TryGetValueMethod · 0.45
ContainsKeyMethod · 0.45

Tested by

no test coverage detected