Skip to content

Commit

Permalink
feat: code opt
Browse files Browse the repository at this point in the history
  • Loading branch information
Sway007 committed Oct 12, 2024
1 parent eb515be commit fb3974e
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/shader-lab/src/GSError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export class GSError extends Error {
}
}

// #endif
export enum GSErrorName {
PreprocessorError = "PreprocessorError",
CompilationError = "CompilationError",
ScannerError = "ScannerError"
}
// #endif
7 changes: 5 additions & 2 deletions packages/shader-lab/src/ShaderLabUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ClearableObjectPool, IPoolElement } from "@galacean/engine";
import { GSError, GSErrorName } from "./GSError";
import { GSErrorName } from "./GSError";
import { ShaderRange } from "./common/ShaderRange";
import { ShaderPosition } from "./common/ShaderPosition";
// #if _VERBOSE
import { GSError } from "./GSError";
// #endif

export class ShaderLabUtils {
private static _shaderLabObjectPoolSet: ClearableObjectPool<IPoolElement>[] = [];
Expand All @@ -28,7 +31,7 @@ export class ShaderLabUtils {
// #if _VERBOSE
return new GSError(errorName, message, location, source, file);
// #else
throw new Error(message);
throw new Error(`[${errorName}]: ${message}`);
// #endif
}
}
5 changes: 3 additions & 2 deletions packages/shader-lab/src/codeGen/CodeGenVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { ESymbolType, FnSymbol, VarSymbol } from "../parser/symbolTable";
import { ParserUtils } from "../ParserUtils";
import { NodeChild } from "../parser/types";
import { VisitorContext } from "./VisitorContext";
import { ShaderLab } from "../ShaderLab";
import { GSErrorName } from "../GSError";
// #if _VERBOSE
import { GSErrorName, GSError } from "../GSError";
import { GSError } from "../GSError";
// #endif
import { ShaderLab } from "../ShaderLab";

/**
* @internal
Expand Down
7 changes: 4 additions & 3 deletions packages/shader-lab/src/codeGen/VisitorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { EShaderStage } from "../common/Enums";
import { ASTNode } from "../parser/AST";
import { ESymbolType, SymbolTable, SymbolInfo } from "../parser/symbolTable";
import { IParamInfo } from "../parser/types";
// #if _VERBOSE
import { GSErrorName, GSError } from "../GSError";
// #endif
import { GSErrorName } from "../GSError";
import { BaseToken } from "../common/BaseToken";
import { ShaderLab } from "../ShaderLab";
import { ShaderLabUtils } from "../ShaderLabUtils";
// #if _VERBOSE
import { GSError } from "../GSError";
// #endif

/** @internal */
export class VisitorContext {
Expand Down
5 changes: 1 addition & 4 deletions packages/shader-lab/src/common/BaseScanner.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Logger } from "@galacean/engine";
import { ETokenType, ShaderRange, ShaderPosition } from ".";
// #if _VERBOSE
import { GSError, GSErrorName } from "../GSError";
// #endif
import { GSErrorName } from "../GSError";
import { ShaderLab } from "../ShaderLab";
import { BaseToken } from "./BaseToken";
import { ShaderLabUtils } from "../ShaderLabUtils";
Expand Down
3 changes: 2 additions & 1 deletion packages/shader-lab/src/contentParser/ShaderContentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import {
IShaderPassContent,
IRenderStates
} from "@galacean/engine-design";
import { GSErrorName } from "../GSError";
// #if _VERBOSE
import { GSError, GSErrorName } from "../GSError";
import { GSError } from "../GSError";
import { ShaderLabUtils } from "../ShaderLabUtils";
// #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
@@ -1,13 +1,14 @@
import { ShaderRange } from "../common";
import { TreeNode } from "./AST";
// #if _VERBOSE
import { GSError, GSErrorName } from "../GSError";
// #endif
import { GSErrorName } from "../GSError";
import { ShaderData } from "./ShaderInfo";
import { SymbolInfo, SymbolTable } from "../parser/symbolTable";
import { NodeChild } from "./types";
import { SymbolTableStack } from "../common/BaseSymbolTable";
import { ShaderLab } from "../ShaderLab";
// #if _VERBOSE
import { GSError } from "../GSError";
// #endif

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

Expand Down
4 changes: 1 addition & 3 deletions packages/shader-lab/src/parser/ShaderTargetParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import { addTranslationRule, createGrammar } from "../lalr/CFG";
import { LALR1 } from "../lalr";
import { ParserUtils } from "../ParserUtils";
import { Logger } from "@galacean/engine";
// #if _VERBOSE
import { GSError, GSErrorName } from "../GSError";
// #endif
import { GSErrorName } from "../GSError";
import { ShaderLab } from "../ShaderLab";
import { ShaderLabUtils } from "../ShaderLabUtils";

Expand Down
8 changes: 4 additions & 4 deletions packages/shader-lab/src/preprocessor/PpParser.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ShaderPosition, ShaderRange } from "../common";
import LexerUtils from "../lexer/Utils";
import { MacroDefine } from "./MacroDefine";
// #if _VERBOSE
import PpSourceMap, { BlockInfo } from "./sourceMap";
import { GSError, GSErrorName } from "../GSError";
// #endif
import { BaseToken } from "../common/BaseToken";
import { EPpKeyword, EPpToken, PpConstant } from "./constants";
import PpScanner from "./PpScanner";
import { PpUtils } from "./Utils";
import { ShaderLab } from "../ShaderLab";
import { ShaderPass } from "@galacean/engine";
import { ShaderLabUtils } from "../ShaderLabUtils";
import { GSErrorName } from "../GSError";
// #if _VERBOSE
import PpSourceMap, { BlockInfo } from "./sourceMap";
// #endif

export interface ExpandSegment {
// #if _VERBOSE
Expand Down

0 comments on commit fb3974e

Please sign in to comment.