• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rjfarmer / gfModParser / 13871568527

15 Mar 2025 09:25AM UTC coverage: 85.347% (-0.5%) from 85.839%
13871568527

push

github

rjfarmer
Add typespec

38 of 53 new or added lines in 3 files covered. (71.7%)

431 of 505 relevant lines covered (85.35%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.55
/gfModParser/modules/expressions.py
1
# SPDX-License-Identifier: GPL-2.0+
2

3
from .. import utils
1✔
4

5

6
class expression:
1✔
7
    def __init__(self, expression, version):
1✔
NEW
8
        self._expression = expression
×
NEW
9
        self.version = version
×
10

11
    @property
1✔
12
    def type(self):
1✔
NEW
13
        return self._expression[0]
×
14

15
    @property
1✔
16
    def typespec(self):
1✔
NEW
17
        return self._expression[1]
×
18

19
    @property
1✔
20
    def rank(self):
1✔
NEW
21
        return int(self._expression[2])
×
22

23

24
# class expression:
25
#     exp_type: str = ""
26
#     ts: typespec = None
27
#     rank: int = -1
28
#     _saved_value: t.Any = None
29
#     _value: t.Any = None
30
#     _resolved_value: t.Any = (
31
#         None  # value may by a symbol_ref, so this is the value after resolving the reference
32
#     )
33
#     arglist: actual_arglist = None  # PDT's?
34
#     charlen: int = -1
35
#     unary_op: str = ""
36
#     unary_args: t.Any = None
37
#     args: t.Any = None
38

39
#     def __init__(self, *args):
40
#         self.raw = args
41
#         self._resolved_value = None
42
#         if not len(args):
43
#             return
44
#         self.exp_type = args[0]
45
#         self.ts = typespec(*args[1])
46
#         self.rank = int(args[2])
47

48
#         if self.exp_type == "OP":
49
#             self._value = None
50
#             self.unary_op = args[3]
51
#             self.unary_args = [expression(*args[4]), expression(*args[5])]
52
#         elif self.exp_type == "FUNCTION":
53
#             self._value = symbol_ref(args[3])
54
#             self.args = expression(*args[4][0][1])
55
#         elif self.exp_type == "CONSTANT":
56
#             if self.ts.type == "REAL":
57
#                 self._value = hextofloat(string_clean(args[3]), self.ts.kind)
58
#             elif self.ts.type == "INTEGER":
59
#                 self._value = int(string_clean(args[3]))
60
#             elif self.ts.type == "CHARACTER":
61
#                 self.charlen = int(args[3])
62
#                 self._value = string_clean(args[4])
63
#             elif self.ts.type == "COMPLEX":
64
#                 self._value = complex(
65
#                     hextofloat(string_clean(args[3]), self.ts.kind),
66
#                     hextofloat(string_clean(args[4]), self.ts.kind),
67
#                 )
68
#             elif self.ts.type == "LOGICAL":
69
#                 self._value = int(args[3]) == 1
70
#             else:
71
#                 raise NotImplementedError(args)
72
#         elif self.exp_type == "VARIABLE":
73
#             self._value = symbol_ref(args[3])
74
#         elif self.exp_type == "SUBSTRING":
75
#             raise NotImplementedError(args)
76
#         elif self.exp_type == "ARRAY" or self.exp_type == "STRUCTURE":
77
#             self._value = []
78
#             for i in args[3]:
79
#                 self._value.append(
80
#                     expression(*i[0]).value
81
#                 )  # Wheres the extra component comming from?
82
#         elif self.exp_type == "NULL":
83
#             self._value = args[3]
84
#         elif self.exp_type == "COMPCALL":
85
#             raise NotImplementedError(args)
86
#         elif self.exp_type == "PPC":
87
#             raise NotImplementedError(args)
88
#         elif self.exp_type == "UNKNOWN":
89
#             raise NotImplementedError(args)
90
#         else:
91
#             raise AttributeError(f"Can't match {self.exp_type}")
92

93
#         try:
94
#             self.arglist = actual_arglist(*args[6])
95
#         except IndexError:
96
#             self.arglist = []
97

98
#         self._saved_value = self._value
99

100
#     @property
101
#     def value(self):
102
#         if self._resolved_value is not None:
103
#             return self._resolved_value
104
#         else:
105
#             return self._value
106

107
#     @value.setter
108
#     def value(self, value):
109
#         self._resolved_value = value
110

111

112
# Need to store this here as we get a cyclic dependency
113
# between expressions and typespec
114
class typespec:
1✔
115
    def __init__(self, typespec, version):
1✔
116
        self._typespec = typespec
1✔
117
        self.version = version
1✔
118

119
    @property
1✔
120
    def type(self):
1✔
121
        return self._typespec[0]
1✔
122

123
    def _isclass(self):
1✔
124
        return self.type == "CLASS" or self.type == "DERIVED"
1✔
125

126
    @property
1✔
127
    def kind(self):
1✔
128
        if not self._isclass():
1✔
129
            return int(self._typespec[1])
1✔
130

131
    @property
1✔
132
    def class_ref(self):
1✔
NEW
133
        if self._isclass():
×
NEW
134
            return int(self._typespec[1])
×
135

136
    @property
1✔
137
    def interface(self):
1✔
NEW
138
        return self._typespec[2]
×
139

140
    @property
1✔
141
    def is_c_interop(self):
1✔
142
        return int(self._typespec[3]) == 1
1✔
143

144
    @property
1✔
145
    def is_iso_c(self):
1✔
NEW
146
        return int(self._typespec[4]) == 1
×
147

148
    @property
1✔
149
    def type2(self):
1✔
150
        # Whats this?
NEW
151
        return self._typespec[5]
×
152

153
    @property
1✔
154
    def charlen(self):
1✔
NEW
155
        return self._typespec[6]
×
156

157
    #     try:
158
    #         if not args[6][0]:
159
    #             self.charlen = -1
160
    #         else:
161
    #             self.charlen = expression(
162
    #                 *args[6][0]
163
    #             )  # TODO: might this need to be iterated for mulit-d strings?
164
    #     except IndexError:
165
    #         self.charlen = -1
166

167
    @property
1✔
168
    def deferred_cl(self):
1✔
NEW
169
        if len(self._typespec) == 8:
×
NEW
170
            return self._typespec[7] == "DEFERRED_CL"
×
171

NEW
172
        return False
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc