From f0ad605119c591da75f333d69460fc125fc8ccaa Mon Sep 17 00:00:00 2001 From: "Samuel D. Crow" Date: Wed, 24 Mar 2021 10:17:01 -0500 Subject: [PATCH] more array support --- yab2cpp.h | 5 ++++- yabDataStructures.cpp | 50 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/yab2cpp.h b/yab2cpp.h index d26493e..476d162 100644 --- a/yab2cpp.h +++ b/yab2cpp.h @@ -376,9 +376,12 @@ class arrayType:public variable list dimensions; public: string generateBox(enum SCOPES s); - virtual string boxName(listindexes); + virtual string boxName(list >indexes); virtual string boxName(){error(E_UNDIMENSIONED_ARRAY);} + void assignment(list >indexes, + shared_ptrvalue); + explicit arrayType(string &name, enum TYPES t, listdim); /*:variable(scope, name, t);*/ virtual ~arrayType() diff --git a/yabDataStructures.cpp b/yabDataStructures.cpp index bbd2cc2..71b83fb 100644 --- a/yabDataStructures.cpp +++ b/yabDataStructures.cpp @@ -398,7 +398,7 @@ void variable::assignment(shared_ptrvalue) } } -string arrayType::boxName(listindexes) +string arrayType::boxName(list >indexes) { ostringstream out; string buf; @@ -406,7 +406,8 @@ string arrayType::boxName(listindexes) out << 'v' << this->getID(); while (i!=indexes.end()) { - out << '[' << *i << ']'; + out << '[' << (*i)->boxName() << ']'; + ++i; } out.str(buf); out.clear(); @@ -431,7 +432,12 @@ string arrayType::generateBox(enum SCOPES s) default: error(E_INTERNAL); } - out << boxName(this->dimensions) << ";\n"; + out << 'v' << this->getID(); + for (auto i=dimensions.begin();i!=dimensions.end();++i) + { + out << '[' << *i << ']'; + } + out << ";\n"; out.str(buf); out.clear(); return buf; @@ -441,4 +447,40 @@ arrayType::arrayType(string &name, enum TYPES t, listdim): variable(S_GLOBAL, name, t) { this->dimensions=dim; -} \ No newline at end of file +} + +void arrayType::assignment(list >indexes, + shared_ptrvalue) +{ + list>x; + shared_ptrop=value->evaluate(); + enum TYPES t=op->getSimpleVarType(); + auto i=indexes.begin(); + while(i!=indexes.end()) + { + x.push_back((*i)->evaluate()); + ++i; + } + switch (this->getType()) + { + case T_FLOATCALL_ARRAY: + if (t==T_INTVAR) + { + output_cpp << this->boxName(x) + << "=static_cast(" + << op->boxName() << ");\n"; + return; + } + if (t!=T_FLOATVAR) error(E_TYPE_MISMATCH); + break; + case T_INTCALL_ARRAY: + if (t!=T_INTVAR) error(E_TYPE_MISMATCH); + break; + case T_STRINGCALL_ARRAY: + if (t!=T_STRINGVAR) error(E_TYPE_MISMATCH); + break; + default: + error(E_INTERNAL); + } + output_cpp << this->boxName(x) << '=' << op->boxName() <<";\n"; +}