diff --git a/python/vsc_dm/pkginfo.py b/python/vsc_dm/pkginfo.py new file mode 100644 index 0000000..032a7cd --- /dev/null +++ b/python/vsc_dm/pkginfo.py @@ -0,0 +1,20 @@ +import os +import ivpm + +class PkgInfo(ivpm.PkgInfo): + + def __init__(self): + pkgdir = os.path.dirname(os.path.abspath(__file__)) + projdir = os.path.dirname(os.path.dirname(pkgdir)) + super().__init__("vsc-dm", os.path.dirname(pkgdir)) + + if os.path.isdir(os.path.join(projdir, "src")): + self._incdirs = [os.path.join(projdir, "src", "include")] + self._libdirs = [ + os.path.join(projdir, "build", "lib"), + os.path.join(projdir, "build", "lib64")] + else: + self._incdirs = [os.path.join(pkgdir, "share", "include")] + self._libdirs = [os.path.join(pkgdir)] + + self._libs = ["vsc-dm"] diff --git a/src/Context.cpp b/src/Context.cpp index 1281b16..b456cf8 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -82,6 +82,7 @@ #include "TypeExprRangelist.h" #include "TypeExprRef.h" #include "TypeExprRefBottomUp.h" +#include "TypeExprRefPath.h" #include "TypeExprRefTopDown.h" #include "TypeExprSubField.h" #include "TypeExprVal.h" @@ -767,6 +768,13 @@ ITypeExprRefBottomUp *Context::mkTypeExprRefBottomUp( return new TypeExprRefBottomUp(scope_offset, field_index); } +ITypeExprRefPath *Context::mkTypeExprRefPath( + ITypeExpr *root, + bool owned, + const std::vector &path) { + return new TypeExprRefPath(root, owned, path); +} + ITypeExprRefTopDown *Context::mkTypeExprRefTopDown() { return new TypeExprRefTopDown(); } diff --git a/src/Context.h b/src/Context.h index e9578dd..9cdfbd0 100644 --- a/src/Context.h +++ b/src/Context.h @@ -328,6 +328,11 @@ class Context : public IContext { int32_t scope_offset, int32_t field_index) override; + virtual ITypeExprRefPath *mkTypeExprRefPath( + ITypeExpr *root, + bool owned, + const std::vector &path) override; + virtual ITypeExprRefTopDown *mkTypeExprRefTopDown() override; virtual ITypeExprSubField *mkTypeExprSubField( diff --git a/src/TypeExprRefPath.cpp b/src/TypeExprRefPath.cpp new file mode 100644 index 0000000..653989d --- /dev/null +++ b/src/TypeExprRefPath.cpp @@ -0,0 +1,41 @@ +/* + * TypeExprRefPath.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 "TypeExprRefPath.h" + + +namespace vsc { +namespace dm { + + +TypeExprRefPath::TypeExprRefPath( + ITypeExpr *root, + bool owned, + const std::vector &path) : TypeExprRef(root, owned), + m_path(path.begin(), path.end()) { + +} + +TypeExprRefPath::~TypeExprRefPath() { + +} + +} +} diff --git a/src/TypeExprRefPath.h b/src/TypeExprRefPath.h new file mode 100644 index 0000000..63a6046 --- /dev/null +++ b/src/TypeExprRefPath.h @@ -0,0 +1,56 @@ +/** + * TypeExprRefPath.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 "vsc/dm/ITypeExprRefPath.h" +#include "TypeExprRef.h" + +namespace vsc { +namespace dm { + + + +class TypeExprRefPath : + public virtual ITypeExprRefPath, + public virtual TypeExprRef { +public: + TypeExprRefPath( + ITypeExpr *root, + bool owned, + const std::vector &path); + + virtual ~TypeExprRefPath(); + + virtual const std::vector &getPath() const override { + return m_path; + } + + virtual void accept(IVisitor *v) override { + v->visitTypeExprRefPath(this); + } + +private: + std::vector m_path; +}; + +} +} + + diff --git a/src/include/vsc/dm/IContext.h b/src/include/vsc/dm/IContext.h index 68c47d5..d047b4d 100644 --- a/src/include/vsc/dm/IContext.h +++ b/src/include/vsc/dm/IContext.h @@ -66,6 +66,7 @@ #include "vsc/dm/ITypeExprRangelist.h" #include "vsc/dm/ITypeExprRef.h" #include "vsc/dm/ITypeExprRefBottomUp.h" +#include "vsc/dm/ITypeExprRefPath.h" #include "vsc/dm/ITypeExprRefTopDown.h" #include "vsc/dm/ITypeExprSubField.h" #include "vsc/dm/ITypeExprUnary.h" @@ -356,6 +357,11 @@ class IContext : public virtual IValAlloc { int32_t scope_offset, int32_t field_index) = 0; + virtual ITypeExprRefPath *mkTypeExprRefPath( + ITypeExpr *root, + bool owned, + const std::vector &path) = 0; + virtual ITypeExprRefTopDown *mkTypeExprRefTopDown() = 0; virtual ITypeExprSubField *mkTypeExprSubField( diff --git a/src/include/vsc/dm/ITypeExprRefPath.h b/src/include/vsc/dm/ITypeExprRefPath.h new file mode 100644 index 0000000..48183a8 --- /dev/null +++ b/src/include/vsc/dm/ITypeExprRefPath.h @@ -0,0 +1,41 @@ +/** + * ITypeExprRefPath.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 +#include "vsc/dm/ITypeExprRef.h" + +namespace vsc { +namespace dm { + + +class ITypeExprRefPath : public virtual ITypeExprRef { +public: + + virtual ~ITypeExprRefPath() { } + + virtual const std::vector &getPath() const = 0; + +}; + +} /* namespace dm */ +} /* namespace vsc */ + + diff --git a/src/include/vsc/dm/IVisitor.h b/src/include/vsc/dm/IVisitor.h index 1a102e0..9df29b2 100644 --- a/src/include/vsc/dm/IVisitor.h +++ b/src/include/vsc/dm/IVisitor.h @@ -98,6 +98,7 @@ class ITypeExprRange; class ITypeExprRangelist; class ITypeExprRef; class ITypeExprRefBottomUp; +class ITypeExprRefPath; class ITypeExprRefTopDown; class ITypeExprSubField; class ITypeExprUnary; @@ -240,6 +241,8 @@ class IVisitor { virtual void visitTypeExprRefBottomUp(ITypeExprRefBottomUp *e) = 0; + virtual void visitTypeExprRefPath(ITypeExprRefPath *e) = 0; + virtual void visitTypeExprRefTopDown(ITypeExprRefTopDown *e) = 0; virtual void visitTypeExprSubField(ITypeExprSubField *e) = 0; diff --git a/src/include/vsc/dm/impl/ContextDelegator.h b/src/include/vsc/dm/impl/ContextDelegator.h index 5a17a55..8e9e549 100644 --- a/src/include/vsc/dm/impl/ContextDelegator.h +++ b/src/include/vsc/dm/impl/ContextDelegator.h @@ -403,6 +403,13 @@ class ContextDelegator : public virtual vsc::dm::IContext { return m_ctxt->mkTypeExprRefBottomUp(scope_offset, field_index); } + virtual ITypeExprRefPath *mkTypeExprRefPath( + ITypeExpr *target, + bool owned, + const std::vector &path) override { + return m_ctxt->mkTypeExprRefPath(target, owned, path); + } + virtual ITypeExprRefTopDown *mkTypeExprRefTopDown() { return m_ctxt->mkTypeExprRefTopDown(); } diff --git a/src/include/vsc/dm/impl/ValRef.h b/src/include/vsc/dm/impl/ValRef.h index 23ddf35..b27836e 100644 --- a/src/include/vsc/dm/impl/ValRef.h +++ b/src/include/vsc/dm/impl/ValRef.h @@ -160,9 +160,10 @@ class ValRef { // return type()->copyVal(*this); } - ValRef toMutable() const { + ValRef toMutable(bool move=false) const { + Flags flags = (move)?m_flags:VALREF_CLRFLAG(m_flags, Flags::Owned); // We want - if (VALREF_FLAGSET(m_flags, Flags::Mutable)) { + if (VALREF_FLAGSET(flags, Flags::Mutable)) { // This value is already mutable // It might be a value with locally-held storage (eg simple int). // It might be a reference to a field within an aggregate. If it @@ -171,7 +172,7 @@ class ValRef { // Either way, the referent will not hold ownership of any // allocated storage - Flags flags = VALREF_CLRFLAG(m_flags, Flags::Owned); + flags = VALREF_CLRFLAG(flags, Flags::Owned); // A mutable ref must change its source. In order for that // to happen, we need to convert a non-pointer reference @@ -181,13 +182,13 @@ class ValRef { // pointer semantics uintptr_t vp = m_vp; - if (VALREF_FLAGSET(m_flags, Flags::Scalar) && !VALREF_FLAGSET(m_flags, Flags::IsPtr)) { + if (VALREF_FLAGSET(flags, Flags::Scalar) && !VALREF_FLAGSET(flags, Flags::IsPtr)) { VALREF_DEBUG(stdout, "Transform to pointer\n"); vp = reinterpret_cast(&m_vp); flags = VALREF_SETFLAG(flags, Flags::IsPtr); } - return (VALREF_FLAGSET(m_flags, Flags::HasField))? + return (VALREF_FLAGSET(flags, Flags::HasField))? ValRef(vp, m_type_field.m_field, flags):ValRef(vp, m_type_field.m_type, flags); } else { // TODO: maybe this is just a failure? @@ -201,13 +202,14 @@ class ValRef { } } - ValRef toImmutable() const { + ValRef toImmutable(bool move=false) const { + Flags flags = (move)?m_flags:VALREF_CLRFLAG(m_flags, Flags::Owned); if (VALREF_FLAGSET(m_flags, Flags::HasField)) { return ValRef(m_vp, m_type_field.m_field, - VALREF_CLRFLAG(m_flags, Flags::Mutable)); + VALREF_CLRFLAG(flags, Flags::Mutable)); } else { return ValRef(m_vp, m_type_field.m_type, - VALREF_CLRFLAG(m_flags, Flags::Mutable)); + VALREF_CLRFLAG(flags, Flags::Mutable)); } } diff --git a/src/include/vsc/dm/impl/VisitorBase.h b/src/include/vsc/dm/impl/VisitorBase.h index f8f10d9..1ac0ef2 100644 --- a/src/include/vsc/dm/impl/VisitorBase.h +++ b/src/include/vsc/dm/impl/VisitorBase.h @@ -82,6 +82,7 @@ #include "vsc/dm/ITypeExprRangelist.h" #include "vsc/dm/ITypeExprRef.h" #include "vsc/dm/ITypeExprRefBottomUp.h" +#include "vsc/dm/ITypeExprRefPath.h" #include "vsc/dm/ITypeExprRefTopDown.h" #include "vsc/dm/ITypeExprSubField.h" #include "vsc/dm/ITypeExprUnary.h" @@ -400,6 +401,8 @@ class VisitorBase : public virtual IVisitor { virtual void visitTypeExprRefBottomUp(ITypeExprRefBottomUp *e) override { } + virtual void visitTypeExprRefPath(ITypeExprRefPath *e) override { } + virtual void visitTypeExprRefTopDown(ITypeExprRefTopDown *e) override { } virtual void visitTypeExprSubField(ITypeExprSubField *e) override {