From 94410accf41dd752861f002b33502db64cbcd74d Mon Sep 17 00:00:00 2001 From: Leonard2 Date: Sun, 30 Oct 2016 04:35:01 +0100 Subject: [PATCH] Renamed "VectorInitializer" to "VectorValue" This was really confusing for me as this is an actual vector "value" rather than an "initializer" --- src/scripting/codegeneration/codegen.cpp | 14 ++++---- src/scripting/codegeneration/codegen.h | 8 ++--- src/scripting/zscript/ast.cpp | 2 +- src/scripting/zscript/zcc-parse.lemon | 46 +++++++++++------------- src/scripting/zscript/zcc_compile.cpp | 6 ++-- src/scripting/zscript/zcc_parser.h | 4 +-- 6 files changed, 37 insertions(+), 43 deletions(-) diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index d2ca17db59..0930399025 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -446,8 +446,8 @@ ExpEmit FxConstant::Emit(VMFunctionBuilder *build) // //========================================================================== -FxVectorInitializer::FxVectorInitializer(FxExpression *x, FxExpression *y, FxExpression *z, const FScriptPosition &sc) - :FxExpression(EFX_VectorInitializer, sc) +FxVectorValue::FxVectorValue(FxExpression *x, FxExpression *y, FxExpression *z, const FScriptPosition &sc) + :FxExpression(EFX_VectorValue, sc) { xyz[0] = x; xyz[1] = y; @@ -456,13 +456,13 @@ FxVectorInitializer::FxVectorInitializer(FxExpression *x, FxExpression *y, FxExp ValueType = TypeVoid; // we do not know yet } -FxVectorInitializer::~FxVectorInitializer() +FxVectorValue::~FxVectorValue() { for (auto &a : xyz) SAFE_DELETE(a); } -FxExpression *FxVectorInitializer::Resolve(FCompileContext&ctx) +FxExpression *FxVectorValue::Resolve(FCompileContext&ctx) { bool fails = false; @@ -501,10 +501,10 @@ FxExpression *FxVectorInitializer::Resolve(FCompileContext&ctx) return nullptr; } ValueType = TypeVector3; - if (xyz[0]->ExprType == EFX_VectorInitializer) + if (xyz[0]->ExprType == EFX_VectorValue) { // If two vector initializers are nested, unnest them now. - auto vi = static_cast(xyz[0]); + auto vi = static_cast(xyz[0]); xyz[2] = xyz[1]; xyz[1] = vi->xyz[1]; xyz[0] = vi->xyz[0]; @@ -542,7 +542,7 @@ static ExpEmit EmitKonst(VMFunctionBuilder *build, ExpEmit &emit) return emit; } -ExpEmit FxVectorInitializer::Emit(VMFunctionBuilder *build) +ExpEmit FxVectorValue::Emit(VMFunctionBuilder *build) { // no const handling here. Ultimstely it's too rarely used (i.e. the only fully constant vector ever allocated in ZDoom is the 0-vector in a very few places) // and the negatives (excessive allocation of float constants) outweigh the positives (saved a few instructions) diff --git a/src/scripting/codegeneration/codegen.h b/src/scripting/codegeneration/codegen.h index 9e13d3806b..f9393d11f7 100644 --- a/src/scripting/codegeneration/codegen.h +++ b/src/scripting/codegeneration/codegen.h @@ -265,7 +265,7 @@ enum EFxType EFX_LocalVariableDeclaration, EFX_SwitchStatement, EFX_CaseStatement, - EFX_VectorInitializer, + EFX_VectorValue, EFX_VectorBuiltin, EFX_TypeCheck, EFX_COUNT @@ -463,14 +463,14 @@ public: // //========================================================================== -class FxVectorInitializer : public FxExpression +class FxVectorValue : public FxExpression { FxExpression *xyz[3]; bool isConst; // gets set to true if all element are const public: - FxVectorInitializer(FxExpression *x, FxExpression *y, FxExpression *z, const FScriptPosition &sc); - ~FxVectorInitializer(); + FxVectorValue(FxExpression *x, FxExpression *y, FxExpression *z, const FScriptPosition &sc); + ~FxVectorValue(); FxExpression *Resolve(FCompileContext&); ExpEmit Emit(VMFunctionBuilder *build); diff --git a/src/scripting/zscript/ast.cpp b/src/scripting/zscript/ast.cpp index e77c631e18..cb0240dea8 100644 --- a/src/scripting/zscript/ast.cpp +++ b/src/scripting/zscript/ast.cpp @@ -623,7 +623,7 @@ static void PrintExprTrinary(FLispString &out, ZCC_TreeNode *node) static void PrintVectorInitializer(FLispString &out, ZCC_TreeNode *node) { - ZCC_VectorInitializer *enode = (ZCC_VectorInitializer *)node; + ZCC_VectorValue *enode = (ZCC_VectorValue *)node; OpenExprType(out, enode->Operation); PrintNodes(out, enode->X); PrintNodes(out, enode->Y); diff --git a/src/scripting/zscript/zcc-parse.lemon b/src/scripting/zscript/zcc-parse.lemon index 173ec27fc0..b1065281c8 100644 --- a/src/scripting/zscript/zcc-parse.lemon +++ b/src/scripting/zscript/zcc-parse.lemon @@ -945,7 +945,6 @@ func_param_flags(X) ::= func_param_flags(A) OPTIONAL(T). { X.Int = A.Int | ZCC_O %type expr{ZCC_Expression *} %type primary{ZCC_Expression *} -%type vectorinit{ZCC_VectorInitializer*} %type unary_expr{ZCC_Expression *} %type constant{ZCC_ExprConstant *} @@ -967,8 +966,26 @@ primary(X) ::= SUPER(T). X = expr; } primary(X) ::= constant(A). { X = A; /*X-overwrites-A*/ } -primary(X) ::= vectorinit(A). { X = A; /*X-overwrites-A*/ } - +primary(XX) ::= LPAREN expr(A) COMMA expr(B) COMMA expr(C) RPAREN. [DOT] +{ + NEW_AST_NODE(VectorValue, expr, A); + expr->Operation = PEX_Vector; + expr->Type = TypeVector3; + expr->X = A; + expr->Y = B; + expr->Z = C; + XX = expr; +} +primary(XX) ::= LPAREN expr(A) COMMA expr(B) RPAREN. [DOT] +{ + NEW_AST_NODE(VectorValue, expr, A); + expr->Operation = PEX_Vector; + expr->Type = TypeVector2; + expr->X = A; + expr->Y = B; + expr->Z = nullptr; + XX = expr; +} primary(X) ::= LPAREN expr(A) RPAREN. { X = A; /*X-overwrites-A*/ @@ -1019,29 +1036,6 @@ primary(X) ::= SCOPE primary(B). } */ -vectorinit(XX) ::= LPAREN expr(A) COMMA expr(B) COMMA expr(C) RPAREN. [DOT] -{ - NEW_AST_NODE(VectorInitializer, expr, A); - expr->Operation = PEX_Vector; - expr->Type = TypeVector3; - expr->X = A; - expr->Y = B; - expr->Z = C; - XX = expr; -} - - -vectorinit(XX) ::= LPAREN expr(A) COMMA expr(B) RPAREN. [DOT] -{ - NEW_AST_NODE(VectorInitializer, expr, A); - expr->Operation = PEX_Vector; - expr->Type = TypeVector2; - expr->X = A; - expr->Y = B; - expr->Z = nullptr; - XX = expr; -} - /*----- Unary Expressions -----*/ unary_expr(X) ::= primary(X). diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index e545bd5087..38754bdce8 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2712,13 +2712,13 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast) return new FxConditional(condition, left, right); } - case AST_VectorInitializer: + case AST_VectorValue: { - auto vecini = static_cast(ast); + auto vecini = static_cast(ast); auto xx = ConvertNode(vecini->X); auto yy = ConvertNode(vecini->Y); auto zz = ConvertNode(vecini->Z); - return new FxVectorInitializer(xx, yy, zz, *ast); + return new FxVectorValue(xx, yy, zz, *ast); } case AST_LocalVarStmt: diff --git a/src/scripting/zscript/zcc_parser.h b/src/scripting/zscript/zcc_parser.h index 0889d1d378..715fa0be65 100644 --- a/src/scripting/zscript/zcc_parser.h +++ b/src/scripting/zscript/zcc_parser.h @@ -98,7 +98,7 @@ enum EZCCTreeNodeType AST_Default, AST_FlagStmt, AST_PropertyStmt, - AST_VectorInitializer, + AST_VectorValue, NUM_AST_NODE_TYPES }; @@ -385,7 +385,7 @@ struct ZCC_ExprTrinary : ZCC_Expression ZCC_Expression *Right; }; -struct ZCC_VectorInitializer : ZCC_Expression +struct ZCC_VectorValue : ZCC_Expression { ZCC_Expression *X, *Y, *Z; };