Skip to content

Commit

Permalink
beginning of array support
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Feb 16, 2024
1 parent 9690a40 commit 6347fbe
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/ElemFactoryArray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* ElemFactoryArray.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 "zsp/parser/impl/TaskEvalExpr.h"
#include "ElemFactoryPyObj.h"
#include "ElemFactoryArray.h"
#include "TaskBuildDataType.h"


namespace zsp {
namespace fe {
namespace parser {


ElemFactoryArray::ElemFactoryArray(dmgr::IDebugMgr *dmgr) {
DEBUG_INIT("zsp::fe::parser::ElemFactoryArray", dmgr);
}

ElemFactoryArray::~ElemFactoryArray() {

}

vsc::dm::IDataType *ElemFactoryArray::mkDataType(
IAst2ArlContext *ctx,
const std::string &name,
ast::IScopeChild *type) {
DEBUG_ENTER("mkDataType");
ast::ITypeScope *ts = dynamic_cast<ast::ITypeScope *>(type);
const std::vector<ast::ITemplateParamDeclUP> &params = ts->getParams()->getParams();
ast::ITemplateGenericTypeParamDecl *Tp =
dynamic_cast<ast::ITemplateGenericTypeParamDecl *>(params.at(0).get());
ast::ITemplateValueParamDecl *SZp =
dynamic_cast<ast::ITemplateValueParamDecl *>(params.at(1).get());

// TODO:
vsc::dm::IDataType *elem_t = TaskBuildDataType(ctx).build(Tp->getDflt());


zsp::parser::IVal *size_v = zsp::parser::TaskEvalExpr(
ctx->factory(),
ctx->getRoot()).eval(SZp->getDflt());

vsc::dm::IDataTypeArray *ret = 0;
if (size_v) {
if (size_v->getKind() == zsp::parser::ValKind::Int) {
ret = ctx->ctxt()->findDataTypeArray(
elem_t,
dynamic_cast<zsp::parser::IValInt *>(size_v)->getValU(),
true);
} else {
ERROR("data-type width expression is %d, not int", size_v->getKind());
}
} else {
ERROR("data-type width expression produced null result");
}

DEBUG_LEAVE("mkDataType %p", ret);
return ret;
}

dmgr::IDebug *ElemFactoryArray::m_dbg = 0;


}
}
}
54 changes: 54 additions & 0 deletions src/ElemFactoryArray.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* ElemFactoryArray.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/fe/parser/impl/ElemFactoryAssocDataBase.h"

namespace zsp {
namespace fe {
namespace parser {


class ElemFactoryArray : public virtual ElemFactoryAssocDataBase {
public:
ElemFactoryArray(dmgr::IDebugMgr *dmgr);

virtual ~ElemFactoryArray();

virtual vsc::dm::IDataType *mkDataType(
IAst2ArlContext *ctx,
const std::string &name,
ast::IScopeChild *type) override;

static ElemFactoryArray *create(dmgr::IDebugMgr *dmgr) {
return new ElemFactoryArray(dmgr);
}

private:
static dmgr::IDebug *m_dbg;

};


}
}
}

0 comments on commit 6347fbe

Please sign in to comment.