From 28cab5dc11c5a8c96297e422e1ad304f74ebc348 Mon Sep 17 00:00:00 2001 From: Matthew Ballance Date: Mon, 6 Nov 2023 07:36:24 -0800 Subject: [PATCH] Refactor Signed-off-by: Matthew Ballance --- src/TaskCompareTypeRefs.h | 2 +- src/TaskEvalExpr.cpp | 160 ------------------- src/TaskEvalExpr.h | 92 ----------- src/include/zsp/parser/impl/TaskEvalExpr.h | 176 +++++++++++++++++++++ 4 files changed, 177 insertions(+), 253 deletions(-) delete mode 100644 src/TaskEvalExpr.cpp delete mode 100644 src/TaskEvalExpr.h create mode 100644 src/include/zsp/parser/impl/TaskEvalExpr.h diff --git a/src/TaskCompareTypeRefs.h b/src/TaskCompareTypeRefs.h index 1ecfb7e..9e4c475 100644 --- a/src/TaskCompareTypeRefs.h +++ b/src/TaskCompareTypeRefs.h @@ -22,7 +22,7 @@ #include "dmgr/IDebugMgr.h" #include "zsp/ast/impl/VisitorBase.h" #include "zsp/parser/IFactory.h" -#include "TaskEvalExpr.h" +#include "zsp/parser/impl/TaskEvalExpr.h" #include "TaskCompareVal.h" namespace zsp { diff --git a/src/TaskEvalExpr.cpp b/src/TaskEvalExpr.cpp deleted file mode 100644 index d85d209..0000000 --- a/src/TaskEvalExpr.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * TaskEvalExpr.cpp - * - * Copyright 2023 Matthew Ballance and Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Created on: - * Author: - */ -#include "dmgr/impl/DebugMacros.h" -#include "TaskEvalExpr.h" - - -namespace zsp { -namespace parser { - - -TaskEvalExpr::TaskEvalExpr(IFactory *factory) : m_factory(factory) { - DEBUG_INIT("zsp::parser::TaskEvalExpr", factory->getDebugMgr()); -} - -TaskEvalExpr::~TaskEvalExpr() { - -} - -IVal *TaskEvalExpr::eval(ast::IExpr *expr) { - m_val.reset(); - expr->accept(m_this); - return m_val.release(); -} - -void TaskEvalExpr::visitExprAggregateLiteral(ast::IExprAggregateLiteral *i) { - DEBUG_ENTER("visitExprAggregateLiteral"); - DEBUG("TODO: visitExprAggregateLiteral"); - DEBUG_LEAVE("visitExprAggregateLiteral"); -} - -void TaskEvalExpr::visitExprBin(ast::IExprBin *i) { - DEBUG_ENTER("visitExprBin"); - DEBUG("TODO: visitExprBin"); - DEBUG_LEAVE("visitExprBin"); -} - -void TaskEvalExpr::visitExprBitSlice(ast::IExprBitSlice *i) { - DEBUG_ENTER("visitExprBitSlice"); - DEBUG("TODO: visitExprBitSlice"); - DEBUG_LEAVE("visitExprBitSlice"); -} - -void TaskEvalExpr::visitExprBool(ast::IExprBool *i) { - DEBUG_ENTER("visitExprBool"); - DEBUG("TODO: visitExprBool"); - DEBUG_LEAVE("visitExprBool"); -} - -void TaskEvalExpr::visitExprCast(ast::IExprCast *i) { - DEBUG_ENTER("visitExprCast"); - DEBUG("TODO: visitExprCast"); - DEBUG_LEAVE("visitExprCast"); -} - -void TaskEvalExpr::visitExprCompileHas(ast::IExprCompileHas *i) { - DEBUG_ENTER("visitExprCompileHas"); - DEBUG("TODO: visitExprCompileHas"); - DEBUG_LEAVE("visitExprCompileHas"); -} - -void TaskEvalExpr::visitExprCond(ast::IExprCond *i) { - DEBUG_ENTER("visitExprCond"); - DEBUG("TODO: visitExprCond"); - DEBUG_LEAVE("visitExprCond"); -} - -void TaskEvalExpr::visitExprDomainOpenRangeList(ast::IExprDomainOpenRangeList *i) { - DEBUG_ENTER("visitExprDomainOpenRangeList"); - DEBUG("TODO: visitExprDomainOpenRangeList"); - DEBUG_LEAVE("visitExprDomainOpenRangeList"); -} - -void TaskEvalExpr::visitExprDomainOpenRangeValue(ast::IExprDomainOpenRangeValue *i) { - DEBUG_ENTER("visitExprDomainOpenRangeValue"); - DEBUG("TODO: visitExprDomainOpenRangeValue"); - DEBUG_LEAVE("visitExprDomainOpenRangeValue"); -} - -void TaskEvalExpr::visitExprId(ast::IExprId *i) { - DEBUG_ENTER("visitExprId"); - DEBUG("TODO: visitExprId"); - DEBUG_LEAVE("visitExprId"); -} - -void TaskEvalExpr::visitExprIn(ast::IExprIn *i) { - DEBUG_ENTER("visitExprIn"); - DEBUG("TODO: visitExprIn"); - DEBUG_LEAVE("visitExprIn"); -} - -void TaskEvalExpr::visitExprOpenRangeList(ast::IExprOpenRangeList *i) { - DEBUG_ENTER("visitExprOpenRangeList"); - DEBUG("TODO: visitExprOpenRangeList"); - DEBUG_LEAVE("visitExprOpenRangeList"); -} - -void TaskEvalExpr::visitExprOpenRangeValue(ast::IExprOpenRangeValue *i) { - DEBUG_ENTER("visitExprOpenRangeValue"); - DEBUG("TODO: visitExprOpenRangeValue"); - DEBUG_LEAVE("visitExprOpenRangeValue"); -} - -void TaskEvalExpr::visitExprNull(ast::IExprNull *i) { - DEBUG_ENTER("visitExprNull"); - DEBUG("TODO: visitExprNull"); - DEBUG_LEAVE("visitExprNull"); -} - -void TaskEvalExpr::visitExprSignedNumber(ast::IExprSignedNumber *i) { - DEBUG_ENTER("visitExprSignedNumber"); - m_val = IValUP(m_factory->mkValInt(true, i->getWidth(), i->getValue())); - DEBUG_LEAVE("visitExprSignedNumber"); -} - -void TaskEvalExpr::visitExprString(ast::IExprString *i) { - DEBUG_ENTER("visitExprString"); - DEBUG("TODO: visitExprString"); - DEBUG_LEAVE("visitExprString"); -} - -void TaskEvalExpr::visitExprSubscript(ast::IExprSubscript *i) { - DEBUG_ENTER("visitExprSubscript"); - DEBUG("TODO: visitExprSubscript"); - DEBUG_LEAVE("visitExprSubscript"); -} - -void TaskEvalExpr::visitExprUnary(ast::IExprUnary *i) { - DEBUG_ENTER("visitExprUnary"); - DEBUG("TODO: visitExprUnary"); - DEBUG_LEAVE("visitExprUnary"); -} - -void TaskEvalExpr::visitExprUnsignedNumber(ast::IExprUnsignedNumber *i) { - DEBUG_ENTER("visitExprUnsignedNumber"); - m_val = IValUP(m_factory->mkValInt(false, i->getWidth(), i->getValue())); - DEBUG_LEAVE("visitExprUnsignedNumber"); -} - -dmgr::IDebug *TaskEvalExpr::m_dbg = 0; - -} -} diff --git a/src/TaskEvalExpr.h b/src/TaskEvalExpr.h deleted file mode 100644 index b0a4cf0..0000000 --- a/src/TaskEvalExpr.h +++ /dev/null @@ -1,92 +0,0 @@ -/** - * TaskEvalExpr.h - * - * Copyright 2023 Matthew Ballance and Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Created on: - * Author: - */ -#pragma once -#include "dmgr/IDebugMgr.h" -#include "zsp/ast/impl/VisitorBase.h" -#include "zsp/parser/IFactory.h" -#include "zsp/parser/IVal.h" - -namespace zsp { -namespace parser { - - - -class TaskEvalExpr : public virtual ast::VisitorBase { -public: - TaskEvalExpr(IFactory *factory); - - virtual ~TaskEvalExpr(); - - IVal *eval(ast::IExpr *expr); - - template T *evalT(ast::IExpr *expr) { - return dynamic_cast(eval(expr)); - } - - virtual void visitExprAggregateLiteral(ast::IExprAggregateLiteral *i) override; - - virtual void visitExprBin(ast::IExprBin *i) override; - - virtual void visitExprBitSlice(ast::IExprBitSlice *i) override; - - virtual void visitExprBool(ast::IExprBool *i) override; - - virtual void visitExprCast(ast::IExprCast *i) override; - - virtual void visitExprCompileHas(ast::IExprCompileHas *i) override; - - virtual void visitExprCond(ast::IExprCond *i) override; - - virtual void visitExprDomainOpenRangeList(ast::IExprDomainOpenRangeList *i) override; - - virtual void visitExprDomainOpenRangeValue(ast::IExprDomainOpenRangeValue *i) override; - - virtual void visitExprId(ast::IExprId *i) override; - - virtual void visitExprIn(ast::IExprIn *i) override; - - virtual void visitExprOpenRangeList(ast::IExprOpenRangeList *i) override; - - virtual void visitExprOpenRangeValue(ast::IExprOpenRangeValue *i) override; - - virtual void visitExprNull(ast::IExprNull *i) override; - - virtual void visitExprSignedNumber(ast::IExprSignedNumber *i) override; - - virtual void visitExprString(ast::IExprString *i) override; - - virtual void visitExprSubscript(ast::IExprSubscript *i) override; - - virtual void visitExprUnary(ast::IExprUnary *i) override; - - virtual void visitExprUnsignedNumber(ast::IExprUnsignedNumber *i) override; - -private: - static dmgr::IDebug *m_dbg; - IFactory *m_factory; - IValUP m_val; - -}; - -} -} - - diff --git a/src/include/zsp/parser/impl/TaskEvalExpr.h b/src/include/zsp/parser/impl/TaskEvalExpr.h new file mode 100644 index 0000000..de5ddf4 --- /dev/null +++ b/src/include/zsp/parser/impl/TaskEvalExpr.h @@ -0,0 +1,176 @@ +/** + * TaskEvalExpr.h + * + * Copyright 2023 Matthew Ballance and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Created on: + * Author: + */ +#pragma once +#include "dmgr/IDebugMgr.h" +#include "dmgr/impl/DebugMacros.h" +#include "zsp/ast/impl/VisitorBase.h" +#include "zsp/parser/IFactory.h" +#include "zsp/parser/IVal.h" + +namespace zsp { +namespace parser { + + + +class TaskEvalExpr : public virtual ast::VisitorBase { +public: + TaskEvalExpr(IFactory *factory) : + m_dbg(0), m_factory(factory) { + DEBUG_INIT("zsp::parser::TaskEvalExpr", factory->getDebugMgr()); + } + + virtual ~TaskEvalExpr() {} + + IVal *eval(ast::IExpr *expr) { + m_val.reset(); + expr->accept(m_this); + return m_val.release(); + } + + template T *evalT(ast::IExpr *expr) { + return dynamic_cast(eval(expr)); + } + + virtual void visitExprAggregateLiteral(ast::IExprAggregateLiteral *i) override { + DEBUG_ENTER("visitExprAggregateLiteral"); + DEBUG("TODO: visitExprAggregateLiteral"); + DEBUG_LEAVE("visitExprAggregateLiteral"); + } + + virtual void visitExprBin(ast::IExprBin *i) override { + DEBUG_ENTER("visitExprBin"); + DEBUG("TODO: visitExprBin"); + DEBUG_LEAVE("visitExprBin"); + } + + virtual void visitExprBitSlice(ast::IExprBitSlice *i) override { + DEBUG_ENTER("visitExprBitSlice"); + DEBUG("TODO: visitExprBitSlice"); + DEBUG_LEAVE("visitExprBitSlice"); + } + + virtual void visitExprBool(ast::IExprBool *i) override { + DEBUG_ENTER("visitExprBool"); + DEBUG("TODO: visitExprBool"); + DEBUG_LEAVE("visitExprBool"); + } + + virtual void visitExprCast(ast::IExprCast *i) override { + DEBUG_ENTER("visitExprCast"); + DEBUG("TODO: visitExprCast"); + DEBUG_LEAVE("visitExprCast"); + } + + virtual void visitExprCompileHas(ast::IExprCompileHas *i) override { + DEBUG_ENTER("visitExprCompileHas"); + DEBUG("TODO: visitExprCompileHas"); + DEBUG_LEAVE("visitExprCompileHas"); + } + + virtual void visitExprCond(ast::IExprCond *i) override { + DEBUG_ENTER("visitExprCond"); + DEBUG("TODO: visitExprCond"); + DEBUG_LEAVE("visitExprCond"); + } + + virtual void visitExprDomainOpenRangeList(ast::IExprDomainOpenRangeList *i) override { + DEBUG_ENTER("visitExprDomainOpenRangeList"); + DEBUG("TODO: visitExprDomainOpenRangeList"); + DEBUG_LEAVE("visitExprDomainOpenRangeList"); + } + + virtual void visitExprDomainOpenRangeValue(ast::IExprDomainOpenRangeValue *i) override { + DEBUG_ENTER("visitExprDomainOpenRangeValue"); + DEBUG("TODO: visitExprDomainOpenRangeValue"); + DEBUG_LEAVE("visitExprDomainOpenRangeValue"); + } + + virtual void visitExprId(ast::IExprId *i) override { + DEBUG_ENTER("visitExprId"); + DEBUG("TODO: visitExprId"); + DEBUG_LEAVE("visitExprId"); + } + + virtual void visitExprIn(ast::IExprIn *i) override { + DEBUG_ENTER("visitExprIn"); + DEBUG("TODO: visitExprIn"); + DEBUG_LEAVE("visitExprIn"); + } + + virtual void visitExprOpenRangeList(ast::IExprOpenRangeList *i) override { + DEBUG_ENTER("visitExprOpenRangeList"); + DEBUG("TODO: visitExprOpenRangeList"); + DEBUG_LEAVE("visitExprOpenRangeList"); + } + + virtual void visitExprOpenRangeValue(ast::IExprOpenRangeValue *i) override { + DEBUG_ENTER("visitExprOpenRangeValue"); + DEBUG("TODO: visitExprOpenRangeValue"); + DEBUG_LEAVE("visitExprOpenRangeValue"); + } + + virtual void visitExprNull(ast::IExprNull *i) override { + DEBUG_ENTER("visitExprNull"); + DEBUG("TODO: visitExprNull"); + DEBUG_LEAVE("visitExprNull"); + } + + virtual void visitExprSignedNumber(ast::IExprSignedNumber *i) override { + DEBUG_ENTER("visitExprSignedNumber"); + m_val = IValUP(m_factory->mkValInt(true, i->getWidth(), i->getValue())); + DEBUG_LEAVE("visitExprSignedNumber"); + } + + virtual void visitExprString(ast::IExprString *i) override { + DEBUG_ENTER("visitExprString"); + DEBUG("TODO: visitExprString"); + DEBUG_LEAVE("visitExprString"); + } + + virtual void visitExprSubscript(ast::IExprSubscript *i) override { + DEBUG_ENTER("visitExprSubscript"); + DEBUG("TODO: visitExprSubscript"); + DEBUG_LEAVE("visitExprSubscript"); + } + + virtual void visitExprUnary(ast::IExprUnary *i) override { + DEBUG_ENTER("visitExprUnary"); + DEBUG("TODO: visitExprUnary"); + DEBUG_LEAVE("visitExprUnary"); + } + + virtual void visitExprUnsignedNumber(ast::IExprUnsignedNumber *i) override { + DEBUG_ENTER("visitExprUnsignedNumber"); + m_val = IValUP(m_factory->mkValInt(false, i->getWidth(), i->getValue())); + DEBUG_LEAVE("visitExprUnsignedNumber"); + } + +private: + dmgr::IDebug *m_dbg; + IFactory *m_factory; + IValUP m_val; + +}; + +} +} + +