From cb25b8106c04238f26e5c52cae3276599d6556f6 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Wed, 8 Oct 2014 01:55:54 +0200 Subject: [PATCH] Rez: rect and point --- Rez/Expression.cc | 24 ++++++++++++------------ Rez/Expression.h | 1 + Rez/ResourceDefinitions.cc | 38 ++++++++++++++++++++++++++++++++++++++ Rez/ResourceDefinitions.h | 1 + 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/Rez/Expression.cc b/Rez/Expression.cc index 259cde21f3..e8d1b72ced 100644 --- a/Rez/Expression.cc +++ b/Rez/Expression.cc @@ -108,6 +108,16 @@ void IdentifierExpr::addArgument(ExprPtr e) arguments.push_back(e); } +ExprPtr IdentifierExpr::lookup(ResourceCompiler *ctx) +{ + Subscripts sub; + for(auto arg : arguments) + sub.addSubscript(arg->evaluateInt(ctx)); + ExprPtr val = ctx->lookupIdentifier(id, sub); + assert(val); + return val; +} + int IdentifierExpr::evaluateInt(ResourceCompiler *ctx) { if(isFunction) @@ -130,24 +140,14 @@ int IdentifierExpr::evaluateInt(ResourceCompiler *ctx) } else { - Subscripts sub; - for(auto arg : arguments) - sub.addSubscript(arg->evaluateInt(ctx)); - ExprPtr val = ctx->lookupIdentifier(id, sub); - assert(val); - return val->evaluateInt(ctx); + return lookup(ctx)->evaluateInt(ctx); } } std::string IdentifierExpr::evaluateString(ResourceCompiler *ctx) { assert(!isFunction); - Subscripts sub; - for(auto arg : arguments) - sub.addSubscript(arg->evaluateInt(ctx)); - ExprPtr val = ctx->lookupIdentifier(id, sub); - assert(val); - return val->evaluateString(ctx); + return lookup(ctx)->evaluateString(ctx); } diff --git a/Rez/Expression.h b/Rez/Expression.h index acc417e759..be57fc31e8 100644 --- a/Rez/Expression.h +++ b/Rez/Expression.h @@ -110,6 +110,7 @@ public: IdentifierExpr(std::string id, bool isFunction = false); void addArgument(ExprPtr e); + ExprPtr lookup(ResourceCompiler *ctx); virtual int evaluateInt(ResourceCompiler *ctx); virtual std::string evaluateString(ResourceCompiler *ctx); }; diff --git a/Rez/ResourceDefinitions.cc b/Rez/ResourceDefinitions.cc index 65a17fc98c..36078bd934 100644 --- a/Rez/ResourceDefinitions.cc +++ b/Rez/ResourceDefinitions.cc @@ -103,6 +103,12 @@ void SimpleField::compile(ExprPtr expr, ResourceCompiler *compiler, bool prePass case Type::char_: compileString(expr, compiler, prePass); break; + + case Type::rect: + case Type::point: + compileCompound(expr, compiler, prePass); + break; + } } @@ -181,6 +187,38 @@ void SimpleField::compileInt(ExprPtr expr, ResourceCompiler *compiler, bool preP compiler->write(bitSize, actualValue); } +void SimpleField::compileCompound(ExprPtr expr, ResourceCompiler *compiler, bool prePass) +{ + ExprPtr val = value ? value : expr; + if(IdentifierExprPtr id = std::dynamic_pointer_cast(val)) + { + ResourceCompiler::FieldScope scope(compiler, this); + val = id->lookup(compiler); + } + + int count = 0; + switch(type) + { + case Type::rect: + count = 4; + break; + case Type::point: + count = 2; + break; + } + + CompoundExprPtr compound = std::dynamic_pointer_cast(val); + assert(compound); + + assert(compound->size() == count); + + for(int i = 0; i < count; i++) + { + int x = compound->getItem(i)->evaluateInt(compiler); + compiler->write(16, x); + } +} + ArrayField::ArrayField(std::string name, ExprPtr count) : name(name), arrayCount(count) diff --git a/Rez/ResourceDefinitions.h b/Rez/ResourceDefinitions.h index baa2dd059e..d2456e2419 100644 --- a/Rez/ResourceDefinitions.h +++ b/Rez/ResourceDefinitions.h @@ -94,6 +94,7 @@ public: private: void compileString(ExprPtr expr, ResourceCompiler *compiler, bool prePass); void compileInt(ExprPtr expr, ResourceCompiler *compiler, bool prePass); + void compileCompound(ExprPtr expr, ResourceCompiler *compiler, bool prePass); }; typedef std::shared_ptr SimpleFieldPtr;