Renamed "VectorInitializer" to "VectorValue"

This was really confusing for me as this is an actual vector "value" rather than an "initializer"
This commit is contained in:
Leonard2 2016-10-30 04:35:01 +01:00
parent ac1c022911
commit 94410accf4
6 changed files with 37 additions and 43 deletions

View file

@ -446,8 +446,8 @@ ExpEmit FxConstant::Emit(VMFunctionBuilder *build)
// //
//========================================================================== //==========================================================================
FxVectorInitializer::FxVectorInitializer(FxExpression *x, FxExpression *y, FxExpression *z, const FScriptPosition &sc) FxVectorValue::FxVectorValue(FxExpression *x, FxExpression *y, FxExpression *z, const FScriptPosition &sc)
:FxExpression(EFX_VectorInitializer, sc) :FxExpression(EFX_VectorValue, sc)
{ {
xyz[0] = x; xyz[0] = x;
xyz[1] = y; xyz[1] = y;
@ -456,13 +456,13 @@ FxVectorInitializer::FxVectorInitializer(FxExpression *x, FxExpression *y, FxExp
ValueType = TypeVoid; // we do not know yet ValueType = TypeVoid; // we do not know yet
} }
FxVectorInitializer::~FxVectorInitializer() FxVectorValue::~FxVectorValue()
{ {
for (auto &a : xyz) for (auto &a : xyz)
SAFE_DELETE(a); SAFE_DELETE(a);
} }
FxExpression *FxVectorInitializer::Resolve(FCompileContext&ctx) FxExpression *FxVectorValue::Resolve(FCompileContext&ctx)
{ {
bool fails = false; bool fails = false;
@ -501,10 +501,10 @@ FxExpression *FxVectorInitializer::Resolve(FCompileContext&ctx)
return nullptr; return nullptr;
} }
ValueType = TypeVector3; ValueType = TypeVector3;
if (xyz[0]->ExprType == EFX_VectorInitializer) if (xyz[0]->ExprType == EFX_VectorValue)
{ {
// If two vector initializers are nested, unnest them now. // If two vector initializers are nested, unnest them now.
auto vi = static_cast<FxVectorInitializer*>(xyz[0]); auto vi = static_cast<FxVectorValue*>(xyz[0]);
xyz[2] = xyz[1]; xyz[2] = xyz[1];
xyz[1] = vi->xyz[1]; xyz[1] = vi->xyz[1];
xyz[0] = vi->xyz[0]; xyz[0] = vi->xyz[0];
@ -542,7 +542,7 @@ static ExpEmit EmitKonst(VMFunctionBuilder *build, ExpEmit &emit)
return 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) // 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) // and the negatives (excessive allocation of float constants) outweigh the positives (saved a few instructions)

View file

@ -265,7 +265,7 @@ enum EFxType
EFX_LocalVariableDeclaration, EFX_LocalVariableDeclaration,
EFX_SwitchStatement, EFX_SwitchStatement,
EFX_CaseStatement, EFX_CaseStatement,
EFX_VectorInitializer, EFX_VectorValue,
EFX_VectorBuiltin, EFX_VectorBuiltin,
EFX_TypeCheck, EFX_TypeCheck,
EFX_COUNT EFX_COUNT
@ -463,14 +463,14 @@ public:
// //
//========================================================================== //==========================================================================
class FxVectorInitializer : public FxExpression class FxVectorValue : public FxExpression
{ {
FxExpression *xyz[3]; FxExpression *xyz[3];
bool isConst; // gets set to true if all element are const bool isConst; // gets set to true if all element are const
public: public:
FxVectorInitializer(FxExpression *x, FxExpression *y, FxExpression *z, const FScriptPosition &sc); FxVectorValue(FxExpression *x, FxExpression *y, FxExpression *z, const FScriptPosition &sc);
~FxVectorInitializer(); ~FxVectorValue();
FxExpression *Resolve(FCompileContext&); FxExpression *Resolve(FCompileContext&);
ExpEmit Emit(VMFunctionBuilder *build); ExpEmit Emit(VMFunctionBuilder *build);

View file

@ -623,7 +623,7 @@ static void PrintExprTrinary(FLispString &out, ZCC_TreeNode *node)
static void PrintVectorInitializer(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); OpenExprType(out, enode->Operation);
PrintNodes(out, enode->X); PrintNodes(out, enode->X);
PrintNodes(out, enode->Y); PrintNodes(out, enode->Y);

View file

@ -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 expr{ZCC_Expression *}
%type primary{ZCC_Expression *} %type primary{ZCC_Expression *}
%type vectorinit{ZCC_VectorInitializer*}
%type unary_expr{ZCC_Expression *} %type unary_expr{ZCC_Expression *}
%type constant{ZCC_ExprConstant *} %type constant{ZCC_ExprConstant *}
@ -967,8 +966,26 @@ primary(X) ::= SUPER(T).
X = expr; X = expr;
} }
primary(X) ::= constant(A). { X = A; /*X-overwrites-A*/ } 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. primary(X) ::= LPAREN expr(A) RPAREN.
{ {
X = A; /*X-overwrites-A*/ 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 Expressions -----*/
unary_expr(X) ::= primary(X). unary_expr(X) ::= primary(X).

View file

@ -2712,13 +2712,13 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast)
return new FxConditional(condition, left, right); return new FxConditional(condition, left, right);
} }
case AST_VectorInitializer: case AST_VectorValue:
{ {
auto vecini = static_cast<ZCC_VectorInitializer *>(ast); auto vecini = static_cast<ZCC_VectorValue *>(ast);
auto xx = ConvertNode(vecini->X); auto xx = ConvertNode(vecini->X);
auto yy = ConvertNode(vecini->Y); auto yy = ConvertNode(vecini->Y);
auto zz = ConvertNode(vecini->Z); auto zz = ConvertNode(vecini->Z);
return new FxVectorInitializer(xx, yy, zz, *ast); return new FxVectorValue(xx, yy, zz, *ast);
} }
case AST_LocalVarStmt: case AST_LocalVarStmt:

View file

@ -98,7 +98,7 @@ enum EZCCTreeNodeType
AST_Default, AST_Default,
AST_FlagStmt, AST_FlagStmt,
AST_PropertyStmt, AST_PropertyStmt,
AST_VectorInitializer, AST_VectorValue,
NUM_AST_NODE_TYPES NUM_AST_NODE_TYPES
}; };
@ -385,7 +385,7 @@ struct ZCC_ExprTrinary : ZCC_Expression
ZCC_Expression *Right; ZCC_Expression *Right;
}; };
struct ZCC_VectorInitializer : ZCC_Expression struct ZCC_VectorValue : ZCC_Expression
{ {
ZCC_Expression *X, *Y, *Z; ZCC_Expression *X, *Y, *Z;
}; };