Skip to content

Commit

Permalink
XX
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 Jul 6, 2024
1 parent 3ca706e commit aee5570
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 6 deletions.
27 changes: 26 additions & 1 deletion src/ElemFactoryAddrClaim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
#include "dmgr/impl/DebugMacros.h"
#include "ElemFactoryAddrClaim.h"
#include "TaskBuildDataType.h"
#include "TaskGetAddrClaimTrait.h"


namespace zsp {
Expand All @@ -35,13 +37,36 @@ ElemFactoryAddrClaim::~ElemFactoryAddrClaim() {

}

vsc::dm::IDataType *ElemFactoryAddrClaim::mkDataType(
IAst2ArlContext *ctx,
const std::string &name,
ast::IScopeChild *type) {
DEBUG_ENTER("mkDataType");
vsc::dm::IDataType *ret = ctx->ctxt()->mkDataTypeAddrClaim(name);
DEBUG_LEAVE("mkDataType");
return ret;
}

vsc::dm::ITypeField *ElemFactoryAddrClaim::mkTypeFieldPhy(
IAst2ArlContext *ctx,
const std::string &name,
ast::IScopeChild *type,
vsc::dm::TypeFieldAttr attr,
const vsc::dm::ValRef &init) {
return 0;
DEBUG_ENTER("mkTypeFieldPhy %s", name.c_str());
vsc::dm::IDataType *type_dt = TaskBuildDataType(ctx).build(type);
ast::IScopeChild *trait_t = TaskGetAddrClaimTrait(
ctx->getDebugMgr(), ctx->getRoot()).get(type);
vsc::dm::IDataType *trait_dt = TaskBuildDataType(ctx).build(trait_t);

vsc::dm::ITypeField *ret = ctx->ctxt()->mkTypeFieldAddrClaim(
name,
type_dt,
false,
dynamic_cast<vsc::dm::IDataTypeStruct *>(trait_dt));

DEBUG_LEAVE("mkTypeFieldPhy %s", name.c_str());
return ret;
}

}
Expand Down
5 changes: 5 additions & 0 deletions src/ElemFactoryAddrClaim.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class ElemFactoryAddrClaim : public virtual ElemFactoryAssocDataBase {

virtual ~ElemFactoryAddrClaim();

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

virtual vsc::dm::ITypeField *mkTypeFieldPhy(
IAst2ArlContext *ctx,
const std::string &name,
Expand Down
31 changes: 29 additions & 2 deletions src/ElemFactoryTransparentAddrClaim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,49 @@
* Created on:
* Author:
*/
#include "dmgr/impl/DebugMacros.h"
#include "ElemFactoryTransparentAddrClaim.h"
#include "TaskBuildDataType.h"
#include "TaskGetAddrClaimTrait.h"


namespace zsp {
namespace fe {
namespace parser {


ElemFactoryTransparentAddrClaim::ElemFactoryTransparentAddrClaim() {

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

ElemFactoryTransparentAddrClaim::~ElemFactoryTransparentAddrClaim() {

}

vsc::dm::ITypeField *ElemFactoryTransparentAddrClaim::mkTypeFieldPhy(
IAst2ArlContext *ctx,
const std::string &name,
ast::IScopeChild *type,
vsc::dm::TypeFieldAttr attr,
const vsc::dm::ValRef &init) {
DEBUG_ENTER("mkTypeFieldPhy %s", name.c_str());
vsc::dm::IDataType *type_dt = TaskBuildDataType(ctx).build(type);
ast::IScopeChild *trait_t = TaskGetAddrClaimTrait(
ctx->getDebugMgr(), ctx->getRoot()).get(type);
vsc::dm::IDataType *trait_dt = TaskBuildDataType(ctx).build(trait_t);

vsc::dm::ITypeField *ret = ctx->ctxt()->mkTypeFieldAddrClaimTransparent(
name,
type_dt,
false,
dynamic_cast<vsc::dm::IDataTypeStruct *>(trait_dt));

DEBUG_LEAVE("mkTypeFieldPhy %s", name.c_str());
return ret;
}

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

}
}
}
21 changes: 19 additions & 2 deletions src/ElemFactoryTransparentAddrClaim.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,36 @@
* Author:
*/
#pragma once
#include "dmgr/IDebugMgr.h"
#include "zsp/fe/parser/impl/ElemFactoryAssocDataBase.h"

namespace zsp {
namespace fe {
namespace parser {



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

virtual ~ElemFactoryTransparentAddrClaim();

virtual vsc::dm::ITypeField *mkTypeFieldPhy(
IAst2ArlContext *ctx,
const std::string &name,
ast::IScopeChild *type,
vsc::dm::TypeFieldAttr attr,
const vsc::dm::ValRef &init) override;

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

private:
static dmgr::IDebug *m_dbg;

};

}
Expand Down
8 changes: 7 additions & 1 deletion src/ElemFactoryTransparentAddrSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "vsc/dm/impl/ValRef.h"
#include "ElemFactoryTransparentAddrSpace.h"
#include "TaskBuildDataType.h"
#include "TaskGetAddrClaimTrait.h"


namespace zsp {
Expand Down Expand Up @@ -63,8 +64,13 @@ vsc::dm::IDataType *ElemFactoryTransparentAddrSpace::mkDataType(
const std::string &name,
ast::IScopeChild *type) {
DEBUG_ENTER("mkDataTtype %s", name.c_str());
ast::IScopeChild *trait_t = TaskGetAddrClaimTrait(
ctx->getDebugMgr(), ctx->getRoot()).get(type);
vsc::dm::IDataType *trait_dt = TaskBuildDataType(ctx).build(trait_t);
arl::dm::IDataTypeAddrSpaceTransparentC *t =
ctx->ctxt()->mkDataTypeAddrSpaceTransparentC(name);
ctx->ctxt()->mkDataTypeAddrSpaceTransparentC(
name,
dynamic_cast<vsc::dm::IDataTypeStruct *>(trait_dt));
DEBUG_LEAVE("mkDataTtype %s", name.c_str());
return t;
}
Expand Down
126 changes: 126 additions & 0 deletions src/TaskGetAddrClaimTrait.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* TaskGetAddrClaimTrait.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/impl/TaskResolveSymbolPathRef.h"

namespace zsp {
namespace fe {
namespace parser {



class TaskGetAddrClaimTrait : public ast::VisitorBase {
public:

TaskGetAddrClaimTrait(
dmgr::IDebugMgr *dmgr,
ast::ISymbolScope *root) : m_dbg(0), m_dmgr(dmgr), m_root(root) {
DEBUG_INIT("zsp::fe::parser::TaskGetAddrClaimTrait", dmgr);
}

virtual ~TaskGetAddrClaimTrait() { }

ast::IScopeChild *get(ast::IScopeChild *claim_t) {
DEBUG_ENTER("get");
m_depth = 0;
m_trait_t = 0;
claim_t->accept(m_this);
DEBUG_LEAVE("get %p", m_trait_t);
return m_trait_t;
}

virtual void visitDataTypeUserDefined(ast::IDataTypeUserDefined *i) override {
DEBUG_ENTER("visitDataTypeUserDefined %s", i->getType_id()->getElems().at(0)->getId()->getId().c_str());
ast::IScopeChild *type_t = zsp::parser::TaskResolveSymbolPathRef(
m_dmgr, m_root).resolve(i->getType_id()->getTarget());
if (m_depth) {
m_trait_t = type_t;
} else {
type_t->accept(m_this);
}
DEBUG_LEAVE("visitDataTypeUserDefined");
}

virtual void visitSymbolTypeScope(ast::ISymbolTypeScope *i) override {
DEBUG_ENTER("visitSymbolTypeScope %s", i->getName().c_str());
i->getTarget()->accept(m_this);
DEBUG_LEAVE("visitSymbolTypeScope %s", i->getName().c_str());
}

virtual void visitTypeScope(ast::ITypeScope *i) override {
DEBUG_ENTER("visitTypeScope %s", i->getName()->getId().c_str());
m_depth++;
if (i->getSuper_t()) {
ast::IScopeChild *super_t = zsp::parser::TaskResolveSymbolPathRef(
m_dmgr, m_root).resolve(i->getSuper_t()->getTarget());
super_t->accept(m_this);
}

if (i->getParams() && !m_trait_t) {
// Root parameterized type. Should be able to grab pval from here
i->getParams()->getParams().at(0)->accept(m_this);
}

m_depth--;
DEBUG_LEAVE("visitTypeScope %s", i->getName()->getId().c_str());
}

virtual void visitTemplateGenericTypeParamDecl(ast::ITemplateGenericTypeParamDecl *i) override {
DEBUG_ENTER("visitTemplateGenericTypeParamDecl");
i->getDflt()->accept(m_this);
DEBUG_LEAVE("visitTemplateGenericTypeParamDecl");
}

virtual void visitTemplateCategoryTypeParamDecl(ast::ITemplateCategoryTypeParamDecl *i) override {
DEBUG_ENTER("visitTemplateCategoryTypeParamDecl");
i->getDflt()->accept(m_this);
DEBUG_LEAVE("visitTemplateCategoryTypeParamDecl");
}

virtual void visitTemplateParamTypeValue(ast::ITemplateParamTypeValue *i) override {
DEBUG_ENTER("visitTemplateParamTypeValue");
i->getValue()->accept(m_this);
DEBUG_LEAVE("visitTemplateParamTypeValue");
}

virtual void visitTemplateParamExprValue(ast::ITemplateParamExprValue *i) override {
DEBUG_ENTER("visitTemplateParamExprValue");
DEBUG_LEAVE("visitTemplateParamExprValue");
}


private:
dmgr::IDebug *m_dbg;
dmgr::IDebugMgr *m_dmgr;
ast::ISymbolScope *m_root;
ast::IScopeChild *m_trait_t;
int32_t m_depth;

};

} /* namespace parser */
} /* namespace fe */
} /* namespace zsp */


2 changes: 2 additions & 0 deletions src/TaskLinkBuiltinTypeElemFactories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "zsp/ast/ISymbolTypeScope.h"
#include "zsp/fe/parser/IElemFactoryAssocData.h"
#include "ElemFactoryAddrClaim.h"
#include "ElemFactoryTransparentAddrClaim.h"
#include "ElemFactoryAddrHandle.h"
#include "ElemFactoryArray.h"
#include "ElemFactoryPackedStruct.h"
Expand All @@ -49,6 +50,7 @@ static struct LinkTabEntry {
{ {"array"}, &ElemFactoryArray::create },
{ {"pyobj"}, &ElemFactoryPyObj::create },
{ {"addr_reg_pkg", "addr_claim_s"}, &ElemFactoryAddrClaim::create },
{ {"addr_reg_pkg", "transparent_addr_claim_s"}, &ElemFactoryTransparentAddrClaim::create },
{ {"addr_reg_pkg", "reg_c"}, &ElemFactoryReg::create },
{ {"addr_reg_pkg", "reg_group_c"}, &ElemFactoryRegGroup::create },
{ {"addr_reg_pkg", "transparent_addr_space_c"}, &ElemFactoryTransparentAddrSpace::create },
Expand Down

0 comments on commit aee5570

Please sign in to comment.