Skip to content

Commit

Permalink
feat: code opt
Browse files Browse the repository at this point in the history
  • Loading branch information
Sway007 committed Dec 16, 2024
1 parent 637d884 commit 6f1fa10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 9 additions & 6 deletions packages/shader-lab/src/parser/AST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export namespace ASTNode {
else {
const id = child as VariableIdentifier;
if (!id.symbolInfo) {
sa.error(id.location, "Undeclared symbol:", id.lexeme);
sa.error(id.location, `Undeclared symbol: ${id.lexeme}`);
}
if (!ParserUtils.typeCompatible(EKeyword.INT, id.typeInfo)) {
sa.error(id.location, "Invalid integer.");
Expand Down Expand Up @@ -876,7 +876,7 @@ export namespace ASTNode {
const fnSymbol = sa.symbolTable.lookup({ ident: fnIdent, symbolType: ESymbolType.FN, signature: paramSig });
if (!fnSymbol) {
// #if _VERBOSE
sa.error(this.location, "No overload function type found: ", functionIdentifier.ident);
sa.error(this.location, `No overload function type found: ${functionIdentifier.ident}`);
// #endif
return;
}
Expand Down Expand Up @@ -1434,19 +1434,22 @@ export namespace ASTNode {
override semanticAnalyze(sa: SematicAnalyzer): void {
const { children } = this;
const length = children.length;
this.type = (children[0] as VariableDeclaration | VariableDeclarationList).type;
const variableDeclation = children[0] as VariableDeclaration;
const type = variableDeclation.type;
this.type = type;

if (length === 1) {
return;
}

const variableDeclation = children[0] as VariableDeclaration;
const type = variableDeclation.type;
const ident = children[2] as Token;

const newVariable = VariableDeclaration.pool.get();
if (length === 3) {
// variable_declaration_list ',' id
newVariable.set(ident.location, [type, ident]);

Check warning on line 1450 in packages/shader-lab/src/parser/AST.ts

View check run for this annotation

Codecov / codecov/patch

packages/shader-lab/src/parser/AST.ts#L1450

Added line #L1450 was not covered by tests
} else {
// variable_declaration_list ',' id array_specifier
newVariable.set(ident.location, [type, ident, children[3] as ArraySpecifier]);
}
newVariable.semanticAnalyze(sa);
Expand Down Expand Up @@ -1490,7 +1493,7 @@ export namespace ASTNode {
this.symbolInfo = sa.symbolTable.lookup({ ident: token.lexeme, symbolType: ESymbolType.VAR }) as VarSymbol;
// #if _VERBOSE
if (!this.symbolInfo) {
sa.error(this.location, "undeclared identifier:", token.lexeme);
sa.error(this.location, `undeclared identifier: ${token.lexeme}`);
}
// #endif
}
Expand Down
7 changes: 4 additions & 3 deletions packages/shader-lab/src/parser/SemanticAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ShaderLab } from "../ShaderLab";
// #if _VERBOSE
import { GSError } from "../GSError";
// #endif
import { Logger } from "@galacean/engine";

export type TranslationRule<T = any> = (sa: SematicAnalyzer, ...tokens: NodeChild[]) => T;

Expand Down Expand Up @@ -64,13 +65,13 @@ export default class SematicAnalyzer {
return this._translationRuleTable.get(pid);
}

error(loc: ShaderRange, ...param: any[]) {
error(loc: ShaderRange, message: string) {
// #if _VERBOSE
const err = new GSError(GSErrorName.CompilationError, param.join(""), loc, ShaderLab._processingPassText);
const err = new GSError(GSErrorName.CompilationError, message, loc, ShaderLab._processingPassText);
this.errors.push(err);
return err;
// #else
this.errors.push(new Error(param.join("")));
Logger.error(message);
// #endif
}
}

0 comments on commit 6f1fa10

Please sign in to comment.