flamapy-fm 2.9.0.dev3__py3-none-any.whl → 2.9.0.dev4__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.
- flamapy/metamodels/fm_metamodel/models/clause_set.py +5 -0
- flamapy/metamodels/fm_metamodel/transformations/clafer_writer.py +12 -3
- flamapy/metamodels/fm_metamodel/transformations/constraint_support.py +73 -0
- flamapy/metamodels/fm_metamodel/transformations/featureide_writer.py +13 -1
- flamapy/metamodels/fm_metamodel/transformations/flat_fm.py +96 -29
- flamapy/metamodels/fm_metamodel/transformations/json_writer.py +10 -1
- flamapy/metamodels/fm_metamodel/transformations/pl_writer.py +10 -1
- flamapy/metamodels/fm_metamodel/transformations/refactorings/feature_cardinality_refactoring_paper.py +2 -1
- flamapy/metamodels/fm_metamodel/transformations/splot_writer.py +14 -1
- flamapy/metamodels/fm_metamodel/transformations/uvl_reader.py +26 -4
- {flamapy_fm-2.9.0.dev3.dist-info → flamapy_fm-2.9.0.dev4.dist-info}/METADATA +4 -4
- {flamapy_fm-2.9.0.dev3.dist-info → flamapy_fm-2.9.0.dev4.dist-info}/RECORD +16 -15
- {flamapy_fm-2.9.0.dev3.dist-info → flamapy_fm-2.9.0.dev4.dist-info}/WHEEL +0 -0
- {flamapy_fm-2.9.0.dev3.dist-info → flamapy_fm-2.9.0.dev4.dist-info}/entry_points.txt +0 -0
- {flamapy_fm-2.9.0.dev3.dist-info → flamapy_fm-2.9.0.dev4.dist-info}/licenses/LICENSE +0 -0
- {flamapy_fm-2.9.0.dev3.dist-info → flamapy_fm-2.9.0.dev4.dist-info}/top_level.txt +0 -0
|
@@ -145,6 +145,11 @@ class _Encoder:
|
|
|
145
145
|
self.clause_groups: list[tuple[str, list[list[int]]]] = []
|
|
146
146
|
|
|
147
147
|
def encode(self, feature_model: FeatureModel) -> ClauseSet:
|
|
148
|
+
# Only the logical constraints are encoded; say so when others are left out (#5).
|
|
149
|
+
from flamapy.metamodels.fm_metamodel.transformations.constraint_support import ( # noqa: PLC0415 pylint: disable=import-outside-toplevel,cyclic-import
|
|
150
|
+
warn_non_boolean_constraints,
|
|
151
|
+
)
|
|
152
|
+
warn_non_boolean_constraints(feature_model, 'CNF encoding', stacklevel=5)
|
|
148
153
|
for feature in feature_model.get_features():
|
|
149
154
|
self._add_feature(feature)
|
|
150
155
|
self._add_root(feature_model.root)
|
|
@@ -14,6 +14,9 @@ from flamapy.metamodels.fm_metamodel.transformations.fm_secure_features_names im
|
|
|
14
14
|
prefix_if_not_letter,
|
|
15
15
|
secure_name,
|
|
16
16
|
)
|
|
17
|
+
from flamapy.metamodels.fm_metamodel.transformations.constraint_support import (
|
|
18
|
+
reject_non_boolean_constraints,
|
|
19
|
+
)
|
|
17
20
|
|
|
18
21
|
|
|
19
22
|
ATTRIBUTED_FEATURE = 'AttributedFeature'
|
|
@@ -55,8 +58,9 @@ class ClaferWriter(ModelToText):
|
|
|
55
58
|
(MultipleGroupDecompositionRefactoring), which adds abstract features but keeps the
|
|
56
59
|
configurations of the original features.
|
|
57
60
|
|
|
58
|
-
Only the logical constraints of the model are written; arithmetic
|
|
59
|
-
constraints
|
|
61
|
+
Only the logical constraints of the model are written; a model with arithmetic or other
|
|
62
|
+
non-Boolean constraints is rejected (as in PLWriter and FeatureIDEWriter), or, with
|
|
63
|
+
``boolean_only=True``, written without them, with a warning and a comment in the file.
|
|
60
64
|
"""
|
|
61
65
|
|
|
62
66
|
@staticmethod
|
|
@@ -64,13 +68,16 @@ class ClaferWriter(ModelToText):
|
|
|
64
68
|
return 'txt'
|
|
65
69
|
|
|
66
70
|
def __init__(self, path: str, source_model: FeatureModel,
|
|
67
|
-
apply_refactorings: bool = False) -> None:
|
|
71
|
+
apply_refactorings: bool = False, *, boolean_only: bool = False) -> None:
|
|
68
72
|
self.path = path
|
|
69
73
|
self.source_model = source_model
|
|
70
74
|
self.apply_refactorings = apply_refactorings
|
|
75
|
+
self.boolean_only = boolean_only
|
|
71
76
|
self.mapping_names: dict[str, str] = {}
|
|
72
77
|
|
|
73
78
|
def transform(self) -> str:
|
|
79
|
+
note = reject_non_boolean_constraints(self.source_model, 'The Clafer writer',
|
|
80
|
+
self.boolean_only)
|
|
74
81
|
model = prepare_model(self.source_model, 'Clafer', [mixed_decomposition],
|
|
75
82
|
[decompose_groups], self.apply_refactorings)
|
|
76
83
|
secure_names = FMSecureFeaturesNames(model)
|
|
@@ -79,6 +86,8 @@ class ClaferWriter(ModelToText):
|
|
|
79
86
|
feature_model = secure_names.transform()
|
|
80
87
|
self.mapping_names = secure_names.mapping_names
|
|
81
88
|
clafer_str = fm_to_clafer(feature_model)
|
|
89
|
+
if note:
|
|
90
|
+
clafer_str = f'// {note}\n{clafer_str}'
|
|
82
91
|
if self.path is not None:
|
|
83
92
|
with open(self.path, 'w', encoding='utf8') as file:
|
|
84
93
|
file.write(clafer_str)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Constraints that the Boolean output formats and encodings cannot represent.
|
|
2
|
+
|
|
3
|
+
SPLOT, FeatureIDE XML, Clafer, the propositional-logic writer and the JSON serialisation write
|
|
4
|
+
only the Boolean (logical) constraints of a model, and the CNF and BDD encodings only reason over
|
|
5
|
+
them. Leaving the arithmetic, aggregate or string constraints out silently would describe a
|
|
6
|
+
different model, so the writers reject such models and the encodings warn (flamapy/flamapy#5).
|
|
7
|
+
A writer called with ``boolean_only=True`` writes the Boolean part of the model instead, with a
|
|
8
|
+
warning and, where the format has comments, a note in the file.
|
|
9
|
+
"""
|
|
10
|
+
import warnings
|
|
11
|
+
|
|
12
|
+
from flamapy.core.exceptions import FlamaException
|
|
13
|
+
from flamapy.metamodels.fm_metamodel.models import Constraint, FeatureModel
|
|
14
|
+
|
|
15
|
+
MAX_SHOWN = 5 # constraints listed in a message
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def non_boolean_constraints(feature_model: FeatureModel) -> list[Constraint]:
|
|
19
|
+
"""The constraints of the model that are not Boolean (arithmetic, aggregate, string)."""
|
|
20
|
+
return [ctc for ctc in feature_model.get_constraints() if not ctc.is_logical_constraint()]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def describe_constraints(constraints: list[Constraint]) -> str:
|
|
24
|
+
# Local import: uvl_writer imports from this package.
|
|
25
|
+
from flamapy.metamodels.fm_metamodel.transformations.uvl_writer import ( # noqa: PLC0415 pylint: disable=import-outside-toplevel
|
|
26
|
+
UVLWriter,
|
|
27
|
+
)
|
|
28
|
+
shown = [UVLWriter.serialize_constraint(ctc) for ctc in constraints[:MAX_SHOWN]]
|
|
29
|
+
more = f' and {len(constraints) - MAX_SHOWN} more' if len(constraints) > MAX_SHOWN else ''
|
|
30
|
+
return '; '.join(shown) + more
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def reject_non_boolean_constraints(feature_model: FeatureModel, format_name: str,
|
|
34
|
+
boolean_only: bool = False) -> str:
|
|
35
|
+
"""Raise if the model has constraints that `format_name` cannot represent.
|
|
36
|
+
|
|
37
|
+
With `boolean_only`, warn instead, and return a note naming the constraints left out (an
|
|
38
|
+
empty string when there are none) for the writer to put in the file where it can.
|
|
39
|
+
"""
|
|
40
|
+
unsupported = non_boolean_constraints(feature_model)
|
|
41
|
+
if not unsupported:
|
|
42
|
+
return ''
|
|
43
|
+
described = describe_constraints(unsupported)
|
|
44
|
+
if not boolean_only:
|
|
45
|
+
raise FlamaException(
|
|
46
|
+
f'{format_name} cannot represent the {len(unsupported)} non-Boolean constraint(s) '
|
|
47
|
+
f'of the model ({described}); writing the model without them would describe a '
|
|
48
|
+
'different model. The UVL writer keeps them; boolean_only=True writes the Boolean '
|
|
49
|
+
'part of the model.')
|
|
50
|
+
warnings.warn(
|
|
51
|
+
f'{format_name} writes only the Boolean part of the model: its {len(unsupported)} '
|
|
52
|
+
f'non-Boolean constraint(s) are left out ({described}).', UserWarning, stacklevel=3)
|
|
53
|
+
return (f'Boolean part of the model only: {len(unsupported)} non-Boolean constraint(s) '
|
|
54
|
+
f'left out ({described}).')
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def xml_comment(text: str) -> str:
|
|
58
|
+
"""`text` made safe for an XML comment, which cannot contain '--'."""
|
|
59
|
+
while '--' in text:
|
|
60
|
+
text = text.replace('--', '- -')
|
|
61
|
+
return text
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def warn_non_boolean_constraints(feature_model: FeatureModel, encoding: str,
|
|
65
|
+
stacklevel: int = 3) -> None:
|
|
66
|
+
"""Warn that `encoding` leaves out the non-Boolean constraints of the model, if any."""
|
|
67
|
+
unsupported = non_boolean_constraints(feature_model)
|
|
68
|
+
if unsupported:
|
|
69
|
+
warnings.warn(
|
|
70
|
+
f'The {encoding} leaves out the {len(unsupported)} non-Boolean constraint(s) of the '
|
|
71
|
+
f'model ({describe_constraints(unsupported)}), so results computed on it are not '
|
|
72
|
+
'exact for this model. The Z3 backend reasons over them.',
|
|
73
|
+
UserWarning, stacklevel=stacklevel)
|
|
@@ -19,6 +19,10 @@ from flamapy.metamodels.fm_metamodel.transformations.group_support import (
|
|
|
19
19
|
refactor_cardinality_groups,
|
|
20
20
|
refactor_mutex_groups,
|
|
21
21
|
)
|
|
22
|
+
from flamapy.metamodels.fm_metamodel.transformations.constraint_support import (
|
|
23
|
+
reject_non_boolean_constraints,
|
|
24
|
+
xml_comment,
|
|
25
|
+
)
|
|
22
26
|
|
|
23
27
|
|
|
24
28
|
|
|
@@ -47,12 +51,18 @@ class FeatureIDEWriter(ModelToText):
|
|
|
47
51
|
return '.xml'
|
|
48
52
|
|
|
49
53
|
def __init__(self, path: str, source_model: FeatureModel,
|
|
50
|
-
apply_refactorings: bool = False) -> None:
|
|
54
|
+
apply_refactorings: bool = False, *, boolean_only: bool = False) -> None:
|
|
55
|
+
"""With ``boolean_only=True`` a model with arithmetic, aggregate or string constraints is
|
|
56
|
+
written without them, with a warning and a comment in the file; by default it is
|
|
57
|
+
rejected (flamapy/flamapy#5)."""
|
|
51
58
|
self._path = path
|
|
52
59
|
self._source_model = source_model
|
|
53
60
|
self.apply_refactorings = apply_refactorings
|
|
61
|
+
self.boolean_only = boolean_only
|
|
54
62
|
|
|
55
63
|
def transform(self) -> str:
|
|
64
|
+
note = reject_non_boolean_constraints(self._source_model, 'FeatureIDE XML',
|
|
65
|
+
self.boolean_only)
|
|
56
66
|
model = prepare_model(self._source_model, 'FeatureIDE XML',
|
|
57
67
|
[mixed_decomposition, mutex_group, cardinality_group],
|
|
58
68
|
[decompose_groups, refactor_mutex_groups,
|
|
@@ -61,6 +71,8 @@ class FeatureIDEWriter(ModelToText):
|
|
|
61
71
|
fm_tree = _to_featureidexml(model).getroot()
|
|
62
72
|
if fm_tree is None:
|
|
63
73
|
raise ValueError("The FeatureIDE XML tree has no root element.")
|
|
74
|
+
if note:
|
|
75
|
+
fm_tree.insert(0, ElementTree.Comment(f' {xml_comment(note)} '))
|
|
64
76
|
xml_str = ElementTree.tostring(fm_tree,
|
|
65
77
|
encoding='UTF-8',
|
|
66
78
|
method='xml',
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import copy
|
|
2
|
+
from collections import Counter
|
|
2
3
|
from typing import cast
|
|
3
4
|
|
|
5
|
+
from flamapy.core.exceptions import FlamaException
|
|
4
6
|
from flamapy.core.transformations import ModelToModel
|
|
5
7
|
from flamapy.core.models import VariabilityModel, AST
|
|
6
8
|
from flamapy.core.models.ast import ASTOperation, Node
|
|
@@ -37,44 +39,109 @@ class FlatFM(ModelToModel):
|
|
|
37
39
|
if not self._maintain_namespaces:
|
|
38
40
|
for ctc in new_feature_model.ctcs:
|
|
39
41
|
remove_namespace_constraint(ctc.ast, new_feature_model)
|
|
42
|
+
# A model imported once but referenced under several parents gives one instance per
|
|
43
|
+
# reference; their names are qualified with the parent's name ('Three.S.Spirits',
|
|
44
|
+
# 'Two.S.Spirits') so that the instances are independent (flamapy/fm_metamodel#110).
|
|
45
|
+
repeated = _repeated_references(new_feature_model.root)
|
|
46
|
+
if self._maintain_namespaces:
|
|
47
|
+
_reject_ambiguous_references(new_feature_model, repeated)
|
|
48
|
+
used_namespaces: set[str] = set()
|
|
40
49
|
features = [new_feature_model.root]
|
|
41
50
|
while features:
|
|
42
51
|
feature = features.pop()
|
|
43
52
|
if feature.reference is not None:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
#
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
feature.reference = imported_fm.root
|
|
50
|
-
# Copy the feature's attributes and relations from the referenced feature
|
|
51
|
-
feature.relations = feature.reference.relations
|
|
52
|
-
for relation in feature.relations:
|
|
53
|
-
relation.parent = feature
|
|
54
|
-
for child in relation.children:
|
|
55
|
-
child.parent = feature
|
|
56
|
-
feature.attributes.extend(feature.reference.attributes)
|
|
57
|
-
# Process attribute constraints
|
|
58
|
-
# (they are also in the imported model's ctcs, which are processed below)
|
|
59
|
-
feature.constraints_attributes.extend(feature.reference.constraints_attributes)
|
|
60
|
-
if not self._maintain_namespaces:
|
|
61
|
-
feature.name = feature.reference.name
|
|
62
|
-
for ctc in imported_fm.ctcs:
|
|
63
|
-
remove_namespace_constraint(ctc.ast, imported_fm)
|
|
64
|
-
else:
|
|
65
|
-
namespace = '.'.join(feature.name.split('.')[:-1])
|
|
66
|
-
put_namespace_to_features(feature.reference, namespace)
|
|
67
|
-
for ctc in imported_fm.ctcs:
|
|
68
|
-
put_namespace_to_constraint(ctc.ast, namespace)
|
|
69
|
-
# Add the constraints of the imported model (nested imports are reached when
|
|
70
|
-
# their referencing features are visited)
|
|
71
|
-
new_feature_model.ctcs.extend(imported_fm.ctcs)
|
|
72
|
-
feature.reference = None # Clear reference after copying
|
|
53
|
+
self._expand_reference(feature, new_feature_model, imported_models,
|
|
54
|
+
repeated, used_namespaces)
|
|
55
|
+
# The copy's own references are now namespaced per instance; count them so
|
|
56
|
+
# that one referenced twice inside it is told apart too.
|
|
57
|
+
repeated |= _repeated_references(feature)
|
|
73
58
|
features.extend(feature.get_children())
|
|
74
59
|
new_feature_model.imports = {} # Clear imports as they are not needed in the flat model
|
|
75
60
|
new_feature_model.alias_namespace = {} # Clear alias namespace as it is not needed in
|
|
76
61
|
return new_feature_model
|
|
77
62
|
|
|
63
|
+
def _expand_reference(self,
|
|
64
|
+
feature: Feature, new_feature_model: FeatureModel,
|
|
65
|
+
imported_models: dict[int, FeatureModel], repeated: set[str],
|
|
66
|
+
used_namespaces: set[str]) -> None:
|
|
67
|
+
"""Replace a feature that references an imported model by a copy of that model."""
|
|
68
|
+
# Every reference gets its own copy of the imported model: the same model may
|
|
69
|
+
# be referenced more than once (under one alias or several), and each
|
|
70
|
+
# reference is a separate subtree with its own namespace.
|
|
71
|
+
imported_fm = copy.deepcopy(imported_models[id(feature.reference)])
|
|
72
|
+
imported_models.update(get_imported_models_by_root(imported_fm))
|
|
73
|
+
reference = imported_fm.root
|
|
74
|
+
# Copy the feature's attributes and relations from the referenced feature
|
|
75
|
+
feature.relations = reference.relations
|
|
76
|
+
for relation in feature.relations:
|
|
77
|
+
relation.parent = feature
|
|
78
|
+
for child in relation.children:
|
|
79
|
+
child.parent = feature
|
|
80
|
+
feature.attributes.extend(reference.attributes)
|
|
81
|
+
# Process attribute constraints
|
|
82
|
+
# (they are also in the imported model's ctcs, which are processed below)
|
|
83
|
+
feature.constraints_attributes.extend(reference.constraints_attributes)
|
|
84
|
+
if not self._maintain_namespaces:
|
|
85
|
+
feature.name = reference.name
|
|
86
|
+
for ctc in imported_fm.ctcs:
|
|
87
|
+
remove_namespace_constraint(ctc.ast, imported_fm)
|
|
88
|
+
else:
|
|
89
|
+
namespace = '.'.join(feature.name.split('.')[:-1])
|
|
90
|
+
if feature.name in repeated:
|
|
91
|
+
namespace = _instance_namespace(feature, namespace, used_namespaces)
|
|
92
|
+
feature.name = f'{namespace}.{feature.name.split(".")[-1]}'
|
|
93
|
+
put_namespace_to_features(reference, namespace)
|
|
94
|
+
for ctc in imported_fm.ctcs:
|
|
95
|
+
put_namespace_to_constraint(ctc.ast, namespace)
|
|
96
|
+
# Add the constraints of the imported model (nested imports are reached when
|
|
97
|
+
# their referencing features are visited)
|
|
98
|
+
new_feature_model.ctcs.extend(imported_fm.ctcs)
|
|
99
|
+
feature.reference = None # Clear reference after copying
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _repeated_references(root: Feature) -> set[str]:
|
|
103
|
+
"""Names of the features under `root` that reference an imported model, and that more than
|
|
104
|
+
one feature shares (several references to the same import)."""
|
|
105
|
+
counts = Counter(f.name for f in _all_features(root) if f.reference is not None)
|
|
106
|
+
return {name for name, count in counts.items() if count > 1}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _all_features(root: Feature) -> list[Feature]:
|
|
110
|
+
features, stack = [], [root]
|
|
111
|
+
while stack:
|
|
112
|
+
feature = stack.pop()
|
|
113
|
+
features.append(feature)
|
|
114
|
+
stack.extend(feature.get_children())
|
|
115
|
+
return features
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _instance_namespace(feature: Feature, namespace: str, used: set[str]) -> str:
|
|
119
|
+
"""A namespace for one of several references to the same imported model: the import
|
|
120
|
+
namespace qualified with the name of the referencing feature's parent, and numbered if
|
|
121
|
+
two references share the parent as well."""
|
|
122
|
+
parent = feature.get_parent()
|
|
123
|
+
base = f'{parent.name}.{namespace}' if parent is not None else namespace
|
|
124
|
+
candidate, index = base, 2
|
|
125
|
+
while candidate in used:
|
|
126
|
+
candidate, index = f'{base}{index}', index + 1
|
|
127
|
+
used.add(candidate)
|
|
128
|
+
return candidate
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _reject_ambiguous_references(feature_model: FeatureModel, repeated: set[str]) -> None:
|
|
132
|
+
"""A constraint of the importing model that names a feature of a model referenced more
|
|
133
|
+
than once cannot tell which instance it means; say so instead of guessing."""
|
|
134
|
+
namespaces = {'.'.join(name.split('.')[:-1]) for name in repeated}
|
|
135
|
+
for ctc in feature_model.ctcs:
|
|
136
|
+
for node in get_feature_terms(ctc.ast):
|
|
137
|
+
namespace = '.'.join(str(node.data).split('.')[:-1])
|
|
138
|
+
if namespace in namespaces:
|
|
139
|
+
raise FlamaException(
|
|
140
|
+
f'The constraint {ctc.name} refers to {node.data}, but the model imported '
|
|
141
|
+
f'as {namespace} is referenced more than once, so it has one instance per '
|
|
142
|
+
'reference and the constraint does not say which one it means. Import the '
|
|
143
|
+
'model under a separate alias for each reference to tell them apart.')
|
|
144
|
+
|
|
78
145
|
|
|
79
146
|
def put_namespace_to_features(root: Feature, namespace: str) -> None:
|
|
80
147
|
"""Put the namespace to the features in the feature model."""
|
|
@@ -10,6 +10,9 @@ from flamapy.metamodels.fm_metamodel.models import (
|
|
|
10
10
|
FeatureModel,
|
|
11
11
|
Attribute
|
|
12
12
|
)
|
|
13
|
+
from flamapy.metamodels.fm_metamodel.transformations.constraint_support import (
|
|
14
|
+
reject_non_boolean_constraints,
|
|
15
|
+
)
|
|
13
16
|
|
|
14
17
|
|
|
15
18
|
class JSONFeatureType(Enum):
|
|
@@ -33,11 +36,17 @@ class JSONWriter(ModelToText):
|
|
|
33
36
|
def get_destination_extension() -> str:
|
|
34
37
|
return 'json'
|
|
35
38
|
|
|
36
|
-
def __init__(self, path: str, source_model: FeatureModel):
|
|
39
|
+
def __init__(self, path: str, source_model: FeatureModel, *, boolean_only: bool = False):
|
|
40
|
+
"""With ``boolean_only=True`` a model with arithmetic, aggregate or string constraints is
|
|
41
|
+
written without them, with a warning (JSON has no comments); by default it is rejected
|
|
42
|
+
(flamapy/flamapy#5)."""
|
|
37
43
|
self.path = path
|
|
38
44
|
self.source_model = source_model
|
|
45
|
+
self.boolean_only = boolean_only
|
|
39
46
|
|
|
40
47
|
def transform(self) -> str:
|
|
48
|
+
reject_non_boolean_constraints(self.source_model, 'The JSON serialisation',
|
|
49
|
+
self.boolean_only)
|
|
41
50
|
json_object = to_json(self.source_model)
|
|
42
51
|
if self.path is not None:
|
|
43
52
|
with open(self.path, 'w', encoding='utf8') as file:
|
|
@@ -9,6 +9,9 @@ from flamapy.metamodels.fm_metamodel.transformations.fm_secure_features_names im
|
|
|
9
9
|
FMSecureFeaturesNames,
|
|
10
10
|
)
|
|
11
11
|
from flamapy.metamodels.fm_metamodel.transformations.uvl_writer import xor_as_negated_equivalence
|
|
12
|
+
from flamapy.metamodels.fm_metamodel.transformations.constraint_support import (
|
|
13
|
+
reject_non_boolean_constraints,
|
|
14
|
+
)
|
|
12
15
|
|
|
13
16
|
|
|
14
17
|
# Reserved words of the Logic2BDD expression scanner (synExpScanner.lpp).
|
|
@@ -54,12 +57,18 @@ class PLWriter(ModelToText):
|
|
|
54
57
|
def get_destination_extension() -> str:
|
|
55
58
|
return 'exp'
|
|
56
59
|
|
|
57
|
-
def __init__(self, path: str, source_model: FeatureModel):
|
|
60
|
+
def __init__(self, path: str, source_model: FeatureModel, *, boolean_only: bool = False):
|
|
61
|
+
"""With ``boolean_only=True`` a model with arithmetic, aggregate or string constraints is
|
|
62
|
+
written without them, with a warning (the format has no comments); by default it is
|
|
63
|
+
rejected (flamapy/flamapy#5)."""
|
|
58
64
|
self.path: str = path
|
|
59
65
|
self.source_model: FeatureModel = source_model
|
|
66
|
+
self.boolean_only = boolean_only
|
|
60
67
|
self.mapping_names: dict[str, str] = {}
|
|
61
68
|
|
|
62
69
|
def transform(self) -> str:
|
|
70
|
+
reject_non_boolean_constraints(self.source_model, 'The propositional-logic format',
|
|
71
|
+
self.boolean_only)
|
|
63
72
|
secure_names = FMSecureFeaturesNames(self.source_model)
|
|
64
73
|
secure_names.reserved_names |= PL_KEYWORDS
|
|
65
74
|
feature_model = secure_names.transform()
|
|
@@ -144,7 +144,8 @@ def create_contextual_constraint(context: ContextualConstraintContext) -> None:
|
|
|
144
144
|
"""Create contextual constraints for the given feature clone."""
|
|
145
145
|
for constraint in context.feature_model.get_constraints():
|
|
146
146
|
features_in_constraint = constraint.get_features()
|
|
147
|
-
if all(feat in context.features_names_map
|
|
147
|
+
if features_in_constraint and all(feat in context.features_names_map
|
|
148
|
+
for feat in features_in_constraint):
|
|
148
149
|
# Contextualize constraint for the clone
|
|
149
150
|
context.ctcs_to_be_removed.add(constraint)
|
|
150
151
|
new_constraint = contextualize_constraint(context.feature_model,
|
|
@@ -6,6 +6,10 @@ from flamapy.metamodels.fm_metamodel.models import (
|
|
|
6
6
|
Feature,
|
|
7
7
|
Constraint
|
|
8
8
|
)
|
|
9
|
+
from flamapy.metamodels.fm_metamodel.transformations.constraint_support import (
|
|
10
|
+
reject_non_boolean_constraints,
|
|
11
|
+
xml_comment,
|
|
12
|
+
)
|
|
9
13
|
|
|
10
14
|
TAB = '\t'
|
|
11
15
|
|
|
@@ -16,12 +20,21 @@ class SPLOTWriter(ModelToText):
|
|
|
16
20
|
def get_destination_extension() -> str:
|
|
17
21
|
return 'sxfm'
|
|
18
22
|
|
|
19
|
-
def __init__(self, path: str, source_model: FeatureModel
|
|
23
|
+
def __init__(self, path: str, source_model: FeatureModel, *,
|
|
24
|
+
boolean_only: bool = False) -> None:
|
|
25
|
+
"""With ``boolean_only=True`` a model with arithmetic, aggregate or string constraints is
|
|
26
|
+
written without them, with a warning and a note in the file; by default it is rejected
|
|
27
|
+
(flamapy/flamapy#5)."""
|
|
20
28
|
self.path = path
|
|
21
29
|
self.source_model = source_model
|
|
30
|
+
self.boolean_only = boolean_only
|
|
22
31
|
|
|
23
32
|
def transform(self) -> str:
|
|
33
|
+
note = reject_non_boolean_constraints(self.source_model, 'SPLOT', self.boolean_only)
|
|
24
34
|
splot_str = fm_to_splot(self.source_model)
|
|
35
|
+
if note:
|
|
36
|
+
header, rest = splot_str.split('\n', 1)
|
|
37
|
+
splot_str = f'{header}\n<!-- {xml_comment(note)} -->\n{rest}'
|
|
25
38
|
if self.path is not None:
|
|
26
39
|
with open(self.path, 'w', encoding='utf8') as file:
|
|
27
40
|
file.write(splot_str)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import logging
|
|
3
|
+
import warnings
|
|
3
4
|
from typing import Any, Optional, Union
|
|
4
5
|
|
|
5
6
|
from antlr4 import CommonTokenStream, FileStream
|
|
@@ -44,7 +45,14 @@ class UVLReader(TextToModel):
|
|
|
44
45
|
def get_source_extension() -> str:
|
|
45
46
|
return "uvl"
|
|
46
47
|
|
|
47
|
-
def __init__(self, path: str) -> None:
|
|
48
|
+
def __init__(self, path: str, strict: bool = False) -> None:
|
|
49
|
+
"""Read the UVL model at `path`.
|
|
50
|
+
|
|
51
|
+
A character the UVL lexer cannot tokenize (e.g. the leading `_` of `_Root_`) is skipped
|
|
52
|
+
with a warning by default, so models that earlier versions read keep reading; with
|
|
53
|
+
`strict=True` it makes the reader fail, as a syntax error of the parser always does.
|
|
54
|
+
"""
|
|
55
|
+
self.strict: bool = strict
|
|
48
56
|
self.path: str = os.sep.join(path.split(os.sep)[:-1])
|
|
49
57
|
self.file: str = path.rsplit(os.sep, maxsplit=1)[-1]
|
|
50
58
|
self.namespace: str = ""
|
|
@@ -63,13 +71,27 @@ class UVLReader(TextToModel):
|
|
|
63
71
|
stream = CommonTokenStream(lexer)
|
|
64
72
|
parser = UVLPythonParser(stream)
|
|
65
73
|
|
|
66
|
-
#
|
|
74
|
+
# A character the lexer cannot tokenize is reported, not silently skipped: as a
|
|
75
|
+
# warning by default (the model is read without it, as before) and as an error with
|
|
76
|
+
# strict=True. Syntax errors of the parser always make the reader fail.
|
|
77
|
+
lexer_listener = CustomErrorListener()
|
|
78
|
+
lexer.removeErrorListeners()
|
|
79
|
+
lexer.addErrorListener(lexer_listener)
|
|
67
80
|
error_listener = CustomErrorListener()
|
|
68
81
|
parser.removeErrorListeners()
|
|
69
82
|
parser.addErrorListener(error_listener)
|
|
70
83
|
|
|
71
84
|
self.parse_tree = parser.featureModel()
|
|
72
85
|
|
|
86
|
+
if lexer_listener.errors and self.strict:
|
|
87
|
+
error_listener.errors[:0] = lexer_listener.errors
|
|
88
|
+
elif lexer_listener.errors:
|
|
89
|
+
warnings.warn(
|
|
90
|
+
f"{self.file}: the UVL lexer skipped characters it cannot read, so the model "
|
|
91
|
+
f"is read without them ({'; '.join(lexer_listener.errors)}). "
|
|
92
|
+
"Use UVLReader(path, strict=True) to reject such models.",
|
|
93
|
+
UserWarning, stacklevel=3)
|
|
94
|
+
|
|
73
95
|
if error_listener.errors:
|
|
74
96
|
for error in error_listener.errors:
|
|
75
97
|
logging.error(error)
|
|
@@ -209,7 +231,7 @@ class UVLReader(TextToModel):
|
|
|
209
231
|
value)
|
|
210
232
|
for attr in attributes_list:
|
|
211
233
|
attributes.append(attr)
|
|
212
|
-
|
|
234
|
+
default_value = None # also when the block is empty
|
|
213
235
|
else:
|
|
214
236
|
default_value = value
|
|
215
237
|
attribute = Attribute(name=f'{parent_attribute_name}.{key}',
|
|
@@ -517,7 +539,7 @@ class UVLReader(TextToModel):
|
|
|
517
539
|
"Import %s not found in path %s", namespace, self.path
|
|
518
540
|
)
|
|
519
541
|
continue
|
|
520
|
-
self.imports[namespace] = UVLReader(import_path).transform()
|
|
542
|
+
self.imports[namespace] = UVLReader(import_path, strict=self.strict).transform()
|
|
521
543
|
# The same model may be imported under several aliases: each one resolves to it.
|
|
522
544
|
self.import_root[alias or namespace] = namespace
|
|
523
545
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flamapy-fm
|
|
3
|
-
Version: 2.9.0.
|
|
3
|
+
Version: 2.9.0.dev4
|
|
4
4
|
Summary: flamapy-fm is a plugin to Flamapy module
|
|
5
5
|
Author-email: Flamapy <flamapy@us.es>
|
|
6
6
|
License-Expression: GPL-3.0-or-later
|
|
@@ -8,7 +8,7 @@ Project-URL: Homepage, https://github.com/flamapy/fm_metamodel
|
|
|
8
8
|
Requires-Python: >=3.11
|
|
9
9
|
Description-Content-Type: text/markdown
|
|
10
10
|
License-File: LICENSE
|
|
11
|
-
Requires-Dist: flamapy-fw~=2.9.0.
|
|
11
|
+
Requires-Dist: flamapy-fw~=2.9.0.dev4
|
|
12
12
|
Requires-Dist: uvlparser~=2.5.0
|
|
13
13
|
Requires-Dist: afmparser~=1.0.3
|
|
14
14
|
Provides-Extra: dev
|
|
@@ -20,8 +20,8 @@ Requires-Dist: coverage; extra == "dev"
|
|
|
20
20
|
Requires-Dist: antlr4-tools; extra == "dev"
|
|
21
21
|
Provides-Extra: test
|
|
22
22
|
Requires-Dist: pytest; extra == "test"
|
|
23
|
-
Requires-Dist: flamapy-sat~=2.9.0.
|
|
24
|
-
Requires-Dist: flamapy-bdd~=2.9.0.
|
|
23
|
+
Requires-Dist: flamapy-sat~=2.9.0.dev4; extra == "test"
|
|
24
|
+
Requires-Dist: flamapy-bdd~=2.9.0.dev4; extra == "test"
|
|
25
25
|
Dynamic: license-file
|
|
26
26
|
|
|
27
27
|
# flamapy-fm
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
flamapy/metamodels/fm_metamodel/__init__.py,sha256=GVfTFI70Ig3A51F60oM5j24EGcpcZ1lZTA2uXAIx5aw,1496
|
|
2
2
|
flamapy/metamodels/fm_metamodel/models/__init__.py,sha256=l2bNmKulcC9DHeJePUTsJZJ4u7hQQfpoi0wXll2-768,465
|
|
3
|
-
flamapy/metamodels/fm_metamodel/models/clause_set.py,sha256=
|
|
3
|
+
flamapy/metamodels/fm_metamodel/models/clause_set.py,sha256=dVmpV2CDq0as7G5mD2AzQrQzDnoKkGRu5kmN4EhT_b8,13050
|
|
4
4
|
flamapy/metamodels/fm_metamodel/models/feature_model.py,sha256=O9Oa4IGqjJ9ldbGfNgdZQsuN2XNZ-V0xhwGhdASB7DM,28902
|
|
5
5
|
flamapy/metamodels/fm_metamodel/operations/__init__.py,sha256=uTnac7Qy9oVxKosQhaH-ob1RswM6bthMhwkxj5vTv1Q,1244
|
|
6
6
|
flamapy/metamodels/fm_metamodel/operations/fm_atomic_sets.py,sha256=BA2MfS12uK1wXguzaiVeDcsqXg2SMOitLHocsZr8Xxs,2059
|
|
@@ -22,20 +22,21 @@ flamapy/metamodels/fm_metamodel/transformations/__init__.py,sha256=WYm5cHp24jNko
|
|
|
22
22
|
flamapy/metamodels/fm_metamodel/transformations/_uvl_lexer.py,sha256=8a5VDa6w5TIGG92SF5RGxUcgOc8Qt94aSVG0CukwAA4,3145
|
|
23
23
|
flamapy/metamodels/fm_metamodel/transformations/afm_reader.py,sha256=yC4MFKCgMmLqLEVbOKi8MSk63E1RmV822KOoNo9p5cU,10497
|
|
24
24
|
flamapy/metamodels/fm_metamodel/transformations/afm_writer.py,sha256=m7DB453oy7Wcj30rM_EqFE1WZjSX9GwuUjjYL6mFDWw,10530
|
|
25
|
-
flamapy/metamodels/fm_metamodel/transformations/clafer_writer.py,sha256=
|
|
25
|
+
flamapy/metamodels/fm_metamodel/transformations/clafer_writer.py,sha256=Ko7_liDZpRQv7oZFQ9DLtszmY_1adkZOc6Plx-2M5vk,11231
|
|
26
|
+
flamapy/metamodels/fm_metamodel/transformations/constraint_support.py,sha256=uZ7J46bs9hjWAOQrYL-qRwzrYawwTIbDaxPxhfv5sy4,3704
|
|
26
27
|
flamapy/metamodels/fm_metamodel/transformations/featureide_reader.py,sha256=GESkrFf_RENvZ7Ox4o2vBaArxlmkJnOW5-HsNyz4IK8,7626
|
|
27
|
-
flamapy/metamodels/fm_metamodel/transformations/featureide_writer.py,sha256=
|
|
28
|
-
flamapy/metamodels/fm_metamodel/transformations/flat_fm.py,sha256=
|
|
28
|
+
flamapy/metamodels/fm_metamodel/transformations/featureide_writer.py,sha256=79qhyHQtjujWe3su6X49XBqOHkyfpQKiOGg_FMKFYig,7370
|
|
29
|
+
flamapy/metamodels/fm_metamodel/transformations/flat_fm.py,sha256=q9ioNB28rtu9O1mWmw7kQxKU64dP0Cb1hfL0m-kmagU,9716
|
|
29
30
|
flamapy/metamodels/fm_metamodel/transformations/fm_secure_features_names.py,sha256=Wo_VDEQajsv6zV7EPHK_UW3XVPZPsE8rLPRdpqgsZVU,5941
|
|
30
31
|
flamapy/metamodels/fm_metamodel/transformations/glencoe_reader.py,sha256=7k9q946lEbg7mBwT39lqpuvRLZqjVjRxenSY5sOFnQ4,5873
|
|
31
32
|
flamapy/metamodels/fm_metamodel/transformations/glencoe_writer.py,sha256=Ym6kdRCCTVwpZ0BVxnTSWQtStjeBHEbIpqgIQdfzHAw,5368
|
|
32
33
|
flamapy/metamodels/fm_metamodel/transformations/group_support.py,sha256=Kw3HCH7E-aSE-y6XhRmQUrh4qJxzHnXS7FL_AmP4qYw,3756
|
|
33
34
|
flamapy/metamodels/fm_metamodel/transformations/json_reader.py,sha256=Uzp_74p9uj46cGcf01oIFZnxdD76DoGPGcf-21dYoDQ,6187
|
|
34
|
-
flamapy/metamodels/fm_metamodel/transformations/json_writer.py,sha256=
|
|
35
|
-
flamapy/metamodels/fm_metamodel/transformations/pl_writer.py,sha256=
|
|
35
|
+
flamapy/metamodels/fm_metamodel/transformations/json_writer.py,sha256=CnnNQILJ56aDbTnebuGzmSnMDFR-4PsJQfFwDmmFdTc,5072
|
|
36
|
+
flamapy/metamodels/fm_metamodel/transformations/pl_writer.py,sha256=hx1eFzFLbGKq0NPw0IUwaVBmM686nKdCE8JYjDLNthA,9779
|
|
36
37
|
flamapy/metamodels/fm_metamodel/transformations/pysat_to_fm.py,sha256=USRXd2UZh4rlcSfliKB4qwH-zBix97KClcnIrNL8muo,3490
|
|
37
|
-
flamapy/metamodels/fm_metamodel/transformations/splot_writer.py,sha256=
|
|
38
|
-
flamapy/metamodels/fm_metamodel/transformations/uvl_reader.py,sha256=
|
|
38
|
+
flamapy/metamodels/fm_metamodel/transformations/splot_writer.py,sha256=5iOB5K85KgRqRAuqmQ8ECncCK1z7soxuSk1JAVd_kqE,3867
|
|
39
|
+
flamapy/metamodels/fm_metamodel/transformations/uvl_reader.py,sha256=YfYIrDpEtjWlGicPQu1UVVVv4wQtZh6xO0DF-oBXbVA,28897
|
|
39
40
|
flamapy/metamodels/fm_metamodel/transformations/uvl_writer.py,sha256=nggRt16gdyA6zZZvy3evE6Jymy68hhnEZl8XdkRUOgA,13348
|
|
40
41
|
flamapy/metamodels/fm_metamodel/transformations/xml_reader.py,sha256=iuTlcc58i1j46nxSLK8Z8geo95J_dEG6ekMQpNHu15U,4999
|
|
41
42
|
flamapy/metamodels/fm_metamodel/transformations/xml_writer.py,sha256=pjUDi3bbtd7CNKoe2c3oAX425DdKcml39ou79JLcTo8,6452
|
|
@@ -44,7 +45,7 @@ flamapy/metamodels/fm_metamodel/transformations/refactorings/cardinality_group_r
|
|
|
44
45
|
flamapy/metamodels/fm_metamodel/transformations/refactorings/commitment_feature.py,sha256=yyC1eiipieSTn9mEiXQpUcK_NYzalwP5ko1jU9Xd_ic,3215
|
|
45
46
|
flamapy/metamodels/fm_metamodel/transformations/refactorings/deletion_feature.py,sha256=J_Tv1p8sYYLN1KP_ougJeWVA-LnsuwgNYBLG52xf3Mo,2896
|
|
46
47
|
flamapy/metamodels/fm_metamodel/transformations/refactorings/feature_cardinality_refactoring.py,sha256=QzE2Aup-7t4qYPOandEK_pE6wsvgwdP3K7-2iD0WFRc,9308
|
|
47
|
-
flamapy/metamodels/fm_metamodel/transformations/refactorings/feature_cardinality_refactoring_paper.py,sha256=
|
|
48
|
+
flamapy/metamodels/fm_metamodel/transformations/refactorings/feature_cardinality_refactoring_paper.py,sha256=xIaVdbfOCuGkeYMrIotw47zCxlZsOTm1jD2rlE9ZWoE,11167
|
|
48
49
|
flamapy/metamodels/fm_metamodel/transformations/refactorings/multiple_group_decomposition_refactoring.py,sha256=MITWIcagPfQmP1B4EUpDWwO_MhKO3ho-qkVn1irwtNk,2985
|
|
49
50
|
flamapy/metamodels/fm_metamodel/transformations/refactorings/mutex_group_refactoring.py,sha256=bWMKLcTt9_AcaHaUjBEoW-ux4UO6NVdkvG8XnH7jLCM,2355
|
|
50
51
|
flamapy/metamodels/fm_metamodel/transformations/refactorings/or_mandatory_refactoring.py,sha256=nI1tuk7TIFYU9RQgY8FMR5UO0bFyVBOyY15tyvUnxVw,2391
|
|
@@ -53,9 +54,9 @@ flamapy/metamodels/fm_metamodel/transformations/refactorings/refactoring_excepti
|
|
|
53
54
|
flamapy/metamodels/fm_metamodel/transformations/refactorings/refactoring_interface.py,sha256=1esc7w0j3Bb8ZcomAzoIwwtv_HOzvdVzGa9zA0AG29Y,3189
|
|
54
55
|
flamapy/metamodels/fm_metamodel/transformations/refactorings/strictcomplex_constraint_refactoring.py,sha256=Tl15MiNbfbFXLL_QvsXf_6Z-g84Zd2mohQXxf4kc_jw,5321
|
|
55
56
|
flamapy/metamodels/fm_metamodel/transformations/refactorings/xor_mandatory_refactoring.py,sha256=8kJeZUAlPZFIfwEMQT6KUA9CnK7Pljcz1vNb1mW0aFY,2405
|
|
56
|
-
flamapy_fm-2.9.0.
|
|
57
|
-
flamapy_fm-2.9.0.
|
|
58
|
-
flamapy_fm-2.9.0.
|
|
59
|
-
flamapy_fm-2.9.0.
|
|
60
|
-
flamapy_fm-2.9.0.
|
|
61
|
-
flamapy_fm-2.9.0.
|
|
57
|
+
flamapy_fm-2.9.0.dev4.dist-info/licenses/LICENSE,sha256=46mU2C5kSwOnkqkw9XQAJlhBL2JAf1_uCD8lVcXyMRg,7652
|
|
58
|
+
flamapy_fm-2.9.0.dev4.dist-info/METADATA,sha256=J4H1-EmihG1RVfQPacKRfL10xYgWo65DS-MW5amkBJU,2069
|
|
59
|
+
flamapy_fm-2.9.0.dev4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
60
|
+
flamapy_fm-2.9.0.dev4.dist-info/entry_points.txt,sha256=QLoGjJfFZGW1qyXdTrrIe084y38eoBKORc-L6aeKY3I,55
|
|
61
|
+
flamapy_fm-2.9.0.dev4.dist-info/top_level.txt,sha256=2YBI9dg4GVk28AJuyNu6dldi5Riwt5SP0zpNe2lSU5M,8
|
|
62
|
+
flamapy_fm-2.9.0.dev4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|