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

Method VisitInvokeExpression

Source/SpireCore/CodeGenerator.cpp:1146–1210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1144 return expr;
1145 }
1146 virtual RefPtr<ExpressionSyntaxNode> VisitInvokeExpression(InvokeExpressionSyntaxNode* expr) override
1147 {
1148 List<ILOperand*> args;
1149 String funcName;
1150 bool hasSideEffect = false;
1151 if (auto basicType = expr->FunctionExpr->Type->AsBasicType())
1152 {
1153 if (basicType->Func)
1154 {
1155 funcName = basicType->Func->SyntaxNode->IsExtern() ? basicType->Func->SyntaxNode->Name.Content : basicType->Func->SyntaxNode->InternalName;
1156 for (auto & param : basicType->Func->SyntaxNode->GetParameters())
1157 {
1158 if (param->HasModifier(ModifierFlag::Out))
1159 {
1160 hasSideEffect = true;
1161 break;
1162 }
1163 }
1164 }
1165 else if (basicType->Component)
1166 {
1167 auto funcCompName = expr->FunctionExpr->Tags["ComponentReference"]().As<StringObject>()->Content;
1168 auto funcComp = *(currentShader->DefinitionsByComponent[funcCompName]().TryGetValue(currentComponent->World));
1169 funcName = GetComponentFunctionName(funcComp->SyntaxNode.Ptr());
1170 for (auto & param : funcComp->SyntaxNode->GetParameters())
1171 {
1172 if (param->HasModifier(ModifierFlag::Out))
1173 {
1174 hasSideEffect = true;
1175 break;
1176 }
1177 }
1178 // push additional arguments
1179 for (auto & dep : funcComp->GetComponentFunctionDependencyClosure())
1180 {
1181 if (!dep->SyntaxNode->IsComponentFunction())
1182 {
1183 ILOperand * op = nullptr;
1184 if (variables.TryGetValue(dep->UniqueName, op))
1185 args.Add(op);
1186 else
1187 throw InvalidProgramException("cannot resolve reference for implicit component function argument.");
1188 }
1189 }
1190 }
1191 }
1192 if (currentWorld)
1193 {
1194 currentWorld->ReferencedFunctions.Add(funcName);
1195 }
1196 for (auto arg : expr->Arguments)
1197 {
1198 arg->Accept(this);
1199 args.Add(PopStack());
1200 }
1201 auto instr = new CallInstruction(args.Count());
1202 instr->SideEffect = hasSideEffect;
1203 instr->Function = funcName;

Callers

nothing calls this directly

Calls 12

AsBasicTypeMethod · 0.80
IsExternMethod · 0.80
HasModifierMethod · 0.80
IsComponentFunctionMethod · 0.80
GetParametersMethod · 0.45
TryGetValueMethod · 0.45
PtrMethod · 0.45
AddMethod · 0.45
AcceptMethod · 0.45
CountMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected