MCPcopy Create free account
hub / github.com/galacean/engine / visitStructSpecifier

Function visitStructSpecifier

packages/shader-lab/src/codeGen/CodeGenVisitor.ts:290–348  ·  view source on GitHub ↗
(node: ASTNode.StructSpecifier)

Source from the content-addressed store, hash-verified

288 }
289
290 visitStructSpecifier(node: ASTNode.StructSpecifier): string {
291 const context = VisitorContext.context;
292 const { varyingStructs, attributeStructs, mrtStructs } = context;
293 const isVaryingStruct = varyingStructs.indexOf(node) !== -1;
294 const isAttributeStruct = attributeStructs.indexOf(node) !== -1;
295 const isMRTStruct = mrtStructs.indexOf(node) !== -1;
296
297 if (isVaryingStruct && isAttributeStruct) {
298 this._reportError(node.location, "cannot use same struct as Varying and Attribute");
299 }
300
301 if (isVaryingStruct && isMRTStruct) {
302 this._reportError(node.location, "cannot use same struct as Varying and MRT");
303 }
304
305 if (isAttributeStruct && isMRTStruct) {
306 this._reportError(node.location, "cannot use same struct as Attribute and MRT");
307 }
308
309 if (isVaryingStruct || isAttributeStruct || isMRTStruct) {
310 let result: ICodeSegment[] = [];
311
312 result.push(
313 ...node.macroExpressions.map((item) => ({
314 text: item instanceof BaseToken ? item.lexeme : item.codeGen(this),
315 index: item.location.start.index
316 }))
317 );
318
319 for (const prop of node.propList) {
320 const name = prop.ident.lexeme;
321 if (isVaryingStruct && context._referencedVaryingList[name]?.indexOf(prop) >= 0) {
322 result.push({
323 text: `${this.getVaryingProp(prop)}\n`,
324 index: prop.ident.location.start.index
325 });
326 } else if (isAttributeStruct && context._referencedAttributeList[name]?.indexOf(prop) >= 0) {
327 result.push({
328 text: `${this.getAttributeProp(prop)}\n`,
329 index: prop.ident.location.start.index
330 });
331 } else if (isMRTStruct && context._referencedMRTList[name]?.indexOf(prop) >= 0) {
332 result.push({
333 text: `${this.getMRTProp(prop)}\n`,
334 index: prop.ident.location.start.index
335 });
336 }
337 }
338
339 const text = result
340 .sort((a, b) => a.index - b.index)
341 .map((item) => item.text)
342 .join("");
343
344 return text;
345 } else {
346 return this.defaultCodeGen(node.children);
347 }

Callers

nothing calls this directly

Calls 9

indexOfMethod · 0.80
_reportErrorMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
sortMethod · 0.80
codeGenMethod · 0.45
getVaryingPropMethod · 0.45
getAttributePropMethod · 0.45
getMRTPropMethod · 0.45

Tested by

no test coverage detected