Skip to content

Commit

Permalink
Progress on translating inline constraints
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 Sep 2, 2024
1 parent 1ab386c commit 5c9ab9c
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 84 deletions.
13 changes: 13 additions & 0 deletions src/Ast2ArlContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ class Ast2ArlContext : public virtual IAst2ArlContext {

virtual int32_t findBottomUpScope(ast::ISymbolScope *scope) override;

virtual ast::ISymbolScope *inlineCtxt() const override {
return (m_inline_ctxt_s.size())?m_inline_ctxt_s.back():0;
}

virtual void pushInlineCtxt(ast::ISymbolScope *s) override {
m_inline_ctxt_s.push_back(s);
}

virtual void popInlineCtxt() override {
m_inline_ctxt_s.pop_back();
}

virtual ast::ISymbolScope *typeScope() const override;

virtual vsc::dm::IDataType *findType(ast::IScopeChild *t) override;
Expand Down Expand Up @@ -124,6 +136,7 @@ class Ast2ArlContext : public virtual IAst2ArlContext {
std::vector<std::vector<ast::ISymbolChildrenScope *>> m_scope_s;
std::map<ast::IScopeChild *, vsc::dm::IDataType *> m_type_m;
std::vector<int32_t> m_type_s_idx_s;
std::vector<ast::ISymbolScope *> m_inline_ctxt_s;
std::vector<bool> m_pyref_s;
std::vector<vsc::dm::ITypeExpr *> m_base_s;

Expand Down
13 changes: 13 additions & 0 deletions src/TaskBuildActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "dmgr/impl/DebugMacros.h"
#include "TaskBuildActivity.h"
#include "TaskBuildExpr.h"
#include "TaskBuildConstraint.h"
#include "zsp/arl/dm/IDataTypeActivityTraverseType.h"
#include "zsp/ast/IActivityDecl.h"
#include "zsp/parser/impl/TaskResolveSymbolPathRef.h"
Expand Down Expand Up @@ -88,6 +89,12 @@ void TaskBuildActivity::visitActivityActionHandleTraversal(ast::IActivityActionH
vsc::dm::ITypeConstraint *with_c = 0;
DEBUG(" ref=%p with_c=%p", ref, with_c);

if (i->getWith_c()) {
m_ctxt->pushInlineCtxt(0); // TODO: get type of inline context
with_c = TaskBuildConstraint(m_ctxt).build(i->getWith_c());
m_ctxt->popInlineCtxt();
}

arl::dm::IDataTypeActivityTraverse *t =
m_ctxt->ctxt()->mkDataTypeActivityTraverse(ref, with_c);
m_scope_s.back()->addActivity(m_ctxt->ctxt()->mkTypeFieldActivity(
Expand All @@ -114,6 +121,12 @@ void TaskBuildActivity::visitActivityActionTypeTraversal(ast::IActivityActionTyp
}
vsc::dm::IDataTypeStruct *dt = dynamic_cast<vsc::dm::IDataTypeStruct *>(m_ctxt->getType(t));

if (i->getWith_c()) {
m_ctxt->pushInlineCtxt(ts);
with_c = TaskBuildConstraint(m_ctxt).build(i->getWith_c());
m_ctxt->popInlineCtxt();
}

if (dt) {
arl::dm::IDataTypeAction *at = dynamic_cast<arl::dm::IDataTypeAction *>(dt);
if (!at) {
Expand Down
133 changes: 133 additions & 0 deletions src/TaskBuildConstraint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* TaskBuildConstraint.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 "TaskBuildConstraint.h"
#include "TaskBuildExpr.h"


namespace zsp {
namespace fe {
namespace parser {


TaskBuildConstraint::TaskBuildConstraint(IAst2ArlContext *ctxt) : m_ctxt(ctxt) {
DEBUG_INIT("zsp::fe::parser::TaskBuildConstraint", ctxt->getDebugMgr());
}

TaskBuildConstraint::~TaskBuildConstraint() {

}

vsc::dm::ITypeConstraint *TaskBuildConstraint::build(ast::IConstraintStmt *c) {
m_ret = 0;
c->accept(m_this);
return m_ret;
}

void TaskBuildConstraint::visitConstraintBlock(ast::IConstraintBlock *i) {
DEBUG_ENTER("visitConstraintBlock");
DEBUG_LEAVE("visitConstraintBlock");
}

void TaskBuildConstraint::visitConstraintScope(ast::IConstraintScope *i) {
DEBUG_ENTER("visitConstraintScope");
vsc::dm::ITypeConstraintScope *scope = m_ctxt->ctxt()->mkTypeConstraintScope();
for (std::vector<ast::IConstraintStmtUP>::const_iterator
it=i->getConstraints().begin();
it!=i->getConstraints().end(); it++) {
m_ret = 0;
(*it)->accept(m_this);
if (m_ret) {
scope->addConstraint(m_ret);
}
}
m_ret = scope;
DEBUG_LEAVE("visitConstraintScope");
}

void TaskBuildConstraint::visitConstraintStmtDefault(ast::IConstraintStmtDefault *i) { }

void TaskBuildConstraint::visitConstraintStmtDefaultDisable(ast::IConstraintStmtDefaultDisable *i) { }

void TaskBuildConstraint::visitConstraintStmtExpr(ast::IConstraintStmtExpr *i) {
DEBUG_ENTER("visitConstraintStmtExpr");
vsc::dm::ITypeExpr *expr = TaskBuildExpr(m_ctxt).build(i->getExpr());
vsc::dm::ITypeConstraintExpr *expr_c = m_ctxt->ctxt()->mkTypeConstraintExpr(expr, true);
m_ret = expr_c;
DEBUG_LEAVE("visitConstraintStmtExpr");
}

void TaskBuildConstraint::visitConstraintStmtField(ast::IConstraintStmtField *i) { }

void TaskBuildConstraint::visitConstraintStmtIf(ast::IConstraintStmtIf *i) {
vsc::dm::ITypeExpr *cond = TaskBuildExpr(m_ctxt).build(i->getCond());
m_ret = 0;
i->getTrue_c()->accept(m_this);
vsc::dm::ITypeConstraint *true_c = m_ret;
vsc::dm::ITypeConstraint *false_c = 0;

if (i->getFalse_c()) {
m_ret = 0;
i->getFalse_c()->accept(m_this);
false_c = m_ret;
}

vsc::dm::ITypeConstraintIfElse *c = m_ctxt->ctxt()->mkTypeConstraintIfElse(
cond,
true_c,
false_c);
m_ret = c;
}

void TaskBuildConstraint::visitConstraintStmtImplication(ast::IConstraintStmtImplication *i) {
m_ret = 0;
if (i->getConstraints().size() > 1) {
vsc::dm::ITypeConstraintScope *cs = m_ctxt->ctxt()->mkTypeConstraintScope();
for (std::vector<ast::IConstraintStmtUP>::const_iterator
it=i->getConstraints().begin();
it!=i->getConstraints().end(); it++) {
(*it)->accept(m_this);
if (m_ret) {
cs->addConstraint(m_ret);
}
}
m_ret = cs;
} else {
i->getConstraints().at(0)->accept(m_this);
}

vsc::dm::ITypeConstraintImplies *imp = m_ctxt->ctxt()->mkTypeConstraintImplies(
TaskBuildExpr(m_ctxt).build(i->getCond()),
m_ret);
m_ret = imp;
}

void TaskBuildConstraint::visitConstraintStmtForeach(ast::IConstraintStmtForeach *i) { }

void TaskBuildConstraint::visitConstraintStmtForall(ast::IConstraintStmtForall *i) { }

void TaskBuildConstraint::visitConstraintStmtUnique(ast::IConstraintStmtUnique *i) { }

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

}
}
}
79 changes: 79 additions & 0 deletions src/TaskBuildConstraint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* TaskBuildConstraint.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 <map>
#include <string>
#include "dmgr/IDebug.h"
#include "vsc/dm/IDataTypeStruct.h"
#include "zsp/fe/parser/IAst2ArlContext.h"
#include "zsp/ast/IConstraintScope.h"
#include "zsp/ast/impl/VisitorBase.h"

namespace zsp {
namespace fe {
namespace parser {



class TaskBuildConstraint :
public virtual ast::VisitorBase {
public:
TaskBuildConstraint(IAst2ArlContext *ctxt);

virtual ~TaskBuildConstraint();

vsc::dm::ITypeConstraint *build(ast::IConstraintStmt *c);

virtual void visitConstraintBlock(ast::IConstraintBlock *i) override;

virtual void visitConstraintScope(ast::IConstraintScope *i) override;

virtual void visitConstraintStmtDefault(ast::IConstraintStmtDefault *i) override;

virtual void visitConstraintStmtDefaultDisable(ast::IConstraintStmtDefaultDisable *i) override;

virtual void visitConstraintStmtExpr(ast::IConstraintStmtExpr *i) override;

virtual void visitConstraintStmtField(ast::IConstraintStmtField *i) override;

virtual void visitConstraintStmtIf(ast::IConstraintStmtIf *i) override;

virtual void visitConstraintStmtImplication(ast::IConstraintStmtImplication *i) override;

virtual void visitConstraintStmtForeach(ast::IConstraintStmtForeach *i) override;

virtual void visitConstraintStmtForall(ast::IConstraintStmtForall *i) override;

virtual void visitConstraintStmtUnique(ast::IConstraintStmtUnique *i) override;

private:
static dmgr::IDebug *m_dbg;
IAst2ArlContext *m_ctxt;
vsc::dm::ITypeConstraint *m_ret;
std::vector<vsc::dm::ITypeConstraintScope *> m_scope_s;

};

}
}
}


1 change: 0 additions & 1 deletion src/TaskBuildDataType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ void TaskBuildDataType::visitDataTypeString(ast::IDataTypeString *i) {

void TaskBuildDataType::visitDataTypeUserDefined(ast::IDataTypeUserDefined *i) {
DEBUG_ENTER("visitDataTypeUserDefined");
i->getType_id()->getElems().size();
for (std::vector<ast::ITypeIdentifierElemUP>::const_iterator
it=i->getType_id()->getElems().begin();
it!=i->getType_id()->getElems().end(); it++) {
Expand Down
Loading

0 comments on commit 5c9ab9c

Please sign in to comment.