zuspec-dataclasses 0.0.1.6307838556__py2.py3-none-any.whl → 0.0.1.6314474429__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ Created on Mar 19, 2022
6
6
 
7
7
  import typeworks
8
8
 
9
+ from vsc_dataclasses.impl.ctor import Ctor as VscCtor
9
10
  from .type_info import TypeInfo
10
11
  from .type_kind_e import TypeKindE
11
12
  from .ctor_scope import CtorScope
@@ -228,6 +229,7 @@ class Ctor(object):
228
229
 
229
230
  @classmethod
230
231
  def init(cls, ctxt):
232
+ VscCtor.init(ctxt)
231
233
  cls._inst = Ctor()
232
234
  cls._inst._ctxt = ctxt
233
235
 
@@ -60,7 +60,7 @@ class ZspDataModelCppGen(VscDataModelCppGen,VisitorBase):
60
60
  self._ctxt,
61
61
  i.name()))
62
62
  else:
63
- self.println("zsp::arl::dm::IDataTypeComponent %s_t = %s->mkDataTypeComponent(\"%s\");" % (
63
+ self.println("zsp::arl::dm::IDataTypeComponent *%s_t = %s->mkDataTypeComponent(\"%s\");" % (
64
64
  self.leaf_name(i.name()),
65
65
  self._ctxt,
66
66
  i.name()))
@@ -120,7 +120,7 @@ class ZspDataModelCppGen(VscDataModelCppGen,VisitorBase):
120
120
  else:
121
121
  self.println("{")
122
122
  self.inc_indent()
123
- self.println("zsp::arl::dm::IDataTypeAction %s_t = %s->mkDataTypeAction(\"%s\");" % (
123
+ self.println("zsp::arl::dm::IDataTypeAction *%s_t = %s->mkDataTypeAction(\"%s\");" % (
124
124
  self.leaf_name(i.name()),
125
125
  self._ctxt,
126
126
  i.name()))
@@ -64,6 +64,10 @@ class TypeInfoAction(TypeInfo):
64
64
  modelinfo_p.addSubfield(field._modelinfo)
65
65
 
66
66
  return field
67
+
68
+ # def createTypeInst(self):
69
+ # obj = super().createTypeInst()
70
+ # print("LibObj: %s" % str(obj._modelinfo.libobj))
67
71
 
68
72
  def elabActivities(self, obj):
69
73
  ctor_a = Ctor.inst()
@@ -0,0 +1,197 @@
1
+ #****************************************************************************
2
+ #* extract_cpp_embedded_dsl.py
3
+ #*
4
+ #* Copyright 2022 Matthew Ballance and Contributors
5
+ #*
6
+ #* Licensed under the Apache License, Version 2.0 (the "License"); you may
7
+ #* not use this file except in compliance with the License.
8
+ #* You may obtain a copy of the License at:
9
+ #*
10
+ #* http://www.apache.org/licenses/LICENSE-2.0
11
+ #*
12
+ #* Unless required by applicable law or agreed to in writing, software
13
+ #* distributed under the License is distributed on an "AS IS" BASIS,
14
+ #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ #* See the License for the specific language governing permissions and
16
+ #* limitations under the License.
17
+ #*
18
+ #* Created on:
19
+ #* Author:
20
+ #*
21
+ #****************************************************************************
22
+ from typing import List
23
+
24
+ #
25
+ #
26
+ # ZSP_DATACLASSES(TestSuite_testname, RootComp, RootAction, R"(
27
+ # @vdc.randclass
28
+ # class MyC(object):
29
+ # a : vdc.rand_uint32_t
30
+ # )")
31
+ #
32
+ #
33
+
34
+ class DSLContent(object):
35
+ def __init__(self,
36
+ name,
37
+ root_comp,
38
+ root_action,
39
+ content):
40
+ self.name = name
41
+ self.root_comp = root_comp
42
+ self.root_action = root_action
43
+ self.content = content
44
+
45
+ class ExtractCppEmbeddedDSL(object):
46
+
47
+ def __init__(self,
48
+ file_or_fp,
49
+ name=None,
50
+ macro_name="ZSP_DATACLASSES"):
51
+ self._macro_name = macro_name
52
+ if hasattr(file_or_fp, "read"):
53
+ # This is a stream-like object
54
+ self._fp = file_or_fp
55
+ if name is None:
56
+ self._name = self._fp.name()
57
+ else:
58
+ self._fp = open(file_or_fp, "r")
59
+ self._name = file_or_fp
60
+
61
+ self._lineno = 0
62
+ self._unget_ch = None
63
+ self._last_ch = None
64
+ self._buffer = ""
65
+ self._buffer_i = 0
66
+
67
+ def extract(self) -> List[DSLContent]:
68
+ ret = []
69
+
70
+ while self.find_macro():
71
+
72
+ lineno = self._lineno
73
+ while True:
74
+ ch = self.getch()
75
+
76
+ if ch is None or ch == '(':
77
+ break
78
+
79
+ if ch is None:
80
+ raise Exception("Failed to parse embedded DSL @ %s:%d" % (self._name, self._lineno))
81
+
82
+ # Now, collect the complete content of the macro
83
+ content = ""
84
+ count_b = 1
85
+ while count_b > 0:
86
+ ch = self.getch()
87
+
88
+ if ch is None:
89
+ break
90
+ content += ch
91
+
92
+ if ch == '(':
93
+ count_b += 1
94
+ elif ch == ')':
95
+ count_b -= 1
96
+
97
+ if count_b > 0:
98
+ raise Exception("Unbalanced parens")
99
+ content = content[:-2]
100
+
101
+ # We now have text from a macro invocation
102
+ start = 0
103
+ count_b = 0
104
+ params = []
105
+
106
+ for i in range(len(content)):
107
+ if content[i] == "," and count_b == 0:
108
+ params.append(content[start:i].strip())
109
+ start = i+1
110
+ elif content[i] == '(':
111
+ count_b += 1
112
+ elif content[i] == ')':
113
+ count_b -= 1
114
+
115
+ if count_b != 0:
116
+ raise Exception("Unbalanced parens while tokenizing")
117
+
118
+ if start < len(content):
119
+ params.append(content[start:].strip())
120
+
121
+ if len(params) != 4:
122
+ raise Exception("Expected 3 params; received %d" % len(params))
123
+
124
+ if params[-1].startswith('R"('):
125
+ params[-1] = params[-1][3:-2]
126
+
127
+ content = params[-1].split("\n")
128
+ min_ws = 10000
129
+
130
+ for l in content:
131
+ l_strip = l.strip()
132
+ if l_strip != "":
133
+ ws_l = len(l) - len(l_strip)
134
+ if ws_l < min_ws:
135
+ min_ws = ws_l
136
+
137
+ for i in range(len(content)):
138
+ content[i] = content[i][min_ws:]
139
+
140
+ vsc_content = "\n".join(content)
141
+
142
+ root_comp = params[1]
143
+ root_action = params[2]
144
+
145
+ info = DSLContent(params[0], root_comp, root_action, vsc_content)
146
+ ret.append(info)
147
+
148
+ self._fp.close()
149
+ return ret
150
+
151
+ def find_macro(self):
152
+
153
+ while True:
154
+ line = self._fp.readline()
155
+ self._lineno += 1
156
+
157
+ if line == "":
158
+ break
159
+
160
+ idx = line.find(self._macro_name)
161
+
162
+ if idx >= 0:
163
+ self._buffer = line
164
+ self._buffer_i = idx + len(self._macro_name)
165
+ return True
166
+
167
+ return False
168
+
169
+ def getch(self):
170
+ if self._buffer is None:
171
+ return None
172
+
173
+ if self._buffer_i >= len(self._buffer):
174
+ try:
175
+ self._buffer = self._fp.readline()
176
+ self._buffer_i = 0
177
+ self._lineno += 1
178
+ if self._buffer == "":
179
+ self._buffer = None
180
+ return None
181
+ except Exception:
182
+ self._buffer = None
183
+ return None
184
+
185
+ ret = self._buffer[self._buffer_i]
186
+ self._buffer_i += 1
187
+ return ret
188
+
189
+ def ungetch(self, ch):
190
+ if self._buffer is None:
191
+ self._buffer = ch
192
+ elif self._buffer_i > 0:
193
+ self._buffer_i -= 1
194
+ self._buffer[self._buffer_i] = ch
195
+ else:
196
+ self._buffer.insert(0, ch)
197
+
@@ -22,8 +22,78 @@
22
22
  #*
23
23
  #****************************************************************************
24
24
 
25
+ import argparse
26
+ import os
27
+ import zsp_dataclasses as zdc
28
+ from zsp_dataclasses.impl.ctor import Ctor
29
+ from zsp_dataclasses.impl.pyctxt.context import Context
30
+ from zsp_dataclasses.impl.generators.zsp_data_model_cpp_gen import ZspDataModelCppGen
31
+ from ..extract_cpp_embedded_dsl import ExtractCppEmbeddedDSL
32
+
33
+ def get_parser():
34
+ parser = argparse.ArgumentParser()
35
+ parser.add_argument("-o","--outdir", default="zspdefs",
36
+ help="Specifies the output directory")
37
+ parser.add_argument("-d", "--depfile",
38
+ help="Specifies a dependency file")
39
+ parser.add_argument("files", nargs='+')
40
+
41
+ return parser
42
+
25
43
  def main():
26
- pass
44
+ parser = get_parser()
45
+ args = parser.parse_args()
46
+
47
+ deps_ts = None
48
+ if args.depfile is not None and os.path.isfile(args.depfile):
49
+ deps_ts = os.path.getmtime(args.depfile)
50
+
51
+ fragment_m = {}
52
+ for file in args.files:
53
+ print("Process %s" % file)
54
+ if deps_ts is not None:
55
+ file_ts = os.path.getmtime(file)
56
+ if file_ts <= deps_ts:
57
+ print("Skip due to deps")
58
+ continue
59
+
60
+ fragments = ExtractCppEmbeddedDSL(file).extract()
61
+ print("fragments: %s" % str(fragments))
62
+
63
+ for f in fragments:
64
+ if f.name in fragment_m.keys():
65
+ raise Exception("Duplicate fragment-name %s" % f.name)
66
+ fragment_m[f.name] = f
67
+
68
+ if not os.path.isdir(args.outdir):
69
+ os.makedirs(args.outdir, exist_ok=True)
70
+
71
+ for fn in fragment_m.keys():
72
+ Ctor.init(Context())
73
+
74
+ _globals = globals().copy()
75
+ exec(fragment_m[fn].content, _globals)
76
+
77
+ Ctor.inst().elab()
78
+
79
+ header_path = os.path.join(args.outdir, "%s.h" % fn)
80
+ root_comp = Ctor.inst().ctxt().findDataTypeComponent(fragment_m[fn].root_comp)
81
+ if root_comp is None:
82
+ raise Exception("Failed to find root component %s" % fragment_m[fn].root_comp)
83
+ root_action = Ctor.inst().ctxt().findDataTypeAction(fragment_m[fn].root_action)
84
+ if root_action is None:
85
+ raise Exception("Failed to find root action %s" % fragment_m[fn].root_action)
86
+ gen = ZspDataModelCppGen()
87
+ gen._ctxt = "m_ctxt"
88
+ with open(header_path, "w") as fp:
89
+ fp.write(gen.generate(root_comp, root_action))
90
+
91
+ pass
92
+
93
+ if args.depfile is not None:
94
+ with open(args.depfile, "w") as fp:
95
+ fp.write("\n")
27
96
 
28
97
  if __name__ == "__main__":
29
98
  main()
99
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zuspec-dataclasses
3
- Version: 0.0.1.6307838556
3
+ Version: 0.0.1.6314474429
4
4
  Summary: Front-end for capturing Action Relation Level models using dataclasses
5
5
  Home-page: https://github.com/zuspec/zuspec-dataclasses
6
6
  Author: Matthew Ballance
@@ -30,7 +30,7 @@ zsp_dataclasses/impl/component_decorator_impl.py,sha256=1IK5-fYw8IYP8t55FYqMnmdz
30
30
  zsp_dataclasses/impl/component_impl.py,sha256=_FEaLbmsha1xWySpbMlmf782cX0v2865meFYyx2hSL4,4758
31
31
  zsp_dataclasses/impl/constraint_impl.py,sha256=qEbh7cBRjEOULEEpgX8cqSvNuIDfbKYwG2kZovHdIWQ,190
32
32
  zsp_dataclasses/impl/context.py,sha256=uoHZQGN6aZGNAxtz-ess9A6TChAzd9iMqrL3z0X8KBk,6559
33
- zsp_dataclasses/impl/ctor.py,sha256=zwM9WlJQ9jXsP8hvuL5L2XEoXunLnkjHEC-lrNzHTBk,6689
33
+ zsp_dataclasses/impl/ctor.py,sha256=0zcWhlvDXsmJpnnZIXkSKzjPg_xFoZ5-k2HC8nqHuiY,6770
34
34
  zsp_dataclasses/impl/ctor_scope.py,sha256=HsWpJqE6eQl0--aWPLm11WEzuFF3CKHc7S_P89PeZX4,956
35
35
  zsp_dataclasses/impl/decorator_impl_base.py,sha256=2g9PgX2WKDqdlQW4HhCa_Ayfm9-b9LIbQrJh_T0dOdg,3817
36
36
  zsp_dataclasses/impl/do_impl.py,sha256=IGajJ-sAOR9noOdXcb2SrboE0g9YS6MNaWkyPWLLf14,1597
@@ -70,7 +70,7 @@ zsp_dataclasses/impl/struct_decorator_impl.py,sha256=W5IwBKzQok51lxAJnlewAk9dpoL
70
70
  zsp_dataclasses/impl/struct_kind_e.py,sha256=gUrxFdT8YnK0NrMSKuHFIPIBHl7Q7y4BGRU1dvYrDo8,216
71
71
  zsp_dataclasses/impl/type_info.py,sha256=CHFcynN8crFHQk7p41QxMEDVX7G5tGskVZh-bzfkn5o,7620
72
72
  zsp_dataclasses/impl/type_kind_e.py,sha256=3EqUEeQrtmQMGPcXGKnuA1dFDMu46lN40BHQzSsuCLI,330
73
- zsp_dataclasses/impl/typeinfo_action.py,sha256=Zr2NhOHUVu2cKqdFkuSieQDKcGwxGTl3kjH2fnZs7QY,3897
73
+ zsp_dataclasses/impl/typeinfo_action.py,sha256=66BBe15H4eUW7lTcd6HMtQGCjgikQE4WM8YWJvedv0U,4034
74
74
  zsp_dataclasses/impl/typeinfo_claim.py,sha256=TlN200FoSakB-hqpNPY-ZjZq9BeVsXNnawAFtLU26So,1775
75
75
  zsp_dataclasses/impl/typeinfo_comp_ref.py,sha256=Y1ek3i2k9Clf3GrINEb6uo_P79PX5jUUPzBAYWwQ3IM,952
76
76
  zsp_dataclasses/impl/typeinfo_component.py,sha256=vovYUjjXLdwdsswIzy6k5Qfwo4KP9Uw-Ur6eYwWaEt4,6619
@@ -81,7 +81,7 @@ zsp_dataclasses/impl/typeinfo_flow_obj_ref.py,sha256=NhNwKY2Qp6umQWgPRpAyqLPQsjX
81
81
  zsp_dataclasses/impl/typeinfo_pool.py,sha256=-fbPtyoiorI1GwEKxXEn6Birxq4WJCNn_0exAwTAIdw,443
82
82
  zsp_dataclasses/impl/typeinfo_struct.py,sha256=JF-1NJGaNxgm6aTEkNHPEx230yMXExnORLlJIHe4KBI,333
83
83
  zsp_dataclasses/impl/generators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
84
- zsp_dataclasses/impl/generators/zsp_data_model_cpp_gen.py,sha256=r2fqYL-2q-YvPEqVHspprXcMBmb4Y6UCDt2N1wuSWPM,4778
84
+ zsp_dataclasses/impl/generators/zsp_data_model_cpp_gen.py,sha256=7tD6Zs52SGf8m59kUx8NUrLrznhltKwiU4tDn22gCg0,4780
85
85
  zsp_dataclasses/impl/pyctxt/context.py,sha256=B3EqQth4L086F2GkAsueOnme3tjwINlzb9NGuE2Oo70,2952
86
86
  zsp_dataclasses/impl/pyctxt/data_type_action.py,sha256=jMPEA8MKXeVIuDbQaCmnZT4U6kjLIqTLQs8YzULKYzY,1166
87
87
  zsp_dataclasses/impl/pyctxt/data_type_activity_replicate.py,sha256=RE3uNEAjs-FeeThN-KClneFCXWAfTuefaA0Fhlui_38,1298
@@ -97,9 +97,10 @@ zsp_dataclasses/impl/pyctxt/type_field_activity.py,sha256=SFpdm_fOQgE1F3qKTM9gU9
97
97
  zsp_dataclasses/impl/pyctxt/type_proc_stmt_var_decl.py,sha256=S72xc5tIRiFOIv68yop77IO7a1Dy7WQ2YyZ4NSznhoE,1235
98
98
  zsp_dataclasses/impl/pyctxt/visitor_base.py,sha256=2LqVRXJU5_vKoUBHePdb1zSew-T2l2KrMe8osNuApq0,1978
99
99
  zsp_dataclasses/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
100
- zsp_dataclasses/util/gen_cpp_dt_defs/__main__.py,sha256=qj9JZGOZkn4F4S275Wepbgn_-Tic58KeNpKSlwj1RPc,932
101
- zuspec_dataclasses-0.0.1.6307838556.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
102
- zuspec_dataclasses-0.0.1.6307838556.dist-info/METADATA,sha256=QwyLM-Cld_hlaC26hwTmi215HeVn_dEy4z118pqX6rw,499
103
- zuspec_dataclasses-0.0.1.6307838556.dist-info/WHEEL,sha256=iYlv5fX357PQyRT2o6tw1bN-YcKFFHKqB_LwHO5wP-g,110
104
- zuspec_dataclasses-0.0.1.6307838556.dist-info/top_level.txt,sha256=BHigRYcGvNv_xCJUUv5OXgSPSoczsH3Tle0gABks4l0,16
105
- zuspec_dataclasses-0.0.1.6307838556.dist-info/RECORD,,
100
+ zsp_dataclasses/util/extract_cpp_embedded_dsl.py,sha256=SyMMLumZD6fsubj40hyekYzWyrcoUGTijJH3NmK1ihY,5630
101
+ zsp_dataclasses/util/gen_cpp_dt_defs/__main__.py,sha256=xUbDpPaC9JrRkfDFKDMAVo-CBvqJla6NeJX8vzUGXo8,3311
102
+ zuspec_dataclasses-0.0.1.6314474429.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
103
+ zuspec_dataclasses-0.0.1.6314474429.dist-info/METADATA,sha256=JmHD3TheN_yM2OfFYcRlyeja437khpL0owfG9ENgFSM,499
104
+ zuspec_dataclasses-0.0.1.6314474429.dist-info/WHEEL,sha256=iYlv5fX357PQyRT2o6tw1bN-YcKFFHKqB_LwHO5wP-g,110
105
+ zuspec_dataclasses-0.0.1.6314474429.dist-info/top_level.txt,sha256=BHigRYcGvNv_xCJUUv5OXgSPSoczsH3Tle0gABks4l0,16
106
+ zuspec_dataclasses-0.0.1.6314474429.dist-info/RECORD,,